Completed
Push — master ( 4c26f1...ff6f36 )
by Maximilian
14s
created

tests/Filter/BooleanFilterTest.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sonata Project 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
    /**
20
     * @var BooleanFilter
21
     */
22
    private $filter;
23
24
    public function setUp()
25
    {
26
        parent::setUp();
27
        $this->filter = new BooleanFilter();
28
    }
29
30
    public function testFilterNullData()
31
    {
32
        $this->filter->filter($this->proxyQuery, null, 'somefield', null);
33
        $this->assertFalse($this->filter->isActive());
34
    }
35
36
    public function testFilterEmptyArrayData()
37
    {
38
        $this->filter->filter($this->proxyQuery, null, 'somefield', array());
39
        $this->assertFalse($this->filter->isActive());
40
    }
41
42
    public function testFilterEmptyArrayDataSpecifiedType()
43
    {
44
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES));
45
        $this->assertFalse($this->filter->isActive());
46
    }
47
48
    public function testFilterEmptyArrayDataWithMeaninglessValue()
49
    {
50
        $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => BooleanType::TYPE_YES, 'value' => 'someValue'));
51
        $this->assertFalse($this->filter->isActive());
52
    }
53
54
    public function getFilters()
55
    {
56
        return array(
57
            array('eq', BooleanType::TYPE_YES, 1),
58
            array('eq', BooleanType::TYPE_NO, 0),
59
        );
60
    }
61
62
    /**
63
     * @dataProvider getFilters
64
     */
65
    public function testFilterSwitch($operatorMethod, $value, $expectedValue)
0 ignored issues
show
The parameter $operatorMethod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        $this->filter->filter(
68
            $this->proxyQuery,
69
            null,
70
            'somefield',
71
            array('type' => '', 'value' => $value)
72
        );
73
74
        $opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
75
        $opStatic = $this->qbTester->getNode('where.constraint.operand_static');
76
77
        $this->assertEquals('a', $opDynamic->getAlias());
78
        $this->assertEquals('somefield', $opDynamic->getField());
79
        $this->assertEquals($expectedValue, $opStatic->getValue());
80
81
        $this->assertTrue($this->filter->isActive());
82
    }
83
}
84