Completed
Push — 92-better-datepicker ( b8f6e7...c0251f )
by
unknown
39:47 queued 37:41
created

testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
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
        $this->assertEquals('1985/06/20', $element->attr('value'));
58
    }
59
60 View Code Duplication
    public function testIfSingleTextWithDatePickerRenderedCorrectly()
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...
61
    {
62
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
63
        $date = new \DateTime();
64
65
        $element = $crawler->filter('input#form_date_example5');
66
        $wrapper = $element->parents()->filter('.date-widget')->first();
67
68
        $this->assertEquals(1, $element->count());
69
        $this->assertEquals(1, $wrapper->count());
70
71
        $this->assertEquals($date->format('Y/m/j'), $element->attr('value'));
72
    }
73
74
    public function testIfSingleTextWithDatePickerAndOnlyDatesInTheFutureRenderedCorrectly()
75
    {
76
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
77
        $date = new \DateTime();
78
        $startDate = new \DateTime('last monday');
79
80
        $element = $crawler->filter('input#form_date_example6');
81
82
        $this->assertEquals(1, $element->count());
83
84
        // check if it has all the required data-attributes
85
        $this->assertEquals($startDate->format('Y-m-d'), $element->attr('data-date-start-date'));
86
87
        // check if the actual element is hidden
88
        $this->assertEquals($date->format('Y/m/j'), $element->attr('value'));
89
    }
90
91
    public function testIfSingleTextWithDatePickerAndOnlyDatesInThePastRenderedCorrectly()
92
    {
93
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
94
        $date = new \DateTime();
95
        $endDate = new \DateTime('next friday');
96
97
        $element = $crawler->filter('input#form_date_example7');
98
99
        $this->assertEquals(1, $element->count());
100
101
        // check if it has all the required data-attributes
102
        $this->assertEquals($endDate->format('Y-m-d'), $element->attr('data-date-end-date'));
103
104
        // check if the actual element is hidden
105
        $this->assertEquals($date->format('Y/m/j'), $element->attr('value'));
106
    }
107
108
    public function testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly()
109
    {
110
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
111
        $date = new \DateTime();
112
        $startDate = new \DateTime('last monday');
113
        $endDate = new \DateTime('next friday');
114
115
        $element = $crawler->filter('input#form_date_example8');
116
        $wrapper = $element->parents()->filter('.date-widget')->first();
0 ignored issues
show
Unused Code introduced by
$wrapper is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
117
118
        $this->assertEquals(1, $element->count());
119
120
        // check if it has all the required data-attributes
121
        $this->assertEquals($startDate->format('Y-m-d'), $element->attr('data-date-start-date'));
122
        $this->assertEquals($endDate->format('Y-m-d'), $element->attr('data-date-end-date'));
123
124
        // check if the actual element is hidden
125
        $this->assertEquals($date->format('Y/m/j'), $element->attr('value'));
126
    }
127
128 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...
129
    {
130
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
131
132
        $element = $crawler->filter('input#form_date_example9');
133
        $wrapper = $element->parents()->filter('.date-widget')->first();
134
135
        $this->assertEquals(1, $element->count());
136
        $this->assertEquals(1, $wrapper->count());
137
138
        // check if the actual element is hidden
139
        $this->assertEquals('', $element->attr('value'));
140
    }
141
}
142