Passed
Push — 1 ( 7aa2c3 )
by Robbie
02:48
created

EventHolderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 22.62 %

Importance

Changes 0
Metric Value
wmc 6
dl 19
loc 84
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testEventsWithTagFilter() 10 10 1
A testEventWithParentFilter() 0 7 1
B testExtractMonths() 0 30 1
A testEventsWithMonthFilter() 0 7 1
A testEventTags() 7 7 1
A testEventsWithDateRangeFilter() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class EventHolderTest extends SapphireTest {
4
	static $fixture_file = 'cwp/tests/EventHolderTest.yml';
5
6 View Code Duplication
	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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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 View Code Duplication
	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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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