Completed
Push — master ( f7234f...d97733 )
by
unknown
05:19
created

testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 10
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
    public function testIfChoiceRenderedCorrectly()
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
    public function testIfSingleTextRenderedCorrectly()
33
    {
34
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
35
36
        $this->assertEquals(1, $crawler->filter('input#form_date_example2')->count());
37
    }
38
39 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...
40
    {
41
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
42
43
        $element = $crawler->filter('input#form_date_example3');
44
45
        $this->assertEquals(1, $element->count());
46
        $this->assertEquals('20/06/1985', $element->attr('value'));
47
    }
48
49 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...
50
    {
51
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
52
        $date = new \DateTime();
53
54
        $element = $crawler->filter('input#form_date_example4');
55
56
        $this->assertEquals(1, $element->count());
57
58
        $this->assertEquals($date->format('d/m/Y'), $element->attr('value'));
59
    }
60
61 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...
62
    {
63
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
64
        $date = new \DateTime();
65
        $startDate = new \DateTime('last monday');
66
67
        $element = $crawler->filter('input#form_date_example5');
68
69
        $this->assertEquals(1, $element->count());
70
71
        // check if it has all the required data-attributes
72
        $this->assertEquals($startDate->format('d/m/Y'), $element->attr('data-date-start-date'));
73
74
        // check if the actual element is hidden
75
        $this->assertEquals($date->format('d/m/Y'), $element->attr('value'));
76
    }
77
78 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...
79
    {
80
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
81
        $date = new \DateTime();
82
        $endDate = new \DateTime('next friday');
83
84
        $element = $crawler->filter('input#form_date_example6');
85
86
        $this->assertEquals(1, $element->count());
87
88
        // check if it has all the required data-attributes
89
        $this->assertEquals($endDate->format('d/m/Y'), $element->attr('data-date-end-date'));
90
91
        // check if the actual element is hidden
92
        $this->assertEquals($date->format('d/m/Y'), $element->attr('value'));
93
    }
94
95
    public function testIfSingleTextWithDatePickerAndOnlyDatesBetweenCorrectly()
96
    {
97
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
98
        $date = new \DateTime();
99
        $startDate = new \DateTime('last monday');
100
        $endDate = new \DateTime('next friday');
101
102
        $element = $crawler->filter('input#form_date_example7');
103
104
        $this->assertEquals(1, $element->count());
105
106
        // check if it has all the required data-attributes
107
        $this->assertEquals($startDate->format('d/m/Y'), $element->attr('data-date-start-date'));
108
        $this->assertEquals($endDate->format('d/m/Y'), $element->attr('data-date-end-date'));
109
110
        // check if the actual element is hidden
111
        $this->assertEquals($date->format('d/m/Y'), $element->attr('value'));
112
    }
113
114 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...
115
    {
116
        $crawler = $this->getCrawlerForRequest('GET', '/_tests/datepicker');
117
118
        $element = $crawler->filter('input#form_date_example8');
119
120
        $this->assertEquals(1, $element->count());
121
122
        // check if the actual element is hidden
123
        $this->assertEquals('', $element->attr('value'));
124
    }
125
}
126