Completed
Push — master ( d3bd06...5d3395 )
by Mark
8s
created

syntax_plugin_backlinks_test::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
/*
3
 * Copyright (c) 2016 Mark C. Prins <[email protected]>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
18
/**
19
 * Syntax tests for the backlinks plugin.
20
 *
21
 * @group plugin_backlinks
22
 * @group plugins
23
 */
24
class syntax_plugin_backlinks_test extends DokuWikiTest {
25
26
    protected $pluginsEnabled = array('backlinks');
27
28
    /**
29
     * copy data and add pages to the index.
30
     */
31 View Code Duplication
    public static function setUpBeforeClass(){
1 ignored issue
show
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...
32
        parent::setUpBeforeClass();
33
        global $conf;
34
        $conf['allowdebug'] = 1;
35
36
        TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/');
37
38
        dbglog("\nset up class syntax_plugin_backlinks_test");
39
    }
40
41 View Code Duplication
    function setUp() {
1 ignored issue
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...
42
        parent::setUp();
43
44
        global $conf;
45
        $conf['allowdebug'] = 1;
46
        $conf['cachetime'] = -1;
47
48
        $data = array();
49
        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
50
51
        //dbglog($data, "pages for indexing");
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
53
        $verbose = false;
54
        $force = false;
55
        foreach($data as $val) {
56
            idx_addPage($val['id'], $verbose, $force);
57
        }
58
        //idx_addPage('bob_ross_says', $verbose, $force);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
        //idx_addPage('link', $verbose, $force);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
        //idx_addPage('backlinks_syntax', $verbose, $force);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
        if($conf['allowdebug']) {
62
            touch(DOKU_TMP_DATA.'cache/debug.log');
63
        }
64
    }
65
66 View Code Duplication
    public function tearDown() {
1 ignored issue
show
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...
67
        parent::tearDown();
68
69
        global $conf;
70
        // try to get the debug log after running the test, print and clear
71
        if($conf['allowdebug']) {
72
            print "\n";
73
            readfile(DOKU_TMP_DATA.'cache/debug.log');
74
            unlink(DOKU_TMP_DATA.'cache/debug.log');
75
        }
76
    }
77
78
    public function testIndex() {
79
        $query = array('ross');
80
        $this->assertEquals(
81
                 array('ross' => array(
82
                    'link' => '3',
83
                    'bob_ross_says' => '1',
84
                    'backlinks_syntax' => '2',
85
                    'backlinks_include_syntax' => '2',
86
                    'backlinks_exclude_syntax' => '2',
87
                    'backlink_test_pages' => '8',
88
                    'include:link' => '3',
89
                    'exclude:link' => '3'
90
                    )),
91
                 idx_lookup($query)
92
        );
93
    }
94
95 View Code Duplication
    public function testLinksPage() {
1 ignored issue
show
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...
96
        $request = new TestRequest();
97
        $response = $request->get(array('id'=>'link'), '/doku.php');
98
99
        $this->assertTrue(
100
            strpos($response->getContent(), 'A link to Bob Ross') !== false,
101
            '"A link to Bob Ross" was not in the output'
102
        );
103
     }
104
105 View Code Duplication
    public function testStoryPage() {
1 ignored issue
show
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...
106
        $request = new TestRequest();
107
        $response = $request->get(array('id'=>'bob_ross_says'), '/doku.php');
108
109
        $this->assertTrue(
110
            strpos($response->getContent(), 'Bob Ross says') !== false,
111
            '"Bob Ross says" was not in the output'
112
        );
113
    }
114
115 View Code Duplication
    public function testBacklinks() {
1 ignored issue
show
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...
116
        $request = new TestRequest();
117
        $response = $request->get(array('id'=>'backlinks_syntax'), '/doku.php');
118
119
        $this->assertTrue(
120
            strpos($response->getContent(), 'Backlinks to what Bob Ross says') !== false,
121
            '"Backlinks to what Bob Ross says" was not in the output'
122
        );
123
124
        $doc = phpQuery::newDocument($response->getContent());
125
        // look for id="plugin__backlinks"
126
        $this->assertEquals(
127
                            1,
128
                            pq('#plugin__backlinks', $doc)->length,
129
                            'There should be one backlinks element'
130
                           );
131
132
        $wikilinks = pq('#plugin__backlinks ul li', $doc);
133
        dbglog($wikilinks->text(), 'found backlinks');
134
        $this->assertEquals(
135
                            4,
136
                            $wikilinks->contents()->length,
137
                            'There should be 4 backlinks'
138
                           );
139
140
        $lastlink = pq('a:last',$wikilinks);
141
        dbglog($lastlink->text(),"last backlink");
142
        $this->assertEquals(
143
                            $lastlink->text(),
144
                            'A link to Bob Ross',
145
                            'The last backlink should be a link to Bob Ross'
146
                           );
147
    }
148
}
149