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

syntax_exclude_plugin_backlinks_test   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 44.68 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 0
dl 42
loc 94
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 9 9 1
A setUp() 22 22 3
A tearDown() 11 11 2
B testExclude() 0 40 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
 * 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_exclude_plugin_backlinks_test extends DokuWikiTest {
25
26
    protected $pluginsEnabled = array('backlinks');
27
28
    /**
29
     * copy data.
30
     */
31 View Code Duplication
    public static function setUpBeforeClass(){
0 ignored issues
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() {
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...
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
59
        if($conf['allowdebug']) {
60
            touch(DOKU_TMP_DATA.'cache/debug.log');
61
        }
62
    }
63
64 View Code Duplication
    public function tearDown() {
0 ignored issues
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...
65
        parent::tearDown();
66
67
        global $conf;
68
        // try to get the debug log after running the test, print and clear
69
        if($conf['allowdebug']) {
70
            print "\n";
71
            readfile(DOKU_TMP_DATA.'cache/debug.log');
72
            unlink(DOKU_TMP_DATA.'cache/debug.log');
73
        }
74
    }
75
76
77
    public function testExclude() {
78
        $request = new TestRequest();
79
        $response = $request->get(array('id'=>'backlinks_exclude_syntax'), '/doku.php');
80
81
82
83
        $this->assertTrue(
84
            strpos($response->getContent(), 'Backlinks to what Bob Ross says (excluding exclude namespace)') !== false,
85
            '"Backlinks to what Bob Ross says (excluding exclude namespace)" was not in the output'
86
        );
87
88
        $this->assertTrue(
89
            strpos($response->getContent(), 'An excluded link to Bob Ross') == false,
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($response->getCon...uded link to Bob Ross') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
90
            '"An excluded link to Bob Ross" should not be in the output'
91
        );
92
93
        $doc = phpQuery::newDocument($response->getContent());
94
        // look for id="plugin__backlinks"
95
        $this->assertEquals(
96
                            1,
97
                            pq('#plugin__backlinks', $doc)->length,
98
                            'There should be one backlinks element'
99
                           );
100
101
        $wikilinks = pq('#plugin__backlinks ul li', $doc);
102
        dbglog($wikilinks->text(), 'found backlinks');
103
        $this->assertEquals(
104
                            3,
105
                            $wikilinks->contents()->length,
106
                            'There should be 3 backlinks'
107
                           );
108
109
        $lastlink = pq('a:last',$wikilinks);
110
        dbglog($lastlink->text(),"last backlink");
111
        $this->assertEquals(
112
                            'A link to Bob Ross',
113
                            $lastlink->text(),
114
                            'The last backlink should be "A link to Bob Ross"'
115
                           );
116
    }
117
}
118