Completed
Pull Request — master (#45)
by Laurent
04:03
created

FamilyLogControllerTest::testEditError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace AppBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7 View Code Duplication
class FamilyLogControllerTest extends WebTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    public function testCreate()
10
    {
11
        $client = static::createClient();
12
        $crawler = $client->request('GET', '/admin/settings/');
13
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
14
        $crawler = $client->click($crawler->filter('.new_entry a')->link());
15
        $form = $crawler->filter('form button[type="submit"]')->form(array(
16
            'familylog[name]' => 'Lorem ipsum dolor sit amet',
17
                    ));
18
        $client->submit($form);
19
        $crawler = $client->followRedirect();
20
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
21
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
22
    }
23
24
    public function testCreateError()
25
    {
26
        $client = static::createClient();
27
        $crawler = $client->request('GET', '/admin/settings/new');
28
        $form = $crawler->filter('form button[type="submit"]')->form();
29
        $crawler = $client->submit($form);
30
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
31
        $this->assertTrue($client->getResponse()->isSuccessful());
32
    }
33
34
    /**
35
     * @depends testCreate
36
     */
37
    public function testEdit()
38
    {
39
        $client = static::createClient();
40
        $crawler = $client->request('GET', '/admin/settings/');
41
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")'));
42
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
43
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
44
        $form = $crawler->filter('form button[type="submit"]')->form(array(
45
            'familylog[name]' => 'Changed',
46
            // ... adapt fields value here ...
47
        ));
48
        $client->submit($form);
49
        $crawler = $client->followRedirect();
50
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
51
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")'));
52
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
53
    }
54
55
    /**
56
     * @depends testCreate
57
     */
58
    public function testEditError()
59
    {
60
        $client = static::createClient();
61
        $crawler = $client->request('GET', '/admin/settings/');
62
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
63
        $form = $crawler->filter('form button[type="submit"]')->form(array(
64
            'familylog[field_name]' => '',
65
            // ... use a required field here ...
66
        ));
67
        $crawler = $client->submit($form);
68
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
69
    }
70
71
    /**
72
     * @depends testCreate
73
     */
74
    public function testDelete()
75
    {
76
        $client = static::createClient();
77
        $crawler = $client->request('GET', '/admin/settings/');
78
        $this->assertTrue($client->getResponse()->isSuccessful());
79
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
80
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link());
81
        $client->submit($crawler->filter('form#delete button[type="submit"]')->form());
82
        $crawler = $client->followRedirect();
83
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
84
    }
85
}
86