GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7bdf98...52bff1 )
by Askupa
02:17
created

CompilerTest::testFilterApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 12
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 17
rs 9.4285
1
<?php
2
use PHPUnit\Framework\TestCase;
3
4
/**
5
 * To run the tests, use the following command:
6
 * $ phpunit --bootstrap compiler.php tests.php
7
 */
8
class CompilerTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * DynamicCSSCompiler::strtoval test
12
     */
13
    public function testStrToVal()
14
    {
15
        // Make protected functions accessible through a reflection class
16
        $class = new ReflectionClass('DynamicCSSCompiler');
17
        $method = $class->getMethod('strtoval');
18
        $method->setAccessible(true);
19
        $dcss = DynamicCSSCompiler::get_instance();
20
        
21
        // Assert
22
        $str = "'value'";
23
        $method->invokeArgs($dcss, array(&$str));
24
        $this->assertEquals($str, 'value');
25
        
26
        $str = "false";
27
        $method->invokeArgs($dcss, array(&$str));
28
        $this->assertEquals($str, false);
29
        
30
        $str = "true";
31
        $method->invokeArgs($dcss, array(&$str));
32
        $this->assertEquals($str, true);
33
        
34
        $str = "4";
35
        $method->invokeArgs($dcss, array(&$str));
36
        $this->assertEquals($str, 4);
37
        
38
        $str = "4.321";
39
        $method->invokeArgs($dcss, array(&$str));
40
        $this->assertEquals($str, 4.321);
41
    }
42
    
43
    /**
44
     * DynamicCSSCompiler::apply_filters test
45
     */
46
    public function testFilterApplication()
47
    {
48
        // Make protected functions accessible through a reflection class
49
        $class = new ReflectionClass('DynamicCSSCompiler');
50
        $method = $class->getMethod('apply_filters');
51
        $method->setAccessible(true);
52
        $dcss = DynamicCSSCompiler::get_instance();
53
        
54
        // Assert
55
        $this->assertEquals($method->invokeArgs($dcss, array('simple_filter', 'foo', array('simple_filter' => 'simple_filter_callback'))), 'foobar');
56
        $this->assertEquals($method->invokeArgs($dcss, array('simple_filter|simple_filter', 'foo', array('simple_filter' => 'simple_filter_callback'))), 'foobarbar');
57
        $this->assertEquals($method->invokeArgs($dcss, array('complex_filter(\'bar\')', 'foo', array('complex_filter' => 'complex_filter_callback'))), 'foobar');
58
        $this->assertEquals($method->invokeArgs($dcss, array('complex_filter(\'bar\',\'foo\')', 'foo', array('complex_filter' => 'complex_filter_callback'))), 'foobarfoo');
59
        $this->assertEquals($method->invokeArgs($dcss, array('complex_filter(\'bar\')|complex_filter(\'foo\')', 'foo', array('complex_filter' => 'complex_filter_callback'))), 'foobarfoo');
60
        $this->assertEquals($method->invokeArgs($dcss, array('add_filter(5,5)', '5 + 5 = ', array('add_filter' => 'add_filter_callback'))), '5 + 5 = 10');
61
        $this->assertEquals($method->invokeArgs($dcss, array('add_filter(5.5,5.5)', '5.5 + 5.5 = ', array('add_filter' => 'add_filter_callback'))), '5.5 + 5.5 = 11');
62
    }
63
    
64
    /**
65
     * DynamicCSSCompiler::compile_css test
66
     */
67
    public function testCompilation()
68
    {
69
        // Make protected functions accessible through a reflection class
70
        $class = new ReflectionClass('DynamicCSSCompiler');
71
        $method = $class->getMethod('compile_css');
72
        $method->setAccessible(true);
73
        $dcss = DynamicCSSCompiler::get_instance();
74
        
75
        // Assert
76
        $this->assertEquals($method->invokeArgs($dcss, array('$var1', 'callback', array())), 'value1');
77
        $this->assertEquals($method->invokeArgs($dcss, array('$var2', 'callback', array())), 'value2');
78
        $this->assertEquals($method->invokeArgs($dcss, array('$var3[\'index1\']', 'callback', array())), 'value3');
79
        $this->assertEquals($method->invokeArgs($dcss, array('$var3[\'index2\'][\'subindex1\']', 'callback', array())), 'value4');
80
        $this->assertEquals($method->invokeArgs($dcss, array('$var3[index2][subindex1]', 'callback', array())), 'value4');
81
        $this->assertEquals($method->invokeArgs($dcss, array('$var3[index2][subindex1]', 'callback', array())), 'value4');
82
        $this->assertEquals($method->invokeArgs($dcss, array('$var4|simpleFilter', 'callback', array('simpleFilter' => 'simple_filter_callback'))), 'valuebar');
83
        $this->assertEquals($method->invokeArgs($dcss, array('$var4|simpleFilter|simpleFilter', 'callback', array('simpleFilter' => 'simple_filter_callback'))), 'valuebarbar');
84
        $this->assertEquals($method->invokeArgs($dcss, array('$var4|complexFilter(6)', 'callback', array('complexFilter' => 'complex_filter_callback'))), 'value6');
85
        $this->assertEquals($method->invokeArgs($dcss, array('$var5|complexFilter(e)|complexFilter(7)', 'callback', array('complexFilter' => 'complex_filter_callback'))), 'value7');
86
        $this->assertEquals($method->invokeArgs($dcss, array('$var3[index1]|simpleFilter', 'callback', array('simpleFilter' => 'simple_filter_callback'))), 'value3bar');
87
    }
88
}
89
90
/**
91
 * Value retrieval function
92
 */
93
function callback( $varname, $subscripts )
94
{
95
    $values = array(
96
        'var1'  => 'value1',
97
        'var2'  => 'value2',
98
        'var3'  => array(
99
            'index1' => 'value3',
100
            'index2' => array(
101
                'subindex1' => 'value4'
102
            )
103
        ),
104
        'var4'  => 'value',
105
        'var5'  => 'valu'
106
    );
107
    
108
    $val = $values[$varname];
109
    if( null !== $subscripts )
110
    {
111
        foreach( $subscripts as $subscript )
112
        {
113
            $val = $val[$subscript];
114
        }
115
    }
116
    
117
    return $val;
118
}
119
120
/**
121
 * Simple string concat filter
122
 */
123
function simple_filter_callback( $foo )
124
{
125
    return $foo.'bar';
126
}
127
128
/**
129
 * String concat filter with parameters
130
 */
131
function complex_filter_callback( $value, $arg1 = '', $arg2 = '')
132
{
133
    return $value.$arg1.$arg2;
134
}
135
136
/**
137
 * Number adding filter
138
 */
139
function add_filter_callback( $value, $a, $b )
140
{
141
    return $value.($a+$b);
142
}