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.

141 lines
5.3 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 testHEntryHasHCardAndUrlAuthor() {
  66. $url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
  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 testHEntryHasHCardAuthor() {
  76. $url = 'http://author.example.com/h-entry-has-h-card-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 testPageIsHCard() {
  86. $url = 'http://author.example.com/about';
  87. $response = $this->parse(['url' => $url]);
  88. $body = $response->getContent();
  89. $this->assertEquals(200, $response->getStatusCode());
  90. $data = json_decode($body);
  91. $this->assertEquals('card', $data->data->type);
  92. $this->assertEquals('http://author.example.com/about', $data->data->url);
  93. $this->assertEquals('Author Full Name', $data->data->name);
  94. $this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
  95. }
  96. /*
  97. public function testHFeedHasHCardAuthor() {
  98. $url = 'http://author.example.com/h-feed-has-h-card-author';
  99. $response = $this->parse(['url' => $url]);
  100. $body = $response->getContent();
  101. print_r($body);
  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. */
  109. }