|
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
|
|
|
use SilverStripe\ORM\DB; |
|
10
|
|
|
|
|
11
|
|
|
class DatedUpdateHolderControllerTest extends FunctionalTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected static $fixture_file = 'EventHolderTest.yml'; |
|
14
|
|
|
|
|
15
|
|
|
protected static $use_draft_site = true; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setUp(); |
|
20
|
|
|
|
|
21
|
|
|
// Note: this test requires the starter theme to be installed |
|
22
|
|
|
Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']); |
|
23
|
|
|
Config::modify()->set(SSViewer::class, 'theme', 'starter'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testSettingDateFiltersInReverseOrderShowsMessage() |
|
27
|
|
|
{ |
|
28
|
|
|
if (!$this->isRunningMySQL()) { |
|
29
|
|
|
$this->markTestSkipped('Not running MySQL'); |
|
30
|
|
|
} |
|
31
|
|
|
/** @var EventHolder $holder */ |
|
32
|
|
|
$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
33
|
|
|
|
|
34
|
|
|
$result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01'); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testSettingFromButNotToDateShowsMessage() |
|
40
|
|
|
{ |
|
41
|
|
|
if (!$this->isRunningMySQL()) { |
|
42
|
|
|
$this->markTestSkipped('Not running MySQL'); |
|
43
|
|
|
} |
|
44
|
|
|
/** @var EventHolder $holder */ |
|
45
|
|
|
$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
46
|
|
|
|
|
47
|
|
|
$result = $this->get($holder->Link() . '?from=2018-01-10'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertStringContainsString('Filtered by a single date', $result->getBody()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testInvalidDateFormat() |
|
53
|
|
|
{ |
|
54
|
|
|
if (!$this->isRunningMySQL()) { |
|
55
|
|
|
$this->markTestSkipped('Not running MySQL'); |
|
56
|
|
|
} |
|
57
|
|
|
/** @var EventHolder $holder */ |
|
58
|
|
|
$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
59
|
|
|
$result = $this->get($holder->Link() . '?from=christmas&to=2018-01-10'); |
|
60
|
|
|
$this->assertStringContainsString(htmlentities('Dates must be in "y-MM-dd" format.'), $result->getBody()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* CWP was only designed to run on MySQL, will fail on PGSQL in CI due to DatedUpdateHolder::ExtractMonths() |
|
65
|
|
|
* using date functions that don't work in PGSQL |
|
66
|
|
|
*/ |
|
67
|
|
|
private function isRunningMySQL() |
|
68
|
|
|
{ |
|
69
|
|
|
return strpos(strtolower(get_class(DB::get_connector())), 'mysql') !== false; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|