|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\Functional\Controller\Admin; |
| 6 | + |
| 7 | +use App\Tests\Functional\Traits\LocationTrait; |
| 8 | +use Sulu\Bundle\TestBundle\Testing\SuluTestCase; |
| 9 | +use Symfony\Bundle\FrameworkBundle\KernelBrowser; |
| 10 | +use Symfony\Component\HttpFoundation\Response; |
| 11 | + |
| 12 | +class LocationControllerTest extends SuluTestCase |
| 13 | +{ |
| 14 | + use LocationTrait; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var KernelBrowser |
| 18 | + */ |
| 19 | + private $client; |
| 20 | + |
| 21 | + protected function setUp(): void |
| 22 | + { |
| 23 | + $this->client = $this->createAuthenticatedClient(); |
| 24 | + $this->purgeDatabase(); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCGet(): void |
| 28 | + { |
| 29 | + $location1 = $this->createLocation('Sulu'); |
| 30 | + $location2 = $this->createLocation('Symfony'); |
| 31 | + |
| 32 | + $this->client->request('GET', '/admin/api/locations'); |
| 33 | + |
| 34 | + $response = $this->client->getResponse(); |
| 35 | + $this->assertInstanceOf(Response::class, $response); |
| 36 | + $result = json_decode($response->getContent() ?: '', true); |
| 37 | + $this->assertHttpStatusCode(200, $response); |
| 38 | + |
| 39 | + $this->assertSame(2, $result['total']); |
| 40 | + $this->assertCount(2, $result['_embedded']['locations']); |
| 41 | + $items = $result['_embedded']['locations']; |
| 42 | + |
| 43 | + $this->assertSame($location1->getId(), $items[0]['id']); |
| 44 | + $this->assertSame($location2->getId(), $items[1]['id']); |
| 45 | + |
| 46 | + $this->assertSame($location1->getName(), $items[0]['name']); |
| 47 | + $this->assertSame($location2->getName(), $items[1]['name']); |
| 48 | + } |
| 49 | +} |
0 commit comments