You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
7.5 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class AuthorTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testHEntryAuthorIsName() {
  17. $url = 'http://author.example.com/h-entry-author-is-name';
  18. $response = $this->parse(['url' => $url]);
  19. $body = $response->getContent();
  20. $this->assertEquals(200, $response->getStatusCode());
  21. $data = json_decode($body);
  22. $this->assertEmpty($data->data->author->url);
  23. $this->assertEquals('Author Name', $data->data->author->name);
  24. $this->assertEmpty($data->data->author->photo);
  25. }
  26. public function testHEntryAuthorIsRelLinkToHCardOnPage() {
  27. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-on-page';
  28. $response = $this->parse(['url' => $url]);
  29. $body = $response->getContent();
  30. $this->assertEquals(200, $response->getStatusCode());
  31. $data = json_decode($body);
  32. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  33. $this->assertEquals('Author', $data->data->author->name);
  34. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  35. }
  36. public function testHEntryAuthorIsRelLinkToHCardWithRelMe() {
  37. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-rel-me';
  38. $response = $this->parse(['url' => $url]);
  39. $body = $response->getContent();
  40. $this->assertEquals(200, $response->getStatusCode());
  41. $data = json_decode($body);
  42. $this->assertEquals('http://author.example.com/about-rel-me', $data->data->author->url);
  43. $this->assertEquals('Author Full Name', $data->data->author->name);
  44. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  45. }
  46. public function testHEntryAuthorIsRelLinkToHCardWithUrlUid() {
  47. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-url-uid';
  48. $response = $this->parse(['url' => $url]);
  49. $body = $response->getContent();
  50. $this->assertEquals(200, $response->getStatusCode());
  51. $data = json_decode($body);
  52. $this->assertEquals('http://author.example.com/about-url-uid', $data->data->author->url);
  53. $this->assertEquals('Author Full Name', $data->data->author->name);
  54. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  55. }
  56. public function testHEntryAuthorIsUrlToHCardOnPage() {
  57. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-on-page';
  58. $response = $this->parse(['url' => $url]);
  59. $body = $response->getContent();
  60. $this->assertEquals(200, $response->getStatusCode());
  61. $data = json_decode($body);
  62. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  63. $this->assertEquals('Author', $data->data->author->name);
  64. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  65. }
  66. public function testHEntryAuthorIsUrlToHCardWithMultipleLinks() {
  67. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links';
  68. $response = $this->parse(['url' => $url]);
  69. $body = $response->getContent();
  70. $this->assertEquals(200, $response->getStatusCode());
  71. $data = json_decode($body);
  72. $this->assertEquals('http://author.example.com/about-with-multiple-urls', $data->data->author->url);
  73. $this->assertEquals('Author Full Name', $data->data->author->name);
  74. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  75. }
  76. public function testHEntryAuthorIsUrlToHCardWithNoURL() {
  77. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-no-url';
  78. $response = $this->parse(['url' => $url]);
  79. $body = $response->getContent();
  80. $this->assertEquals(200, $response->getStatusCode());
  81. $data = json_decode($body);
  82. $this->assertEquals('http://author.example.com/about-no-url', $data->data->author->url);
  83. $this->assertEquals('Author Full Name', $data->data->author->name);
  84. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  85. }
  86. public function testHEntryHasHCardAndUrlAuthor() {
  87. $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
  88. $response = $this->parse(['url' => $url]);
  89. $body = $response->getContent();
  90. $this->assertEquals(200, $response->getStatusCode());
  91. $data = json_decode($body);
  92. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  93. $this->assertEquals('Author', $data->data->author->name);
  94. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  95. }
  96. public function testHEntryHasHCardAuthor() {
  97. $url = 'http://author.example.com/h-entry-has-h-card-author';
  98. $response = $this->parse(['url' => $url]);
  99. $body = $response->getContent();
  100. $this->assertEquals(200, $response->getStatusCode());
  101. $data = json_decode($body);
  102. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  103. $this->assertEquals('Author', $data->data->author->name);
  104. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  105. }
  106. public function testPageIsHCard() {
  107. $url = 'http://author.example.com/about';
  108. $response = $this->parse(['url' => $url]);
  109. $body = $response->getContent();
  110. $this->assertEquals(200, $response->getStatusCode());
  111. $data = json_decode($body);
  112. $this->assertEquals('card', $data->data->type);
  113. $this->assertEquals('http://author.example.com/about', $data->data->url);
  114. $this->assertEquals('Author Full Name', $data->data->name);
  115. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  116. }
  117. public function testPageIsHCardWithNoURL() {
  118. $url = 'http://author.example.com/about-no-url';
  119. $response = $this->parse(['url' => $url]);
  120. $body = $response->getContent();
  121. $this->assertEquals(200, $response->getStatusCode());
  122. $data = json_decode($body);
  123. $this->assertEquals('card', $data->data->type);
  124. $this->assertEquals('Author Full Name', $data->data->name);
  125. $this->assertEquals($url, $data->data->url);
  126. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  127. }
  128. public function testHEntryAuthorIs0() {
  129. $url = 'http://author.example.com/author-name-is-0';
  130. $response = $this->parse(['url' => $url]);
  131. $body = $response->getContent();
  132. $this->assertEquals(200, $response->getStatusCode());
  133. $data = json_decode($body);
  134. $this->assertEquals('card', $data->data->type);
  135. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  136. $this->assertEquals('0', $data->data->name);
  137. }
  138. /*
  139. public function testHFeedHasHCardAuthor() {
  140. $url = 'http://author.example.com/h-feed-has-h-card-author';
  141. $response = $this->parse(['url' => $url]);
  142. $body = $response->getContent();
  143. print_r($body);
  144. $this->assertEquals(200, $response->getStatusCode());
  145. $data = json_decode($body);
  146. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  147. $this->assertEquals('Author', $data->data->author->name);
  148. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  149. }
  150. */
  151. }