Passed
Pull Request — 2.9 (#308)
by Steve
02:40
created

DatedUpdateHolderControllerTest::isRunningMySQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace CWP\CWP\Tests\PageTypes;
4
5
use CWP\CWP\PageTypes\EventHolder;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\FunctionalTest;
8
use SilverStripe\View\SSViewer;
9
10
class DatedUpdateHolderControllerTest extends FunctionalTest
11
{
12
    protected static $fixture_file = 'EventHolderTest.yml';
13
14
    protected static $use_draft_site = true;
15
16
    protected function setUp(): void
17
    {
18
        parent::setUp();
19
20
        // Note: this test requires the starter theme to be installed
21
        Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']);
22
        Config::modify()->set(SSViewer::class, 'theme', 'starter');
23
    }
24
25
    public function testSettingDateFiltersInReverseOrderShowsMessage()
26
    {
27
        if (!$this->isRunningMySQL()) {
28
            $this->markTestSkipped('Not running MySQL');
29
        }
30
        /** @var EventHolder $holder */
31
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
32
33
        $result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01');
34
35
        $this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody());
36
    }
37
38
    public function testSettingFromButNotToDateShowsMessage()
39
    {
40
        if (!$this->isRunningMySQL()) {
41
            $this->markTestSkipped('Not running MySQL');
42
        }
43
        /** @var EventHolder $holder */
44
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
45
46
        $result = $this->get($holder->Link() . '?from=2018-01-10');
47
48
        $this->assertStringContainsString('Filtered by a single date', $result->getBody());
49
    }
50
51
    public function testInvalidDateFormat()
52
    {
53
        if (!$this->isRunningMySQL()) {
54
            $this->markTestSkipped('Not running MySQL');
55
        }
56
        /** @var EventHolder $holder */
57
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
58
        $result = $this->get($holder->Link() . '?from=christmas&to=2018-01-10');
59
        $this->assertStringContainsString(htmlentities('Dates must be in "y-MM-dd" format.'), $result->getBody());
60
    }
61
62
    /**
63
     * CWP was only designed to run on MySQL, will fail on PGSQL in CI due to DatedUpdateHolder::ExtractMonths()
64
     * using date functions that don't work in PGSQL
65
     */
66
    private function isRunningMySQL()
67
    {
68
        return strpos(strtolower(get_class(DB::get_connector())), 'mysql') !== false;
0 ignored issues
show
Bug introduced by
The type CWP\CWP\Tests\PageTypes\DB was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
    }
70
}
71