@@ -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 | } |