Completed
Push — master ( 842449...fcd89a )
by Arnold
02:08
created

ArrayExtensionTest::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Jasny\Twig;
4
5
use Jasny\Twig\ArrayExtension;
6
use Jasny\Twig\TestHelper;
7
8
/**
9
 * @covers Jasny\Twig\ArrayExtension
10
 */
11
class ArrayExtensionTest extends \PHPUnit_Framework_TestCase
12
{
13
    use TestHelper;
14
    
15
    protected function getExtension()
16
    {
17
        return new ArrayExtension();
18
    }
19
20
21
    public function testSum()
22
    {
23
        $data = [1, 2, 3, 4];
24
        
25
        $this->assertRender('10', '{{ data|sum }}', compact('data'));
26
    }
27
28
    public function testProduct()
29
    {
30
        $data = [1, 2, 3, 4];
31
        
32
        $this->assertRender('24', '{{ data|product }}', compact('data'));
33
    }
34
35
    public function testValues()
36
    {
37
        $data = (object)['foo' => 1, 'bar' => 2, 'zoo' => 3];
38
        
39
        $this->assertRender('1-2-3', '{{ data|values|join("-") }}', compact('data'));
40
    }
41
42
    
43
    public function testAsArrayWithObject()
44
    {
45
        $data = (object)['foo' => 1, 'bar' => 2, 'zoo' => 3];
46
        
47
        $this->assertRender('foo-bar-zoo', '{{ data|as_array|keys|join("-") }}', compact('data'));
48
    }
49
    
50
    public function testAsArrayWithString()
51
    {
52
        $data = 'foo';
53
        
54
        $this->assertRender('foo', '{{ data|as_array|join("-") }}', compact('data'));
55
    }
56
    
57
    public function testHtmlAttr()
58
    {
59
        $data = ['href' => 'foo.html', 'class' => 'big small', 'checked' => true, 'disabled' => false];
60
        
61
        $this->assertRender(
62
            'href="foo.html" class="big small" checked="checked"',
63
            '{{ data|html_attr|raw }}',
64
            compact('data')
65
        );
66
    }
67
    
68
    
69
    public function filterProvider()
70
    {
71
        return [
72
            ['sum'],
73
            ['product'],
74
            ['values'],
75
            ['as_array'],
76
            ['html_attr']
77
        ];
78
    }
79
    
80
    /**
81
     * @dataProvider filterProvider
82
     * 
83
     * @param string $filter
84
     */
85
    public function testWithNull($filter)
86
    {
87
        $this->assertRender('-', '{{ null|' . $filter . '("//")|default("-") }}');
88
    }    
89
}
90