GpsCoordinateTest.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Tests\Application\Utils;
  3. use App\Tests\Application\OtWebTestCase;
  4. class GpsCoordinateTest extends OtWebTestCase
  5. {
  6. public function testGpsCoordinteResource(): void
  7. {
  8. $this->logger->info("\033[1;34mStarting test... GPS coordinate reverse lookup\033[0m");
  9. $this->loginAs($this->user);
  10. $this->get('/api/gps-coordinate-reverse/48.8566/2.3522');
  11. $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-reverse/48.8566/2.3522\033[0m");
  12. $this->assertResponseStatusCodeSame(200);
  13. $this->logger->info("\033[1;34mReceived status code 200\033[0m");
  14. $this->assertJsonContains([
  15. '@context' => '/api/contexts/GpsCoordinate',
  16. '@id' => '/api/gps-coordinate-reverse/48.8564263/2.3525275780116',
  17. '@type' => 'GpsCoordinate',
  18. 'latitude' => 48.856426299999995,
  19. 'longitude' => 2.3525275780116073,
  20. 'streetAddress' => "Place de l'Hôtel de Ville",
  21. 'streetAddressSecond' => null,
  22. 'streetAddressThird' => null,
  23. 'cp' => '75004',
  24. 'city' => null,
  25. 'country' => null,
  26. ]);
  27. $this->logger->info("\033[1;32mTest 'GPS coordinate reverse lookup' succeeded\033[0m");
  28. $this->logger->info("\033[1;34mStarting test... GPS coordinate searching\033[0m");
  29. $this->get('/api/gps-coordinate-searching');
  30. $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-searching\033[0m");
  31. $this->assertResponseStatusCodeSame(200);
  32. $this->logger->info("\033[1;34mReceived status code 200\033[0m");
  33. $this->assertJsonContains([
  34. '@context' => '/api/contexts/GpsCoordinate',
  35. '@id' => '/api/gps-coordinate-searching',
  36. '@type' => 'hydra:Collection',
  37. 'hydra:totalItems' => 1,
  38. 'hydra:member' => [
  39. [
  40. '@id' => '/api/gps-coordinate-reverse/0/0',
  41. '@type' => 'GpsCoordinate',
  42. 'latitude' => 0,
  43. 'longitude' => 0,
  44. 'streetAddress' => null,
  45. 'streetAddressSecond' => null,
  46. 'streetAddressThird' => null,
  47. 'cp' => null,
  48. 'city' => null,
  49. 'country' => null,
  50. ],
  51. ],
  52. ]);
  53. $this->logger->info("\033[1;32mTest 'GPS coordinate searching' succeeded\033[0m");
  54. $this->logger->info("\033[1;34mStarting test... GPS coordinate reverse lookup with invalid coordinates\033[0m");
  55. $this->loginAs($this->user);
  56. $this->get('/api/gps-coordinate-reverse/12345.6789/98765.4321');
  57. $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-reverse/12345.6789/98765.4321\033[0m");
  58. $this->assertResponseStatusCodeSame(404);
  59. $this->logger->info("\033[1;34mReceived status code 404\033[0m");
  60. $this->assertJsonContains([
  61. '@context' => '/api/contexts/Error',
  62. '@type' => 'hydra:Error',
  63. 'hydra:title' => 'An error occurred',
  64. 'hydra:description' => 'Failed to retrieve GPS coordinates: No address found for the given GPS coordinates.',
  65. ]);
  66. $this->logger->info("\033[1;32mTest 'GPS coordinate reverse lookup with invalid coordinates' succeeded\033[0m");
  67. }
  68. }