Completed
Push — master ( 67a224...a05403 )
by Simon
02:08
created

ShortlistTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 3
c 5
b 0
f 1
lcom 0
cbo 0
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testShortlistCreation() 0 8 1
A testAddPageToShortlist() 0 9 1
A testRemovePageFromShortlist() 0 12 1
1
<?php
2
3
class ShortlistTest extends FunctionalTest
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected static $fixture_file = 'fixtures.yml';
6
7
	public function testShortlistCreation()
8
	{
9
        $shortlists = ShortList::get();
10
11
        $this->get('shortlist');
12
13
        $this->assertNotEquals($shortlists->Count(), 0);
14
    }
15
16
    public function testAddPageToShortlist() {
17
        $testpage = $this->objFromFixture('Page', 'page1');
18
19
        $this->get('shortlist/add?id=' . $testpage->ID . '&type=Page&s=' . session_id() . '&output=0');
20
21
        $shortlist = DataObject::get_one('ShortList', array('SessionID' => session_id()));
22
23
        $this->assertNotEquals($shortlist->ShortListItems()->Count(), 0);
24
    }
25
26
    public function testRemovePageFromShortlist() {
27
        $shortlist = $this->objFromFixture('ShortList', 'test');
0 ignored issues
show
Unused Code introduced by
$shortlist is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
        $testpage = $this->objFromFixture('Page', 'page1');
29
30
        $this->get('shortlist/add?id=' . $testpage->ID . '&type=Page&s=' . session_id() . '&output=0');
31
32
        $shortlist = DataObject::get_one('ShortList', array('SessionID' => session_id()));
33
34
        $this->get('shortlist/remove?id=' . $testpage->ID . '&type=Page&s=' . session_id() . '&output=0');
35
36
        $this->assertEquals($shortlist->ShortListItems()->Count(), 0);
37
    }
38
}
39