Completed
Push — 1.x ( e997bd )
by Sullivan
19:38
created

BooleanFilterTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 68
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testFilterNullData() 0 6 1
A testFilterEmptyArrayData() 0 6 1
A testFilterEmptyArrayDataSpecifiedType() 0 6 1
A testFilterEmptyArrayDataWithMeaninglessValue() 0 8 1
A getFilters() 0 7 1
A testFilterSwitch() 0 18 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Filter;
13
14
use Sonata\CoreBundle\Form\Type\BooleanType;
15
use Sonata\DoctrinePHPCRAdminBundle\Filter\BooleanFilter;
16
17
class BooleanFilterTest extends BaseTestCase
18
{
19
    public function setUp()
20
    {
21
        parent::setUp();
22
        $this->filter = new BooleanFilter();
23
    }
24
25
    public function testFilterNullData()
26
    {
27
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', null);
28
        $this->assertNull($res);
29
        $this->assertFalse($this->filter->isActive());
30
    }
31
32
    public function testFilterEmptyArrayData()
33
    {
34
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', array());
35
        $this->assertNull($res);
36
        $this->assertFalse($this->filter->isActive());
37
    }
38
39
    public function testFilterEmptyArrayDataSpecifiedType()
40
    {
41
        $res = $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES));
42
        $this->assertNull($res);
43
        $this->assertFalse($this->filter->isActive());
44
    }
45
46
    public function testFilterEmptyArrayDataWithMeaninglessValue()
47
    {
48
        $this->proxyQuery->expects($this->never())
49
            ->method('andWhere');
50
51
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES, 'value' => 'someValue'));
52
        $this->assertFalse($this->filter->isActive());
53
    }
54
55
    public function getFilters()
56
    {
57
        return array(
58
            array('eq', BooleanType::TYPE_YES, 1),
59
            array('eq', BooleanType::TYPE_NO, 0),
60
        );
61
    }
62
63
    /**
64
     * @dataProvider getFilters
65
     */
66
    public function testFilterSwitch($operatorMethod, $value, $expectedValue)
67
    {
68
        $this->filter->filter(
69
            $this->proxyQuery,
70
            null,
71
            'somefield',
72
            array('type' => '', 'value' => $value)
73
        );
74
75
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
76
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
77
78
        $this->assertEquals('a', $opDynamic->getAlias());
79
        $this->assertEquals('somefield', $opDynamic->getField());
80
        $this->assertEquals($expectedValue, $opStatic->getValue());
81
82
        $this->assertTrue($this->filter->isActive());
83
    }
84
}
85