Completed
Push — master ( dcf43c...59d132 )
by Tijs
06:54
created

DatePickerControllerTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 184
Duplicated Lines 57.61 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 106
loc 184
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getCrawlerForRequest() 0 7 1
A testIfChoiceRenderedCorrectly() 8 8 1
A testIfTextRenderedCorrectly() 8 8 1
A testIfSingleTextRenderedCorrectly() 0 6 1
A testIfSingleTextWithDatePickerAndDefaultDateRenderedCorrectly() 21 21 1
A testIfSingleTextWithDatePickerRenderedCorrectly() 0 22 1
B testIfSingleTextWithDatePickerAndOnlyDatesInTheFutureRenderedCorrectly() 24 24 1
B testIfSingleTextWithDatePickerAndOnlyDatesInThePastRenderedCorrectly() 24 24 1
B testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly() 0 26 1
A testIfSingleTextWithoutDefaultDateRenderedCorrectly() 21 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace SumoCoders\FrameworkCoreBundle\Tests\Controller;
3
4
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
5
use Symfony\Bundle\FrameworkBundle\Client;
6
use Symfony\Component\DomCrawler\Crawler;
7
8
class DatePickerControllerTest extends WebTestCase
9
{
10
    /**
11
     * @param string $method
12
     * @param string $url
13
     * @return Crawler
14
     */
15
    private function getCrawlerForRequest($method, $url)
16
    {
17
        $client = static::createClient();
18
        $crawler = $client->request($method, $url);
19
20
        return $crawler;
21
    }
22
23 View Code Duplication
    public function testIfChoiceRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
24
    {
25
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
26
27
        $this->assertEquals(1, $crawler->filter('select#form_date_example1_month')->count());
28
        $this->assertEquals(1, $crawler->filter('select#form_date_example1_day')->count());
29
        $this->assertEquals(1, $crawler->filter('select#form_date_example1_year')->count());
30
    }
31
32 View Code Duplication
    public function testIfTextRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
33
    {
34
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
35
36
        $this->assertEquals(1, $crawler->filter('input#form_date_example2_month')->count());
37
        $this->assertEquals(1, $crawler->filter('input#form_date_example2_day')->count());
38
        $this->assertEquals(1, $crawler->filter('input#form_date_example2_year')->count());
39
    }
40
41
    public function testIfSingleTextRenderedCorrectly()
42
    {
43
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
44
45
        $this->assertEquals(1, $crawler->filter('input#form_date_example3')->count());
46
    }
47
48 View Code Duplication
    public function testIfSingleTextWithDatePickerAndDefaultDateRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
49
    {
50
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
51
52
        $element = $crawler->filter('input#form_date_example4');
53
        $wrapper = $element->parents()->filter('.date-widget')->first();
54
55
        $this->assertEquals(1, $element->count());
56
        $this->assertEquals(1, $wrapper->count());
57
58
        // check if it has all the required data-attributes
59
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
60
        $this->assertEquals('1985-06-20', $wrapper->attr('data-date'));
61
        $this->assertEquals('form_date_example4', $wrapper->attr('data-link-field'));
62
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
63
        $this->assertEquals('normal', $wrapper->attr('data-date-type'));
64
65
        // check if the actual element is hidden
66
        $this->assertEquals('hidden', $element->attr('type'));
67
        $this->assertEquals('1985-06-20', $element->attr('value'));
68
    }
69
70
    public function testIfSingleTextWithDatePickerRenderedCorrectly()
71
    {
72
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
73
        $date = new \DateTime();
74
75
        $element = $crawler->filter('input#form_date_example5');
76
        $wrapper = $element->parents()->filter('.date-widget')->first();
77
78
        $this->assertEquals(1, $element->count());
79
        $this->assertEquals(1, $wrapper->count());
80
81
        // check if it has all the required data-attributes
82
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
83
        $this->assertEquals($date->format('Y-m-d'), $wrapper->attr('data-date'));
84
        $this->assertEquals('form_date_example5', $wrapper->attr('data-link-field'));
85
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
86
        $this->assertEquals('normal', $wrapper->attr('data-date-type'));
87
88
        // check if the actual element is hidden
89
        $this->assertEquals('hidden', $element->attr('type'));
90
        $this->assertEquals($date->format('Y-m-d'), $element->attr('value'));
91
    }
92
93 View Code Duplication
    public function testIfSingleTextWithDatePickerAndOnlyDatesInTheFutureRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
94
    {
95
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
96
        $date = new \DateTime();
97
        $startDate = new \DateTime('last monday');
98
99
        $element = $crawler->filter('input#form_date_example6');
100
        $wrapper = $element->parents()->filter('.date-widget')->first();
101
102
        $this->assertEquals(1, $element->count());
103
        $this->assertEquals(1, $wrapper->count());
104
105
        // check if it has all the required data-attributes
106
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
107
        $this->assertEquals($date->format('Y-m-d'), $wrapper->attr('data-date'));
108
        $this->assertEquals('form_date_example6', $wrapper->attr('data-link-field'));
109
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
110
        $this->assertEquals('start', $wrapper->attr('data-date-type'));
111
        $this->assertEquals($startDate->format('Y-m-d'), $wrapper->attr('data-minimum-date'));
112
113
        // check if the actual element is hidden
114
        $this->assertEquals('hidden', $element->attr('type'));
115
        $this->assertEquals($date->format('Y-m-d'), $element->attr('value'));
116
    }
117
118 View Code Duplication
    public function testIfSingleTextWithDatePickerAndOnlyDatesInThePastRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
119
    {
120
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
121
        $date = new \DateTime();
122
        $endDate = new \DateTime('next friday');
123
124
        $element = $crawler->filter('input#form_date_example7');
125
        $wrapper = $element->parents()->filter('.date-widget')->first();
126
127
        $this->assertEquals(1, $element->count());
128
        $this->assertEquals(1, $wrapper->count());
129
130
        // check if it has all the required data-attributes
131
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
132
        $this->assertEquals($date->format('Y-m-d'), $wrapper->attr('data-date'));
133
        $this->assertEquals('form_date_example7', $wrapper->attr('data-link-field'));
134
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
135
        $this->assertEquals('until', $wrapper->attr('data-date-type'));
136
        $this->assertEquals($endDate->format('Y-m-d'), $wrapper->attr('data-maximum-date'));
137
138
        // check if the actual element is hidden
139
        $this->assertEquals('hidden', $element->attr('type'));
140
        $this->assertEquals($date->format('Y-m-d'), $element->attr('value'));
141
    }
142
143
    public function testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly()
144
    {
145
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
146
        $date = new \DateTime();
147
        $startDate = new \DateTime('last monday');
148
        $endDate = new \DateTime('next friday');
149
150
        $element = $crawler->filter('input#form_date_example8');
151
        $wrapper = $element->parents()->filter('.date-widget')->first();
152
153
        $this->assertEquals(1, $element->count());
154
        $this->assertEquals(1, $wrapper->count());
155
156
        // check if it has all the required data-attributes
157
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
158
        $this->assertEquals($date->format('Y-m-d'), $wrapper->attr('data-date'));
159
        $this->assertEquals('form_date_example8', $wrapper->attr('data-link-field'));
160
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
161
        $this->assertEquals('range', $wrapper->attr('data-date-type'));
162
        $this->assertEquals($startDate->format('Y-m-d'), $wrapper->attr('data-minimum-date'));
163
        $this->assertEquals($endDate->format('Y-m-d'), $wrapper->attr('data-maximum-date'));
164
165
        // check if the actual element is hidden
166
        $this->assertEquals('hidden', $element->attr('type'));
167
        $this->assertEquals($date->format('Y-m-d'), $element->attr('value'));
168
    }
169
170 View Code Duplication
    public function testIfSingleTextWithoutDefaultDateRenderedCorrectly()
0 ignored issues
show
Duplication introduced by
This method 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...
171
    {
172
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
173
174
        $element = $crawler->filter('input#form_date_example9');
175
        $wrapper = $element->parents()->filter('.date-widget')->first();
176
177
        $this->assertEquals(1, $element->count());
178
        $this->assertEquals(1, $wrapper->count());
179
180
        // check if it has all the required data-attributes
181
        $this->assertEquals('datepicker', $wrapper->attr('data-provider'));
182
        $this->assertEquals('', $wrapper->attr('data-date'));
183
        $this->assertEquals('form_date_example9', $wrapper->attr('data-link-field'));
184
        $this->assertEquals('yyyy-mm-dd', $wrapper->attr('data-link-format'));
185
        $this->assertEquals('normal', $wrapper->attr('data-date-type'));
186
187
        // check if the actual element is hidden
188
        $this->assertEquals('hidden', $element->attr('type'));
189
        $this->assertEquals('', $element->attr('value'));
190
    }
191
}
192