@@ -10,50 +10,50 @@ |
||
10 | 10 | |
11 | 11 | class PopulateThemeSampleDataTaskTest extends SapphireTest |
12 | 12 | { |
13 | - protected $usesDatabase = true; |
|
14 | - |
|
15 | - /** |
|
16 | - * Ensure that the "contact" user form is only created once |
|
17 | - */ |
|
18 | - public function testOnlyCreateContactFormOnce() |
|
19 | - { |
|
20 | - if (!class_exists(UserDefinedForm::class)) { |
|
21 | - $this->markTestSkipped('This test requires the userforms module to be installed'); |
|
22 | - } |
|
23 | - |
|
24 | - $createdMessage = 'Created "contact" UserDefinedForm'; |
|
25 | - |
|
26 | - $task = new PopulateThemeSampleDataTask; |
|
27 | - |
|
28 | - // Run the task |
|
29 | - $this->assertStringContainsString($createdMessage, $this->bufferedTask($task)); |
|
30 | - |
|
31 | - // Run a second time |
|
32 | - $this->assertStringNotContainsString($createdMessage, $this->bufferedTask($task)); |
|
33 | - |
|
34 | - // Change the page name |
|
35 | - $form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first(); |
|
36 | - $form->URLSegment = 'testing'; |
|
37 | - $form->write(); |
|
38 | - |
|
39 | - // Ensure the old version is still detected in draft, so not recreated |
|
40 | - $this->assertStringNotContainsString($createdMessage, $this->bufferedTask($task)); |
|
41 | - |
|
42 | - // Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions) |
|
43 | - $form->delete(); |
|
44 | - $this->assertStringContainsString($createdMessage, $this->bufferedTask($task)); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Run a BuildTask while buffering its output, and return the result |
|
49 | - * |
|
50 | - * @param BuildTask $task |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - protected function bufferedTask(BuildTask $task) |
|
54 | - { |
|
55 | - ob_start(); |
|
56 | - $task->run(new HTTPRequest('GET', '/')); |
|
57 | - return ob_get_clean(); |
|
58 | - } |
|
13 | + protected $usesDatabase = true; |
|
14 | + |
|
15 | + /** |
|
16 | + * Ensure that the "contact" user form is only created once |
|
17 | + */ |
|
18 | + public function testOnlyCreateContactFormOnce() |
|
19 | + { |
|
20 | + if (!class_exists(UserDefinedForm::class)) { |
|
21 | + $this->markTestSkipped('This test requires the userforms module to be installed'); |
|
22 | + } |
|
23 | + |
|
24 | + $createdMessage = 'Created "contact" UserDefinedForm'; |
|
25 | + |
|
26 | + $task = new PopulateThemeSampleDataTask; |
|
27 | + |
|
28 | + // Run the task |
|
29 | + $this->assertStringContainsString($createdMessage, $this->bufferedTask($task)); |
|
30 | + |
|
31 | + // Run a second time |
|
32 | + $this->assertStringNotContainsString($createdMessage, $this->bufferedTask($task)); |
|
33 | + |
|
34 | + // Change the page name |
|
35 | + $form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first(); |
|
36 | + $form->URLSegment = 'testing'; |
|
37 | + $form->write(); |
|
38 | + |
|
39 | + // Ensure the old version is still detected in draft, so not recreated |
|
40 | + $this->assertStringNotContainsString($createdMessage, $this->bufferedTask($task)); |
|
41 | + |
|
42 | + // Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions) |
|
43 | + $form->delete(); |
|
44 | + $this->assertStringContainsString($createdMessage, $this->bufferedTask($task)); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Run a BuildTask while buffering its output, and return the result |
|
49 | + * |
|
50 | + * @param BuildTask $task |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + protected function bufferedTask(BuildTask $task) |
|
54 | + { |
|
55 | + ob_start(); |
|
56 | + $task->run(new HTTPRequest('GET', '/')); |
|
57 | + return ob_get_clean(); |
|
58 | + } |
|
59 | 59 | } |
@@ -11,42 +11,42 @@ |
||
11 | 11 | |
12 | 12 | class CwpStatsReportTest extends SapphireTest |
13 | 13 | { |
14 | - protected static $fixture_file = 'CwpStatsReportTest.yml'; |
|
15 | - |
|
16 | - protected function setUp(): void |
|
17 | - { |
|
18 | - Config::modify()->set(SiteTree::class, 'create_default_pages', false); |
|
19 | - |
|
20 | - parent::setUp(); |
|
21 | - } |
|
22 | - |
|
23 | - public function testCount() |
|
24 | - { |
|
25 | - // Publish all pages apart from page3. |
|
26 | - $this->objFromFixture(Page::class, 'page1')->publishRecursive(); |
|
27 | - $this->objFromFixture(Page::class, 'page2')->publishRecursive(); |
|
28 | - $this->objFromFixture(Page::class, 'page3')->publishRecursive(); |
|
29 | - |
|
30 | - // Add page5s to a subsite, if the module is installed. |
|
31 | - $page5s = $this->objFromFixture(Page::class, 'page5s'); |
|
32 | - if (class_exists(Subsite::class)) { |
|
33 | - $subsite = Subsite::create(); |
|
34 | - $subsite->Title = 'subsite'; |
|
35 | - $subsite->write(); |
|
36 | - |
|
37 | - $page5s->SubsiteID = $subsite->ID; |
|
38 | - $page5s->write(); |
|
39 | - } |
|
40 | - $page5s->publishRecursive(); |
|
41 | - |
|
42 | - $report = CwpStatsReport::create(); |
|
43 | - $records = $report->sourceRecords([])->toArray(); |
|
44 | - $i = 0; |
|
45 | - $this->assertEquals(4, $records[$i++]['Count'], 'Four pages in total, across locales, subsites, live only.'); |
|
46 | - if (class_exists(Subsite::class)) { |
|
47 | - $this->assertEquals(3, $records[$i++]['Count'], 'Three pages in the main site, if subsites installed.'); |
|
48 | - $this->assertEquals(1, $records[$i++]['Count'], 'One page in the subsite, if subsites installed'); |
|
49 | - } |
|
50 | - $this->assertEquals(1, $records[$i++]['Count'], 'One file in total.'); |
|
51 | - } |
|
14 | + protected static $fixture_file = 'CwpStatsReportTest.yml'; |
|
15 | + |
|
16 | + protected function setUp(): void |
|
17 | + { |
|
18 | + Config::modify()->set(SiteTree::class, 'create_default_pages', false); |
|
19 | + |
|
20 | + parent::setUp(); |
|
21 | + } |
|
22 | + |
|
23 | + public function testCount() |
|
24 | + { |
|
25 | + // Publish all pages apart from page3. |
|
26 | + $this->objFromFixture(Page::class, 'page1')->publishRecursive(); |
|
27 | + $this->objFromFixture(Page::class, 'page2')->publishRecursive(); |
|
28 | + $this->objFromFixture(Page::class, 'page3')->publishRecursive(); |
|
29 | + |
|
30 | + // Add page5s to a subsite, if the module is installed. |
|
31 | + $page5s = $this->objFromFixture(Page::class, 'page5s'); |
|
32 | + if (class_exists(Subsite::class)) { |
|
33 | + $subsite = Subsite::create(); |
|
34 | + $subsite->Title = 'subsite'; |
|
35 | + $subsite->write(); |
|
36 | + |
|
37 | + $page5s->SubsiteID = $subsite->ID; |
|
38 | + $page5s->write(); |
|
39 | + } |
|
40 | + $page5s->publishRecursive(); |
|
41 | + |
|
42 | + $report = CwpStatsReport::create(); |
|
43 | + $records = $report->sourceRecords([])->toArray(); |
|
44 | + $i = 0; |
|
45 | + $this->assertEquals(4, $records[$i++]['Count'], 'Four pages in total, across locales, subsites, live only.'); |
|
46 | + if (class_exists(Subsite::class)) { |
|
47 | + $this->assertEquals(3, $records[$i++]['Count'], 'Three pages in the main site, if subsites installed.'); |
|
48 | + $this->assertEquals(1, $records[$i++]['Count'], 'One page in the subsite, if subsites installed'); |
|
49 | + } |
|
50 | + $this->assertEquals(1, $records[$i++]['Count'], 'One file in total.'); |
|
51 | + } |
|
52 | 52 | } |
@@ -9,100 +9,100 @@ |
||
9 | 9 | |
10 | 10 | class EventHolderTest extends SapphireTest |
11 | 11 | { |
12 | - protected static $fixture_file = 'EventHolderTest.yml'; |
|
13 | - |
|
14 | - public function testEventTags() |
|
15 | - { |
|
16 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
17 | - |
|
18 | - $tags = $holder->UpdateTags(); |
|
19 | - $this->assertNotNull($tags->find('Name', 'Future'), 'Finds present terms.'); |
|
20 | - $this->assertNull($tags->find('Name', 'Event types', 'Does not find top level taxonomy.')); |
|
21 | - $this->assertNull($tags->find('Name', 'Carrot'), 'Does not find terms that are not applied.'); |
|
22 | - } |
|
23 | - |
|
24 | - public function testEventWithParentFilter() |
|
25 | - { |
|
26 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder2'); |
|
27 | - |
|
28 | - $items = $holder->Updates(); |
|
29 | - |
|
30 | - $this->assertNotNull($items->find('URLSegment', 'other-holder'), 'Event from the holder is shown.'); |
|
31 | - $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Events from other holders are not shown.'); |
|
32 | - } |
|
33 | - |
|
34 | - public function testEventsWithTagFilter() |
|
35 | - { |
|
36 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
37 | - |
|
38 | - //Get the "Future" tag. |
|
39 | - $tag = $this->objFromFixture(TaxonomyTerm::class, 'TaxonomyTerm1'); |
|
40 | - |
|
41 | - $items = $holder->Updates($tag->ID); |
|
42 | - |
|
43 | - $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the tagged page.'); |
|
44 | - $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find pages that are not tagged.'); |
|
45 | - } |
|
46 | - |
|
47 | - public function testEventsWithMonthFilter() |
|
48 | - { |
|
49 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
50 | - |
|
51 | - $items = $holder->Updates(null, null, null, 2013, 7); |
|
52 | - |
|
53 | - $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the event in 2013-07.'); |
|
54 | - $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find events at other dates.'); |
|
55 | - } |
|
56 | - |
|
57 | - public function testEventsWithDateRangeFilter() |
|
58 | - { |
|
59 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
60 | - |
|
61 | - $items = $holder->Updates(null, '2013-01-19', null); |
|
62 | - $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds the event at the date'); |
|
63 | - $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find the event at another date'); |
|
64 | - |
|
65 | - $items = $holder->Updates(null, '2013-01-01', '2013-01-19'); |
|
66 | - $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds events in the date range'); |
|
67 | - $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find event out of range'); |
|
68 | - } |
|
69 | - |
|
70 | - public function testExtractMonths() |
|
71 | - { |
|
72 | - // skip test on PGSQL CI, CWP was only designed to work on MySQL |
|
73 | - // DatedUpdateHolder::ExtractMonths contains date functions e.g. YEAR("Date") which don't work in PGSQL |
|
74 | - if (strpos(strtolower(get_class(DB::get_connector())), 'mysql') === false) { |
|
75 | - $this->markTestSkipped('Not running MySQL'); |
|
76 | - } |
|
77 | - |
|
78 | - $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
79 | - |
|
80 | - $months = EventHolder::ExtractMonths( |
|
81 | - $holder->Updates(), |
|
82 | - 'http://mybase.org/?tag=12&start=10&from=2010-10-10&to=2010-10-11', // Used for link generation |
|
83 | - 2013, // Currently selected |
|
84 | - 1 // Currently selected |
|
85 | - ); |
|
86 | - |
|
87 | - // Check which years are generated. |
|
88 | - $this->assertNotNull($months->find('YearName', 2013), 'Generates existing year'); |
|
89 | - $this->assertNull($months->find('YearName', 1990), 'Does not generate non-present year'); |
|
90 | - |
|
91 | - $year = $months->find('YearName', 2013); |
|
92 | - |
|
93 | - // Check which months come up in 2013 |
|
94 | - $this->assertNotNull($year['Months']->find('MonthNumber', 7), 'Generates existing month'); |
|
95 | - $this->assertNull($year['Months']->find('MonthNumber', 12), 'Does not generate non-present month'); |
|
96 | - |
|
97 | - $month = $year['Months']->find('MonthNumber', 7); |
|
98 | - $this->assertEquals( |
|
99 | - $month['MonthLink'], |
|
100 | - 'http://mybase.org/?tag=12&from=2010-10-10&to=2010-10-11&month=7&year=2013', |
|
101 | - 'Selection link is built properly - start is removed, and tag, from and to retained.' |
|
102 | - ); |
|
103 | - |
|
104 | - // Check if these months are marked properly. |
|
105 | - $month = $year['Months']->find('MonthNumber', 1); |
|
106 | - $this->assertEquals($month['Active'], true, 'Correctly marks active link'); |
|
107 | - } |
|
12 | + protected static $fixture_file = 'EventHolderTest.yml'; |
|
13 | + |
|
14 | + public function testEventTags() |
|
15 | + { |
|
16 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
17 | + |
|
18 | + $tags = $holder->UpdateTags(); |
|
19 | + $this->assertNotNull($tags->find('Name', 'Future'), 'Finds present terms.'); |
|
20 | + $this->assertNull($tags->find('Name', 'Event types', 'Does not find top level taxonomy.')); |
|
21 | + $this->assertNull($tags->find('Name', 'Carrot'), 'Does not find terms that are not applied.'); |
|
22 | + } |
|
23 | + |
|
24 | + public function testEventWithParentFilter() |
|
25 | + { |
|
26 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder2'); |
|
27 | + |
|
28 | + $items = $holder->Updates(); |
|
29 | + |
|
30 | + $this->assertNotNull($items->find('URLSegment', 'other-holder'), 'Event from the holder is shown.'); |
|
31 | + $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Events from other holders are not shown.'); |
|
32 | + } |
|
33 | + |
|
34 | + public function testEventsWithTagFilter() |
|
35 | + { |
|
36 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
37 | + |
|
38 | + //Get the "Future" tag. |
|
39 | + $tag = $this->objFromFixture(TaxonomyTerm::class, 'TaxonomyTerm1'); |
|
40 | + |
|
41 | + $items = $holder->Updates($tag->ID); |
|
42 | + |
|
43 | + $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the tagged page.'); |
|
44 | + $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find pages that are not tagged.'); |
|
45 | + } |
|
46 | + |
|
47 | + public function testEventsWithMonthFilter() |
|
48 | + { |
|
49 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
50 | + |
|
51 | + $items = $holder->Updates(null, null, null, 2013, 7); |
|
52 | + |
|
53 | + $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the event in 2013-07.'); |
|
54 | + $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find events at other dates.'); |
|
55 | + } |
|
56 | + |
|
57 | + public function testEventsWithDateRangeFilter() |
|
58 | + { |
|
59 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
60 | + |
|
61 | + $items = $holder->Updates(null, '2013-01-19', null); |
|
62 | + $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds the event at the date'); |
|
63 | + $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find the event at another date'); |
|
64 | + |
|
65 | + $items = $holder->Updates(null, '2013-01-01', '2013-01-19'); |
|
66 | + $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds events in the date range'); |
|
67 | + $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find event out of range'); |
|
68 | + } |
|
69 | + |
|
70 | + public function testExtractMonths() |
|
71 | + { |
|
72 | + // skip test on PGSQL CI, CWP was only designed to work on MySQL |
|
73 | + // DatedUpdateHolder::ExtractMonths contains date functions e.g. YEAR("Date") which don't work in PGSQL |
|
74 | + if (strpos(strtolower(get_class(DB::get_connector())), 'mysql') === false) { |
|
75 | + $this->markTestSkipped('Not running MySQL'); |
|
76 | + } |
|
77 | + |
|
78 | + $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1'); |
|
79 | + |
|
80 | + $months = EventHolder::ExtractMonths( |
|
81 | + $holder->Updates(), |
|
82 | + 'http://mybase.org/?tag=12&start=10&from=2010-10-10&to=2010-10-11', // Used for link generation |
|
83 | + 2013, // Currently selected |
|
84 | + 1 // Currently selected |
|
85 | + ); |
|
86 | + |
|
87 | + // Check which years are generated. |
|
88 | + $this->assertNotNull($months->find('YearName', 2013), 'Generates existing year'); |
|
89 | + $this->assertNull($months->find('YearName', 1990), 'Does not generate non-present year'); |
|
90 | + |
|
91 | + $year = $months->find('YearName', 2013); |
|
92 | + |
|
93 | + // Check which months come up in 2013 |
|
94 | + $this->assertNotNull($year['Months']->find('MonthNumber', 7), 'Generates existing month'); |
|
95 | + $this->assertNull($year['Months']->find('MonthNumber', 12), 'Does not generate non-present month'); |
|
96 | + |
|
97 | + $month = $year['Months']->find('MonthNumber', 7); |
|
98 | + $this->assertEquals( |
|
99 | + $month['MonthLink'], |
|
100 | + 'http://mybase.org/?tag=12&from=2010-10-10&to=2010-10-11&month=7&year=2013', |
|
101 | + 'Selection link is built properly - start is removed, and tag, from and to retained.' |
|
102 | + ); |
|
103 | + |
|
104 | + // Check if these months are marked properly. |
|
105 | + $month = $year['Months']->find('MonthNumber', 1); |
|
106 | + $this->assertEquals($month['Active'], true, 'Correctly marks active link'); |
|
107 | + } |
|
108 | 108 | } |
@@ -9,62 +9,62 @@ |
||
9 | 9 | |
10 | 10 | class DatedUpdateHolderControllerTest extends FunctionalTest |
11 | 11 | { |
12 | - protected static $fixture_file = 'EventHolderTest.yml'; |
|
12 | + protected static $fixture_file = 'EventHolderTest.yml'; |
|
13 | 13 | |
14 | - protected static $use_draft_site = true; |
|
14 | + protected static $use_draft_site = true; |
|
15 | 15 | |
16 | - protected function setUp(): void |
|
17 | - { |
|
18 | - parent::setUp(); |
|
16 | + protected function setUp(): void |
|
17 | + { |
|
18 | + parent::setUp(); |
|
19 | 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 | - } |
|
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 | 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'); |
|
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 | 32 | |
33 | - $result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01'); |
|
33 | + $result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01'); |
|
34 | 34 | |
35 | - $this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody()); |
|
36 | - } |
|
35 | + $this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody()); |
|
36 | + } |
|
37 | 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'); |
|
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 | 45 | |
46 | - $result = $this->get($holder->Link() . '?from=2018-01-10'); |
|
46 | + $result = $this->get($holder->Link() . '?from=2018-01-10'); |
|
47 | 47 | |
48 | - $this->assertStringContainsString('Filtered by a single date', $result->getBody()); |
|
49 | - } |
|
48 | + $this->assertStringContainsString('Filtered by a single date', $result->getBody()); |
|
49 | + } |
|
50 | 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 | - } |
|
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 | 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; |
|
69 | - } |
|
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; |
|
69 | + } |
|
70 | 70 | } |
@@ -15,121 +15,121 @@ |
||
15 | 15 | */ |
16 | 16 | class Quicklink extends DataObject |
17 | 17 | { |
18 | - private static $db = [ |
|
19 | - 'Name' => 'Varchar(255)', |
|
20 | - 'ExternalLink' => 'Varchar(255)', |
|
21 | - 'SortOrder' => 'Int', |
|
22 | - ]; |
|
23 | - |
|
24 | - private static $has_one = [ |
|
25 | - 'Parent' => BaseHomePage::class, |
|
26 | - 'InternalLink' => SiteTree::class, |
|
27 | - ]; |
|
28 | - |
|
29 | - private static $summary_fields = [ |
|
30 | - 'Name' => 'Name', |
|
31 | - 'InternalLink.Title' => 'Internal Link', |
|
32 | - 'ExternalLink' => 'External Link', |
|
33 | - ]; |
|
34 | - |
|
35 | - private static $table_name = 'Quicklink'; |
|
36 | - |
|
37 | - public function fieldLabels($includerelations = true) |
|
38 | - { |
|
39 | - $labels = parent::fieldLabels($includerelations); |
|
40 | - $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
41 | - $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
42 | - $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
43 | - $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
44 | - $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
45 | - |
|
46 | - return $labels; |
|
47 | - } |
|
48 | - |
|
49 | - public function getLink() |
|
50 | - { |
|
51 | - if ($this->ExternalLink) { |
|
52 | - $url = parse_url($this->ExternalLink ?? ''); |
|
53 | - |
|
54 | - // if no scheme set in the link, default to http |
|
55 | - if (!isset($url['scheme'])) { |
|
56 | - return 'http://' . $this->ExternalLink; |
|
57 | - } |
|
58 | - |
|
59 | - return $this->ExternalLink; |
|
60 | - } |
|
61 | - |
|
62 | - if ($this->InternalLinkID) { |
|
63 | - return $this->InternalLink()->Link(); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - public function canCreate($member = null, $context = []) |
|
68 | - { |
|
69 | - // Creating quick links should not be the same permission level as creating parent pages for them, they're |
|
70 | - // essentially content in the context of the page, so use the edit permission instead. |
|
71 | - return $this->canEdit($member); |
|
72 | - } |
|
73 | - |
|
74 | - public function canEdit($member = null) |
|
75 | - { |
|
76 | - return $this->Parent()->canEdit($member); |
|
77 | - } |
|
78 | - |
|
79 | - public function canDelete($member = null) |
|
80 | - { |
|
81 | - return $this->Parent()->canDelete($member); |
|
82 | - } |
|
83 | - |
|
84 | - public function canView($member = null) |
|
85 | - { |
|
86 | - return $this->Parent()->canView($member); |
|
87 | - } |
|
88 | - |
|
89 | - public function getCMSFields() |
|
90 | - { |
|
91 | - $fields = parent::getCMSFields(); |
|
92 | - |
|
93 | - $fields->removeByName('ParentID'); |
|
94 | - |
|
95 | - $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
96 | - |
|
97 | - $fields->removeByName('ExternalLink'); |
|
98 | - $fields->removeByName('InternalLinkID'); |
|
99 | - $fields->removeByName('SortOrder'); |
|
100 | - $externalLinkField->addExtraClass('noBorder'); |
|
101 | - |
|
102 | - $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
103 | - array( |
|
104 | - TreeDropdownField::create( |
|
105 | - 'InternalLinkID', |
|
106 | - $this->fieldLabel('InternalLinkID'), |
|
107 | - SiteTree::class |
|
108 | - ), |
|
109 | - $externalLinkField, |
|
110 | - $wrap = CompositeField::create( |
|
111 | - $extraLabel = LiteralField::create( |
|
112 | - 'NoteOverride', |
|
113 | - sprintf('<div class="message good notice">%s</div>', _t( |
|
114 | - __CLASS__ . '.Note', |
|
115 | - 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
116 | - )) |
|
117 | - ) |
|
118 | - ) |
|
119 | - ) |
|
120 | - )); |
|
121 | - $fields->insertBefore( |
|
122 | - 'Name', |
|
123 | - LiteralField::create( |
|
124 | - 'Note', |
|
125 | - sprintf('<p>%s</p>', _t( |
|
126 | - __CLASS__ . '.Note2', |
|
127 | - 'Use this to specify a link to a page either on this site ' |
|
128 | - . '(Internal Link) or another site (External Link).' |
|
129 | - )) |
|
130 | - ) |
|
131 | - ); |
|
132 | - |
|
133 | - return $fields; |
|
134 | - } |
|
18 | + private static $db = [ |
|
19 | + 'Name' => 'Varchar(255)', |
|
20 | + 'ExternalLink' => 'Varchar(255)', |
|
21 | + 'SortOrder' => 'Int', |
|
22 | + ]; |
|
23 | + |
|
24 | + private static $has_one = [ |
|
25 | + 'Parent' => BaseHomePage::class, |
|
26 | + 'InternalLink' => SiteTree::class, |
|
27 | + ]; |
|
28 | + |
|
29 | + private static $summary_fields = [ |
|
30 | + 'Name' => 'Name', |
|
31 | + 'InternalLink.Title' => 'Internal Link', |
|
32 | + 'ExternalLink' => 'External Link', |
|
33 | + ]; |
|
34 | + |
|
35 | + private static $table_name = 'Quicklink'; |
|
36 | + |
|
37 | + public function fieldLabels($includerelations = true) |
|
38 | + { |
|
39 | + $labels = parent::fieldLabels($includerelations); |
|
40 | + $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
41 | + $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
42 | + $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
43 | + $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
44 | + $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
45 | + |
|
46 | + return $labels; |
|
47 | + } |
|
48 | + |
|
49 | + public function getLink() |
|
50 | + { |
|
51 | + if ($this->ExternalLink) { |
|
52 | + $url = parse_url($this->ExternalLink ?? ''); |
|
53 | + |
|
54 | + // if no scheme set in the link, default to http |
|
55 | + if (!isset($url['scheme'])) { |
|
56 | + return 'http://' . $this->ExternalLink; |
|
57 | + } |
|
58 | + |
|
59 | + return $this->ExternalLink; |
|
60 | + } |
|
61 | + |
|
62 | + if ($this->InternalLinkID) { |
|
63 | + return $this->InternalLink()->Link(); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + public function canCreate($member = null, $context = []) |
|
68 | + { |
|
69 | + // Creating quick links should not be the same permission level as creating parent pages for them, they're |
|
70 | + // essentially content in the context of the page, so use the edit permission instead. |
|
71 | + return $this->canEdit($member); |
|
72 | + } |
|
73 | + |
|
74 | + public function canEdit($member = null) |
|
75 | + { |
|
76 | + return $this->Parent()->canEdit($member); |
|
77 | + } |
|
78 | + |
|
79 | + public function canDelete($member = null) |
|
80 | + { |
|
81 | + return $this->Parent()->canDelete($member); |
|
82 | + } |
|
83 | + |
|
84 | + public function canView($member = null) |
|
85 | + { |
|
86 | + return $this->Parent()->canView($member); |
|
87 | + } |
|
88 | + |
|
89 | + public function getCMSFields() |
|
90 | + { |
|
91 | + $fields = parent::getCMSFields(); |
|
92 | + |
|
93 | + $fields->removeByName('ParentID'); |
|
94 | + |
|
95 | + $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
96 | + |
|
97 | + $fields->removeByName('ExternalLink'); |
|
98 | + $fields->removeByName('InternalLinkID'); |
|
99 | + $fields->removeByName('SortOrder'); |
|
100 | + $externalLinkField->addExtraClass('noBorder'); |
|
101 | + |
|
102 | + $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
103 | + array( |
|
104 | + TreeDropdownField::create( |
|
105 | + 'InternalLinkID', |
|
106 | + $this->fieldLabel('InternalLinkID'), |
|
107 | + SiteTree::class |
|
108 | + ), |
|
109 | + $externalLinkField, |
|
110 | + $wrap = CompositeField::create( |
|
111 | + $extraLabel = LiteralField::create( |
|
112 | + 'NoteOverride', |
|
113 | + sprintf('<div class="message good notice">%s</div>', _t( |
|
114 | + __CLASS__ . '.Note', |
|
115 | + 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
116 | + )) |
|
117 | + ) |
|
118 | + ) |
|
119 | + ) |
|
120 | + )); |
|
121 | + $fields->insertBefore( |
|
122 | + 'Name', |
|
123 | + LiteralField::create( |
|
124 | + 'Note', |
|
125 | + sprintf('<p>%s</p>', _t( |
|
126 | + __CLASS__ . '.Note2', |
|
127 | + 'Use this to specify a link to a page either on this site ' |
|
128 | + . '(Internal Link) or another site (External Link).' |
|
129 | + )) |
|
130 | + ) |
|
131 | + ); |
|
132 | + |
|
133 | + return $fields; |
|
134 | + } |
|
135 | 135 | } |