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.

213 lines
8.1 KiB

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