Issues (404)

tests/GlossaryTest.php (9 issues)

1
<?php
2
3
/**
4
 * Provides test methods for glossary functionality.
5
 */
6
class GlossaryTest extends TWFY_Database_TestCase {
7
    /**
8
     * Loads the glossary testing fixture.
9
     */
10
    public function getDataSet() {
11
        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/glossary.xml');
0 ignored issues
show
Are you sure the usage of $this->createMySQLXMLDat...fixtures/glossary.xml') targeting TWFY_Database_TestCase::createMySQLXMLDataSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
12
    }
13
14
    /**
15
     * Ensures the database is prepared and the glossary class is included for every test.
16
     */
17
    public function setUp(): void {
18
        parent::setUp();
19
20
        include_once('www/includes/easyparliament/glossary.php');
21
    }
22
23
    /**
24
     * Test that glossarising a single word works as expected.
25
     */
26
    public function testGlossariseNormal() {
27
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
28
        $glossary = new GLOSSARY($args);
29
30
        $this->assertEquals('<a href="/glossary/?gl=1" title="In a general election, each Constituency chooses an MP to represent them...." class="glossary">constituency</a>', $glossary->glossarise('constituency'));
31
    }
32
33
    /**
34
     * Test that glossarising a word within a link works as expected.
35
     */
36
    public function testGlossariseInLink() {
37
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
38
        $glossary = new GLOSSARY($args);
39
40
        $this->assertEquals('<a href="#">constituency</a>', $glossary->glossarise('<a href="#">constituency</a>'));
41
    }
42
43
    /**
44
     * Test that glossarising a word bounded by other characters without spaces works as expected.
45
     */
46
    public function testGlossariseInString() {
47
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
48
        $glossary = new GLOSSARY($args);
49
50
        $this->assertEquals('fooconstituencybar', $glossary->glossarise('fooconstituencybar'));
51
    }
52
53
    /**
54
     * Test that glossarising a word bounded by other characters with spaces works as expected.
55
     */
56
    public function testGlossariseInSpacedString() {
57
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
58
        $glossary = new GLOSSARY($args);
59
60
        $this->assertEquals('foo <a href="/glossary/?gl=1" title="In a general election, each Constituency chooses an MP to represent them...." class="glossary">constituency</a> bar', $glossary->glossarise('foo constituency bar'));
61
    }
62
63
    /**
64
     * Test that glossarising a single Wikipedia title works as expected.
65
     */
66
    public function testWikipediaLinkNormal() {
67
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
68
        $glossary = new GLOSSARY($args);
69
70
        $this->assertEquals('<a href="https://en.wikipedia.org/wiki/MP">MP</a>', $glossary->glossarise('MP'));
71
    }
72
73
    /**
74
     * Test that glossarising a Wikipedia title within a link works as expected.
75
     */
76
    public function testWikipediaLinkInLink() {
77
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
78
        $glossary = new GLOSSARY($args);
79
80
        $this->assertEquals('<a href="#">MP</a>', $glossary->glossarise('<a href="#">MP</a>'));
81
    }
82
83
    /**
84
     * Test that glossarising a Wikipedia title bounded by other characters without spaces works as expected.
85
     */
86
    public function testWikipediaLinkInString() {
87
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
88
        $glossary = new GLOSSARY($args);
89
90
        $this->assertEquals('fooMPbar', $glossary->glossarise('fooMPbar'));
91
    }
92
93
    /**
94
     * Test that glossarising a Wikipedia title bounded by other characters with spaces works as expected.
95
     */
96
    public function testWikipediaLinkInSpacedString() {
97
        $args['sort'] = "regexp_replace";
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
98
        $glossary = new GLOSSARY($args);
99
100
        $this->assertEquals('foo <a href="https://en.wikipedia.org/wiki/MP">MP</a> bar', $glossary->glossarise('foo MP bar'));
101
    }
102
}
103