Issues (357)

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
9
    /**
10
     * Loads the glossary testing fixture.
11
     */
12
    public function getDataSet()
13
    {
14
        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...
15
    }
16
17
    /**
18
     * Ensures the database is prepared and the glossary class is included for every test.
19
     */
20
    public function setUp(): void
21
    {
22
        parent::setUp();
23
        
24
        include_once('www/includes/easyparliament/glossary.php');
25
    }
26
27
    /**
28
     * Test that glossarising a single word works as expected.
29
     */
30
    public function testGlossariseNormal()
31
    {
32
        $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...
33
        $glossary = new GLOSSARY($args);
34
		
35
        $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'));
36
    }
37
38
    /**
39
     * Test that glossarising a word within a link works as expected.
40
     */
41
    public function testGlossariseInLink()
42
    {
43
        $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...
44
        $glossary = new GLOSSARY($args);
45
		
46
        $this->assertEquals('<a href="#">constituency</a>', $glossary->glossarise('<a href="#">constituency</a>'));
47
    }
48
49
    /**
50
     * Test that glossarising a word bounded by other characters without spaces works as expected.
51
     */
52
    public function testGlossariseInString()
53
    {
54
        $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...
55
        $glossary = new GLOSSARY($args);
56
		
57
        $this->assertEquals('fooconstituencybar', $glossary->glossarise('fooconstituencybar'));
58
    }
59
60
    /**
61
     * Test that glossarising a word bounded by other characters with spaces works as expected.
62
     */
63
    public function testGlossariseInSpacedString()
64
    {
65
        $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...
66
        $glossary = new GLOSSARY($args);
67
		
68
        $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'));
69
    }
70
71
    /**
72
     * Test that glossarising a single Wikipedia title works as expected.
73
     */
74
    public function testWikipediaLinkNormal()
75
    {
76
        $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...
77
        $glossary = new GLOSSARY($args);
78
		
79
        $this->assertEquals('<a href="https://en.wikipedia.org/wiki/MP">MP</a>', $glossary->glossarise('MP'));
80
    }
81
82
    /**
83
     * Test that glossarising a Wikipedia title within a link works as expected.
84
     */
85
    public function testWikipediaLinkInLink()
86
    {
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('<a href="#">MP</a>', $glossary->glossarise('<a href="#">MP</a>'));
91
    }
92
93
    /**
94
     * Test that glossarising a Wikipedia title bounded by other characters without spaces works as expected.
95
     */
96
    public function testWikipediaLinkInString()
97
    {
98
        $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...
99
        $glossary = new GLOSSARY($args);
100
		
101
        $this->assertEquals('fooMPbar', $glossary->glossarise('fooMPbar'));
102
    }
103
104
    /**
105
     * Test that glossarising a Wikipedia title bounded by other characters with spaces works as expected.
106
     */
107
    public function testWikipediaLinkInSpacedString()
108
    {
109
        $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...
110
        $glossary = new GLOSSARY($args);
111
		
112
        $this->assertEquals('foo <a href="https://en.wikipedia.org/wiki/MP">MP</a> bar', $glossary->glossarise('foo MP bar'));
113
    }
114
}
115