EventHolderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testEventsWithMonthFilter() 0 8 1
A testEventTags() 0 8 1
A testEventsWithTagFilter() 0 11 1
A testEventsWithDateRangeFilter() 0 11 1
A testExtractMonths() 0 31 1
A testEventWithParentFilter() 0 8 1
1
<?php
2
3
namespace CWP\CWP\Tests\PageTypes;
4
5
use CWP\CWP\PageTypes\EventHolder;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Taxonomy\TaxonomyTerm;
8
9
class EventHolderTest extends SapphireTest
10
{
11
    protected static $fixture_file = 'EventHolderTest.yml';
12
13
    public function testEventTags()
14
    {
15
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
16
17
        $tags = $holder->UpdateTags();
18
        $this->assertNotNull($tags->find('Name', 'Future'), 'Finds present terms.');
19
        $this->assertNull($tags->find('Name', 'Event types', 'Does not find top level taxonomy.'));
20
        $this->assertNull($tags->find('Name', 'Carrot'), 'Does not find terms that are not applied.');
21
    }
22
23
    public function testEventWithParentFilter()
24
    {
25
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder2');
26
27
        $items = $holder->Updates();
28
29
        $this->assertNotNull($items->find('URLSegment', 'other-holder'), 'Event from the holder is shown.');
30
        $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Events from other holders are not shown.');
31
    }
32
33
    public function testEventsWithTagFilter()
34
    {
35
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
36
37
        //Get the "Future" tag.
38
        $tag = $this->objFromFixture(TaxonomyTerm::class, 'TaxonomyTerm1');
39
40
        $items = $holder->Updates($tag->ID);
41
42
        $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the tagged page.');
43
        $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find pages that are not tagged.');
44
    }
45
46
    public function testEventsWithMonthFilter()
47
    {
48
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
49
50
        $items = $holder->Updates(null, null, null, 2013, 7);
51
52
        $this->assertNotNull($items->find('URLSegment', 'future-event-1'), 'Finds the event in 2013-07.');
53
        $this->assertNull($items->find('URLSegment', 'past-event-1'), 'Does not find events at other dates.');
54
    }
55
56
    public function testEventsWithDateRangeFilter()
57
    {
58
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
59
60
        $items = $holder->Updates(null, '2013-01-19', null);
61
        $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds the event at the date');
62
        $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find the event at another date');
63
64
        $items = $holder->Updates(null, '2013-01-01', '2013-01-19');
65
        $this->assertNotNull($items->find('URLSegment', 'past-event-2'), 'Finds events in the date range');
66
        $this->assertNull($items->find('URLSegment', 'future-event-1'), 'Does not find event out of range');
67
    }
68
69
    public function testExtractMonths()
70
    {
71
        $holder = $this->objFromFixture(EventHolder::class, 'EventHolder1');
72
73
        $months = EventHolder::ExtractMonths(
74
            $holder->Updates(),
75
            'http://mybase.org/?tag=12&start=10&from=2010-10-10&to=2010-10-11', // Used for link generation
76
            2013, // Currently selected
77
            1 // Currently selected
78
        );
79
80
        // Check which years are generated.
81
        $this->assertNotNull($months->find('YearName', 2013), 'Generates existing year');
82
        $this->assertNull($months->find('YearName', 1990), 'Does not generate non-present year');
83
84
        $year = $months->find('YearName', 2013);
85
86
        // Check which months come up in 2013
87
        $this->assertNotNull($year['Months']->find('MonthNumber', 7), 'Generates existing month');
88
        $this->assertNull($year['Months']->find('MonthNumber', 12), 'Does not generate non-present month');
89
90
        $month = $year['Months']->find('MonthNumber', 7);
91
        $this->assertEquals(
92
            $month['MonthLink'],
93
            'http://mybase.org/?tag=12&from=2010-10-10&to=2010-10-11&month=7&year=2013',
94
            'Selection link is built properly - start is removed, and tag, from and to retained.'
95
        );
96
97
        // Check if these months are marked properly.
98
        $month = $year['Months']->find('MonthNumber', 1);
99
        $this->assertEquals($month['Active'], true, 'Correctly marks active link');
100
    }
101
}
102