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.

169 lines
6.4 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\HTTPTest(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 testHEntryHasHCardAndUrlAuthor() {
  77. $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
  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', $data->data->author->url);
  83. $this->assertEquals('Author', $data->data->author->name);
  84. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  85. }
  86. public function testHEntryHasHCardAuthor() {
  87. $url = 'http://author.example.com/h-entry-has-h-card-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 testPageIsHCard() {
  97. $url = 'http://author.example.com/about';
  98. $response = $this->parse(['url' => $url]);
  99. $body = $response->getContent();
  100. $this->assertEquals(200, $response->getStatusCode());
  101. $data = json_decode($body);
  102. $this->assertEquals('card', $data->data->type);
  103. $this->assertEquals('http://author.example.com/about', $data->data->url);
  104. $this->assertEquals('Author Full Name', $data->data->name);
  105. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  106. }
  107. public function testHEntryAuthorIs0() {
  108. $url = 'http://author.example.com/author-name-is-0';
  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/photo.jpg', $data->data->photo);
  115. $this->assertEquals('0', $data->data->name);
  116. }
  117. /*
  118. public function testHFeedHasHCardAuthor() {
  119. $url = 'http://author.example.com/h-feed-has-h-card-author';
  120. $response = $this->parse(['url' => $url]);
  121. $body = $response->getContent();
  122. print_r($body);
  123. $this->assertEquals(200, $response->getStatusCode());
  124. $data = json_decode($body);
  125. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  126. $this->assertEquals('Author', $data->data->author->name);
  127. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  128. }
  129. */
  130. }