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.

155 lines
5.9 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. }
  10. private function parse($params) {
  11. $request = new Request($params);
  12. $response = new Response();
  13. return $this->client->parse($request, $response);
  14. }
  15. public function testHEntryAuthorIsName() {
  16. $url = 'http://author.example.com/h-entry-author-is-name';
  17. $response = $this->parse(['url' => $url]);
  18. $body = $response->getContent();
  19. $this->assertEquals(200, $response->getStatusCode());
  20. $data = json_decode($body);
  21. $this->assertEmpty($data->data->author->url);
  22. $this->assertEquals('Author Name', $data->data->author->name);
  23. $this->assertEmpty($data->data->author->photo);
  24. }
  25. public function testHEntryAuthorIsRelLinkToHCardOnPage() {
  26. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-on-page';
  27. $response = $this->parse(['url' => $url]);
  28. $body = $response->getContent();
  29. $this->assertEquals(200, $response->getStatusCode());
  30. $data = json_decode($body);
  31. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  32. $this->assertEquals('Author', $data->data->author->name);
  33. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  34. }
  35. public function testHEntryAuthorIsRelLinkToHCardWithRelMe() {
  36. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-rel-me';
  37. $response = $this->parse(['url' => $url]);
  38. $body = $response->getContent();
  39. $this->assertEquals(200, $response->getStatusCode());
  40. $data = json_decode($body);
  41. $this->assertEquals('http://author.example.com/about-rel-me', $data->data->author->url);
  42. $this->assertEquals('Author Full Name', $data->data->author->name);
  43. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  44. }
  45. public function testHEntryAuthorIsRelLinkToHCardWithUrlUid() {
  46. $url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-url-uid';
  47. $response = $this->parse(['url' => $url]);
  48. $body = $response->getContent();
  49. $this->assertEquals(200, $response->getStatusCode());
  50. $data = json_decode($body);
  51. $this->assertEquals('http://author.example.com/about-url-uid', $data->data->author->url);
  52. $this->assertEquals('Author Full Name', $data->data->author->name);
  53. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  54. }
  55. public function testHEntryAuthorIsUrlToHCardOnPage() {
  56. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-on-page';
  57. $response = $this->parse(['url' => $url]);
  58. $body = $response->getContent();
  59. $this->assertEquals(200, $response->getStatusCode());
  60. $data = json_decode($body);
  61. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  62. $this->assertEquals('Author', $data->data->author->name);
  63. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  64. }
  65. public function testHEntryAuthorIsUrlToHCardWithMultipleLinks() {
  66. $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links';
  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-with-multiple-urls', $data->data->author->url);
  72. $this->assertEquals('Author Full Name', $data->data->author->name);
  73. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  74. }
  75. public function testHEntryHasHCardAndUrlAuthor() {
  76. $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
  77. $response = $this->parse(['url' => $url]);
  78. $body = $response->getContent();
  79. $this->assertEquals(200, $response->getStatusCode());
  80. $data = json_decode($body);
  81. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  82. $this->assertEquals('Author', $data->data->author->name);
  83. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  84. }
  85. public function testHEntryHasHCardAuthor() {
  86. $url = 'http://author.example.com/h-entry-has-h-card-author';
  87. $response = $this->parse(['url' => $url]);
  88. $body = $response->getContent();
  89. $this->assertEquals(200, $response->getStatusCode());
  90. $data = json_decode($body);
  91. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  92. $this->assertEquals('Author', $data->data->author->name);
  93. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  94. }
  95. public function testPageIsHCard() {
  96. $url = 'http://author.example.com/about';
  97. $response = $this->parse(['url' => $url]);
  98. $body = $response->getContent();
  99. $this->assertEquals(200, $response->getStatusCode());
  100. $data = json_decode($body);
  101. $this->assertEquals('card', $data->data->type);
  102. $this->assertEquals('http://author.example.com/about', $data->data->url);
  103. $this->assertEquals('Author Full Name', $data->data->name);
  104. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  105. }
  106. /*
  107. public function testHFeedHasHCardAuthor() {
  108. $url = 'http://author.example.com/h-feed-has-h-card-author';
  109. $response = $this->parse(['url' => $url]);
  110. $body = $response->getContent();
  111. print_r($body);
  112. $this->assertEquals(200, $response->getStatusCode());
  113. $data = json_decode($body);
  114. $this->assertEquals('http://author.example.com/about', $data->data->author->url);
  115. $this->assertEquals('Author', $data->data->author->name);
  116. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
  117. }
  118. */
  119. }