Passed
Push — 1.6 ( c1892f...19716f )
by Robbie
02:51
created

EventHolderTest::testEventsWithDateRangeFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
class EventHolderTest extends SapphireTest {
4
	static $fixture_file = 'cwp/tests/EventHolderTest.yml';
5
6
	function testEventTags() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7
		$holder = $this->objFromFixture('EventHolder', 'EventHolder1');
8
9
		$tags = $holder->UpdateTags();
10
		$this->assertNotNull($tags->find('Name', 'Future'), 'Finds present terms.');
11
		$this->assertNull($tags->find('Name', 'Event types', 'Does not find top level taxonomy.'));
12
		$this->assertNull($tags->find('Name', 'Carrot'), 'Does not find terms that are not applied.');
13
	}
14
15
	function testEventWithParentFilter() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
		$holder = $this->objFromFixture('EventHolder', 'EventHolder2');
17
18
		$items = $holder->Updates();
19
		
20
		$this->assertNotNull($items->find('URLSegment', 'other-holder'), 'Event from the holder is shown.');
21
		$this->assertNull($items->find('URLSegment', 'future-event-1'), 'Events from other holders are not shown.');
22
	}
23
24
	function testEventsWithTagFilter() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
		$holder = $this->objFromFixture('EventHolder', 'EventHolder1');
26
27
		//Get the "Future" tag.
28
		$tag = $this->objFromFixture('TaxonomyTerm', 'TaxonomyTerm1');
29
30
		$items = $holder->Updates($tag->ID);
31
		
32
		$this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the tagged page.');
33
		$this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find pages that are not tagged.');
34
	}
35
36
	function testEventsWithMonthFilter() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
		$holder = $this->objFromFixture('EventHolder', 'EventHolder1');
38
39
		$items = $holder->Updates(null, null, null, 2013, 7);
40
		
41
		$this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the event in 2013-07.');
42
		$this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find events at other dates.');
43
	}
44
45
	function testEventsWithDateRangeFilter() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
		$holder = $this->objFromFixture('EventHolder', 'EventHolder1');
47
48
		$items = $holder->Updates(null, '2013-01-19', null);
49
		$this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds the event at the date');
50
		$this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find the event at another date');
51
52
		$items = $holder->Updates(null, '2013-01-01', '2013-01-19');
53
		$this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds events in the date range');
54
		$this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find event out of range');
55
	}
56
57
	function testExtractMonths() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
		$holder = $this->objFromFixture('EventHolder', 'EventHolder1');
59
60
		$months = EventHolder::ExtractMonths(
61
			$holder->Updates(),
62
			'http://mybase.org/?tag=12&start=10&from=2010-10-10&to=2010-10-11', // Used for link generation
63
			2013, // Currently selected
64
			1 // Currently selected
65
		);
66
67
		// Check which years are generated.
68
		$this->assertNotNull($months->find('YearName', 2013), 'Generates existing year');
69
		$this->assertNull($months->find('YearName', 1990), 'Does not generate non-present year');
70
71
		$year = $months->find('YearName', 2013);
72
73
		// Check which months come up in 2013
74
		$this->assertNotNull($year['Months']->find('MonthNumber', 7), 'Generates existing month');
75
		$this->assertNull($year['Months']->find('MonthNumber', 12), 'Does not generate non-present month');
76
77
		$month = $year['Months']->find('MonthNumber', 7);
78
		$this->assertEquals(
79
			$month['MonthLink'],
80
			'http://mybase.org/?tag=12&from=2010-10-10&to=2010-10-11&month=7&year=2013',
81
			'Selection link is built properly - start is removed, and tag, from and to retained.'
82
		);
83
84
		// Check if these months are marked properly.
85
		$month = $year['Months']->find('MonthNumber', 1);
86
		$this->assertEquals($month['Active'], true, 'Correctly marks active link');
87
	}
88
}
89