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.

63 lines
1.9 KiB

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class ParseTest 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 testMissingURL() {
  16. $response = $this->parse([]);
  17. $body = $response->getContent();
  18. $this->assertEquals(400, $response->getStatusCode());
  19. $data = json_decode($body);
  20. $this->assertEquals('error', $data->type);
  21. $this->assertEquals('missing_url', $data->error);
  22. }
  23. public function testInvalidURL() {
  24. $url = 'ftp://example.com/foo';
  25. $response = $this->parse(['url' => $url]);
  26. $body = $response->getContent();
  27. $this->assertEquals(400, $response->getStatusCode());
  28. $data = json_decode($body);
  29. $this->assertEquals('error', $data->type);
  30. $this->assertEquals('invalid_url', $data->error);
  31. }
  32. public function testTargetNotFound() {
  33. $url = 'http://source.example.com/baseictest';
  34. $response = $this->parse(['url' => $url, 'target' => 'http://example.net']);
  35. $body = $response->getContent();
  36. $this->assertEquals(400, $response->getStatusCode());
  37. $data = json_decode($body);
  38. $this->assertEquals('error', $data->type);
  39. $this->assertEquals('no_link_found', $data->error);
  40. }
  41. public function testTargetFound() {
  42. $url = 'http://source.example.com/basictest';
  43. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com']);
  44. $body = $response->getContent();
  45. print_r($body);
  46. $this->assertEquals(200, $response->getStatusCode());
  47. $data = json_decode($body);
  48. $this->assertNotEquals('error', $data->type);
  49. $this->assertNotEquals('no_link_found', $data->error);
  50. }
  51. }