Completed
Push — master ( 6b2632...1706e7 )
by
unknown
07:57 queued 10s
created

tests/Unit/Filter/NodeNameFilterTest.php (1 issue)

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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Filter;
15
16
use Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter;
17
use Sonata\DoctrinePHPCRAdminBundle\Form\Type\Filter\ChoiceType;
18
19
class NodeNameFilterTest extends BaseTestCase
20
{
21
    public function setUp(): void
22
    {
23
        parent::setUp();
24
        $this->filter = new NodeNameFilter();
25
    }
26
27
    public function getChoiceTypeForEmptyTests()
28
    {
29
        return ChoiceType::TYPE_EQUAL;
30
    }
31
32
    public function testFilterNullData(): void
33
    {
34
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', null);
35
        $this->assertNull($res);
36
        $this->assertFalse($this->filter->isActive());
37
    }
38
39
    public function testFilterEmptyArrayData(): void
40
    {
41
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', []);
42
        $this->assertNull($res);
43
        $this->assertFalse($this->filter->isActive());
44
    }
45
46
    public function testFilterEmptyArrayDataSpecifiedType(): void
47
    {
48
        $res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL]);
49
        $this->assertNull($res);
50
        $this->assertFalse($this->filter->isActive());
51
    }
52
53
    public function testFilterEmptyArrayDataWithMeaninglessValue(): void
54
    {
55
        $this->filter->filter($this->proxyQuery, 'a', 'somefield', ['type' => ChoiceType::TYPE_EQUAL, 'value' => ' ']);
56
        $this->assertFalse($this->filter->isActive());
57
    }
58
59
    public function getFilters()
60
    {
61
        return [
62
            ['eqNodeName', ChoiceType::TYPE_EQUAL],
63
            ['likeNodeName', ChoiceType::TYPE_NOT_CONTAINS, '%somevalue%'],
64
            ['likeNodeName', ChoiceType::TYPE_CONTAINS, '%somevalue%'],
65
            ['likeNodeName', ChoiceType::TYPE_CONTAINS_WORDS, '%somevalue%'],
66
        ];
67
    }
68
69
    /**
70
     * @dataProvider getFilters
71
     */
72
    public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue'): void
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...
73
    {
74
        $this->proxyQuery->expects($this->exactly(1))
75
            ->method('getQueryBuilder')
76
            ->willReturn($this->qb);
77
78
        $this->filter->filter(
79
            $this->proxyQuery,
80
            'a',
81
            'somefield',
82
            ['type' => $choiceType, 'value' => 'somevalue']
83
        );
84
85
        $localName = $this->qbTester->getNode('where.constraint.operand_dynamic');
86
        $literal = $this->qbTester->getNode('where.constraint.operand_static');
87
88
        $this->assertSame('a', $localName->getAlias());
89
        $this->assertSame($expectedValue, $literal->getValue());
90
91
        $this->assertTrue($this->filter->isActive());
92
    }
93
}
94