|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Tests; |
| 4 | + |
| 5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 6 | + |
| 7 | +class GeneratedCrudControllerTest extends WebTestCase |
| 8 | +{ |
| 9 | + public function testIndexAction() |
| 10 | + { |
| 11 | + $client = self::createClient(); |
| 12 | + $crawler = $client->request('GET', '/sweet/food/admin/'); |
| 13 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 14 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 15 | + $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); |
| 16 | + |
| 17 | + $newLink = $crawler->filter('a:contains("Create new")')->eq(0)->link(); |
| 18 | + |
| 19 | + $crawler = $client->click($newLink); |
| 20 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 21 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 22 | + $this->assertStringContainsString('New SweetFood', $client->getResponse()->getContent()); |
| 23 | + |
| 24 | + $newForm = $crawler->selectButton('Save')->form(); |
| 25 | + $client->submit($newForm, ['sweet_food[title]' => 'Candy']); |
| 26 | + $this->assertTrue($client->getResponse()->isRedirect()); |
| 27 | + |
| 28 | + $crawler = $client->followRedirect(); |
| 29 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 30 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 31 | + $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); |
| 32 | + $this->assertStringContainsString('<td>Candy</td>', $client->getResponse()->getContent()); |
| 33 | + |
| 34 | + $editLink = $crawler->filter('a:contains("edit")')->eq(0)->link(); |
| 35 | + $crawler = $client->click($editLink); |
| 36 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 37 | + $this->assertStringContainsString('Edit SweetFood', $client->getResponse()->getContent()); |
| 38 | + $this->assertGreaterThan(0, $crawler->filter('input[type=text]')->count()); |
| 39 | + |
| 40 | + $editForm = $crawler->selectButton('Update')->form(); |
| 41 | + $client->submit($editForm, ['sweet_food[title]' => 'Candy edited']); |
| 42 | + $this->assertTrue($client->getResponse()->isRedirect()); |
| 43 | + |
| 44 | + $crawler = $client->followRedirect(); |
| 45 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 46 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 47 | + $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); |
| 48 | + $this->assertStringContainsString('Candy edited', $client->getResponse()->getContent()); |
| 49 | + |
| 50 | + $showLink = $crawler->filter('a:contains("show")')->eq(0)->link(); |
| 51 | + |
| 52 | + $crawler = $client->click($showLink); |
| 53 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 54 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 55 | + $this->assertStringContainsString('SweetFood', $client->getResponse()->getContent()); |
| 56 | + $this->assertStringContainsString('Candy edited', $client->getResponse()->getContent()); |
| 57 | + |
| 58 | + $deleteForm = $crawler->selectButton('Delete')->form(); |
| 59 | + $client->submit($deleteForm); |
| 60 | + $this->assertTrue($client->getResponse()->isRedirect()); |
| 61 | + |
| 62 | + $client->followRedirect(); |
| 63 | + $this->assertTrue($client->getResponse()->isSuccessful()); |
| 64 | + $this->assertStringContainsString('<!DOCTYPE html>', $client->getResponse()->getContent()); |
| 65 | + $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); |
| 66 | + $this->assertStringContainsString('no records found', $client->getResponse()->getContent()); |
| 67 | + } |
| 68 | +} |
0 commit comments