Passed
Pull Request — 2.9 (#308)
by Steve
02:42
created
tests/PageTypes/DatedUpdateHolderControllerTest.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -9,44 +9,44 @@
 block discarded – undo
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
-        /** @var EventHolder $holder */
28
-        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
25
+	public function testSettingDateFiltersInReverseOrderShowsMessage()
26
+	{
27
+		/** @var EventHolder $holder */
28
+		$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
29 29
 
30
-        $result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01');
30
+		$result = $this->get($holder->Link() . '?from=2018-01-10&to=2018-01-01');
31 31
 
32
-        $this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody());
33
-    }
32
+		$this->assertStringContainsString('Filter has been applied with the dates reversed', $result->getBody());
33
+	}
34 34
 
35
-    public function testSettingFromButNotToDateShowsMessage()
36
-    {
37
-        /** @var EventHolder $holder */
38
-        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
35
+	public function testSettingFromButNotToDateShowsMessage()
36
+	{
37
+		/** @var EventHolder $holder */
38
+		$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
39 39
 
40
-        $result = $this->get($holder->Link() . '?from=2018-01-10');
40
+		$result = $this->get($holder->Link() . '?from=2018-01-10');
41 41
 
42
-        $this->assertStringContainsString('Filtered by a single date', $result->getBody());
43
-    }
42
+		$this->assertStringContainsString('Filtered by a single date', $result->getBody());
43
+	}
44 44
 
45
-    public function testInvalidDateFormat()
46
-    {
47
-        /** @var EventHolder $holder */
48
-        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
49
-        $result = $this->get($holder->Link() . '?from=christmas&to=2018-01-10');
50
-        $this->assertStringContainsString(htmlentities('Dates must be in "y-MM-dd" format.'), $result->getBody());
51
-    }
45
+	public function testInvalidDateFormat()
46
+	{
47
+		/** @var EventHolder $holder */
48
+		$holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
49
+		$result = $this->get($holder->Link() . '?from=christmas&to=2018-01-10');
50
+		$this->assertStringContainsString(htmlentities('Dates must be in "y-MM-dd" format.'), $result->getBody());
51
+	}
52 52
 }
Please login to merge, or discard this patch.
tests/PageTypes/SitemapPageTest.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -9,27 +9,27 @@
 block discarded – undo
9 9
 
10 10
 class SitemapPageTest extends FunctionalTest
11 11
 {
12
-    protected static $fixture_file = 'SitemapPageTest.yml';
12
+	protected static $fixture_file = 'SitemapPageTest.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
-        Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']);
21
-        Config::modify()->set(SSViewer::class, 'theme', 'starter');
22
-    }
20
+		Config::modify()->set(SSViewer::class, 'themes', ['starter', '$default']);
21
+		Config::modify()->set(SSViewer::class, 'theme', 'starter');
22
+	}
23 23
 
24
-    /**
25
-     * Note: this test depends on the "starter" theme being installed and configured as default
26
-     */
27
-    public function testSitemapShowsNavigationTitleNotNormalTitle()
28
-    {
29
-        $response = $this->get('sitemap');
30
-        $parser = new CSSContentParser($response->getBody());
31
-        $elements = $parser->getBySelector('.sitemap li.first .sitemap-link');
32
-        $this->assertNotEmpty($elements);
33
-        $this->assertEquals('Top page nav 1', (string) $elements[0]);
34
-    }
24
+	/**
25
+	 * Note: this test depends on the "starter" theme being installed and configured as default
26
+	 */
27
+	public function testSitemapShowsNavigationTitleNotNormalTitle()
28
+	{
29
+		$response = $this->get('sitemap');
30
+		$parser = new CSSContentParser($response->getBody());
31
+		$elements = $parser->getBySelector('.sitemap li.first .sitemap-link');
32
+		$this->assertNotEmpty($elements);
33
+		$this->assertEquals('Top page nav 1', (string) $elements[0]);
34
+	}
35 35
 }
Please login to merge, or discard this patch.
tests/Tasks/PopulateThemeSampleDataTaskTest.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -10,50 +10,50 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
tests/Report/CwpStatsReportTest.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -11,42 +11,42 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
tests/PageTypes/EventHolderTest.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -9,100 +9,100 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.