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.

198 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->assertEquals('mf2+html', $data->{'source-format'});
  23. $this->assertEmpty($data->data->author->url);
  24. $this->assertEquals('Author Name', $data->data->author->name);
  25. $this->assertEmpty($data->data->author->photo);
  26. }
  27. public function testHEntryAuthorIsRelLinkToHCardOnPage() {
  28. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-on-page';
  29. $response = $this->parse(['url' => $url]);
  30. $body = $response->getContent();
  31. $this->assertEquals(200, $response->getStatusCode());
  32. $data = json_decode($body);
  33. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  34. $this->assertEquals('Author', $data->data->author->name);
  35. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  36. }
  37. public function testHEntryAuthorIsRelLinkToHCardWithRelMe() {
  38. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-rel-me';
  39. $response = $this->parse(['url' => $url]);
  40. $body = $response->getContent();
  41. $this->assertEquals(200, $response->getStatusCode());
  42. $data = json_decode($body);
  43. $this->assertEquals('http://author.example.com/about-rel-me', $data->data->author->url);
  44. $this->assertEquals('Author Full Name', $data->data->author->name);
  45. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  46. }
  47. public function testHEntryAuthorIsRelLinkToHCardWithUrlUid() {
  48. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-url-uid';
  49. $response = $this->parse(['url' => $url]);
  50. $body = $response->getContent();
  51. $this->assertEquals(200, $response->getStatusCode());
  52. $data = json_decode($body);
  53. $this->assertEquals('http://author.example.com/about-url-uid', $data->data->author->url);
  54. $this->assertEquals('Author Full Name', $data->data->author->name);
  55. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  56. }
  57. public function testHEntryAuthorIsUrlToHCardOnPage() {
  58. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-on-page';
  59. $response = $this->parse(['url' => $url]);
  60. $body = $response->getContent();
  61. $this->assertEquals(200, $response->getStatusCode());
  62. $data = json_decode($body);
  63. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  64. $this->assertEquals('Author', $data->data->author->name);
  65. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  66. }
  67. public function testHEntryAuthorIsUrlToHCardWithMultipleLinks() {
  68. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links';
  69. $response = $this->parse(['url' => $url]);
  70. $body = $response->getContent();
  71. $this->assertEquals(200, $response->getStatusCode());
  72. $data = json_decode($body);
  73. $this->assertEquals('http://author.example.com/about-with-multiple-urls', $data->data->author->url);
  74. $this->assertEquals('Author Full Name', $data->data->author->name);
  75. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  76. }
  77. public function testHEntryAuthorIsUrlToHCardWithNoURL() {
  78. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-no-url';
  79. $response = $this->parse(['url' => $url]);
  80. $body = $response->getContent();
  81. $this->assertEquals(200, $response->getStatusCode());
  82. $data = json_decode($body);
  83. $this->assertEquals('http://author.example.com/about-no-url', $data->data->author->url);
  84. $this->assertEquals('Author Full Name', $data->data->author->name);
  85. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  86. }
  87. public function testHEntryHasHCardAndUrlAuthor() {
  88. $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
  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', $data->data->author->url);
  94. $this->assertEquals('Author', $data->data->author->name);
  95. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  96. }
  97. public function testHEntryHasHCardAuthor() {
  98. $url = 'http://author.example.com/h-entry-has-h-card-author';
  99. $response = $this->parse(['url' => $url]);
  100. $body = $response->getContent();
  101. $this->assertEquals(200, $response->getStatusCode());
  102. $data = json_decode($body);
  103. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  104. $this->assertEquals('Author', $data->data->author->name);
  105. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  106. }
  107. public function testPageIsHCard() {
  108. $url = 'http://author.example.com/about';
  109. $response = $this->parse(['url' => $url]);
  110. $body = $response->getContent();
  111. $this->assertEquals(200, $response->getStatusCode());
  112. $data = json_decode($body);
  113. $this->assertEquals('card', $data->data->type);
  114. $this->assertEquals('http://author.example.com/about', $data->data->url);
  115. $this->assertEquals('Author Full Name', $data->data->name);
  116. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  117. }
  118. public function testPageIsHCardWithNoURL() {
  119. $url = 'http://author.example.com/about-no-url';
  120. $response = $this->parse(['url' => $url]);
  121. $body = $response->getContent();
  122. $this->assertEquals(200, $response->getStatusCode());
  123. $data = json_decode($body);
  124. $this->assertEquals('card', $data->data->type);
  125. $this->assertEquals('Author Full Name', $data->data->name);
  126. $this->assertEquals($url, $data->data->url);
  127. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  128. }
  129. public function testHEntryAuthorIs0() {
  130. $url = 'http://author.example.com/author-name-is-0';
  131. $response = $this->parse(['url' => $url]);
  132. $body = $response->getContent();
  133. $this->assertEquals(200, $response->getStatusCode());
  134. $data = json_decode($body);
  135. $this->assertEquals('card', $data->data->type);
  136. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  137. $this->assertEquals('0', $data->data->name);
  138. }
  139. /*
  140. public function testHFeedHasHCardAuthor() {
  141. $url = 'http://author.example.com/h-feed-has-h-card-author';
  142. $response = $this->parse(['url' => $url]);
  143. $body = $response->getContent();
  144. print_r($body);
  145. $this->assertEquals(200, $response->getStatusCode());
  146. $data = json_decode($body);
  147. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  148. $this->assertEquals('Author', $data->data->author->name);
  149. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  150. }
  151. */
  152. }