Completed
Push — develop ( e1bb7c...f2e809 )
by Dylan
02:52
created

AutomatedLinkTest::createPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
class AutomatedLinkTest extends SapphireTest {
4
5
    public static $fixture_file = 'fixtures/AutomatedLinkTest.yml';
6
7
    public function testInsertion(){
8
        $this->objFromFixture('AutomatedLink','link1');
9
10
        $page   = $this->createPage('test-1', '<p>Checking if phrase is replaced</p>');
0 ignored issues
show
Unused Code introduced by
The call to AutomatedLinkTest::createPage() has too many arguments starting with '<p>Checking if phrase is replaced</p>'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
11
        $dom    = $this->getPageDOM($page);
12
        $links  = $dom->getElementsByTagName('a');
13
14
        $this->assertTrue($links->length == 1);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AutomatedLinkTest>.

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...
15
16
        if($links->length == 1){
17
            $link = $links->item(0);
18
            $this->assertTrue( $link->getAttribute('title') == 'title 1' );
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AutomatedLinkTest>.

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...
19
            $this->assertTrue( $link->getAttribute('target') == '_blank' );
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AutomatedLinkTest>.

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...
20
            $this->assertTrue( $link->getAttribute('rel') == '' );
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<AutomatedLinkTest>.

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...
21
        }
22
    }
23
24
    /**
25
     * Create a dummy object for testing functionality on the SiteTree
26
     *
27
     * @param string|null $content
28
     * @return Page
29
     */
30
    private function createPage($content=null){
31
        $page = Page::create(array( 'Content' => $content ));
32
        $page->write();
33
        return $page;
34
    }
35
36
    /**
37
     * Render the $page supplied into a DOMDocument object
38
     *
39
     * @param Page $page
40
     * @return DOMDocument
41
     */
42
    private function getPageDOM(Page $page){
43
        $controller = Page_Controller::create($page);
44
        $controller->invokeWithExtensions('addAutomatedLinks');
45
        return AutomatedLink::constructDOMDocument($controller->Content);
46
    }
47
}
48
49
50