Completed
Push — master ( 18f749...9fc766 )
by Gordon
17:08 queued 02:10
created

AttachedGalleryExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetCMSFields() 0 15 2
B testInlineGalleries() 0 33 2
1
<?php
2
3
class AttachedGalleryExtensionTest extends TestWithImage {
0 ignored issues
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
    protected static $fixture_file = 'ss3gallery/tests/ss3gallery.yml';
5
6
    /*
7
    Check for the attached gallery tab, and that a gallery can be attached
8
     */
9
    public function testGetCMSFields()
10
    {
11
        Page::add_extension('AttachedGalleryExtension');
12
        $page = new Page();
13
14
        $tab = $page->getCMSFields()->fieldByName('Root.AttachedGallery');
15
        $fields = $tab->FieldList();
16
        $names = array();
17
        foreach ($fields as $field) {
18
            array_push($names, $field->getName());
19
        }
20
        $expected = array('AttachedGalleryID');
21
        $this->assertEquals($expected, $names);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
        Page::remove_extension('AttachedGalleryExtension');
23
    }
24
25
    public function testInlineGalleries() {
26
        Page::add_extension('AttachedGalleryExtension');
27
        // this page is alone at the top level
28
        $page = $this->objFromFixture('Page', 'page02');
29
        $this->assertEquals(0, $page->InlineGalleries()->count());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        // Check for an attached gallery
32
        $gallery1 = $this->objFromFixture('GalleryPage', 'gp01');
33
        $page->AttachedGalleryID = $gallery1->ID;
34
        $page->write();
35
        $expected = array($page);
1 ignored issue
show
Unused Code introduced by
$expected 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...
36
        $this->assertEquals('Test Gallery 1', $page->InlineGalleries()->first()->Title);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        $this->assertEquals(1, $page->InlineGalleries()->count());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
        // Now add child galleries as well
40
        $gallery2 = $this->objFromFixture('GalleryPage', 'gp02');
41
        $gallery2->ParentID = $page->ID;
42
        $gallery2->write();
43
44
        $gallery3 = $this->objFromFixture('GalleryPage', 'gp03');
45
        $gallery3->ParentID = $page->ID;
46
        $gallery3->write();
47
48
        $this->assertEquals(3, $page->InlineGalleries()->count());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        $titles = array();
50
        foreach ($page->InlineGalleries() as $gallery) {
51
            array_push($titles, $gallery->Title);
52
        }
53
        $expected = array('Test Gallery 2', 'Test Gallery 3', 'Test Gallery 1');
54
        $this->assertEquals($expected, $titles);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<AttachedGalleryExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        Page::remove_extension('AttachedGalleryExtension');
56
57
    }
58
}
59