summaryrefslogtreecommitdiffstats
path: root/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php
blob: 5481ce9f1fa6eabd6a004d0ab1b589c1e1427afd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

/* Icinga Web 2 X.509 Module | (c) 2023 Icinga GmbH | GPLv2 */

namespace Tests\Icinga\Modules\X509\Model\Behavior;

use Icinga\Module\X509\Model\Behavior\ExpressionInjector;
use ipl\Orm\Query;
use ipl\Sql\Connection;
use ipl\Stdlib\Filter\Equal;
use PHPUnit\Framework\TestCase;
use Tests\Icinga\Module\X509\Lib\TestModel;

class ExpressionInjectorTest extends TestCase
{
    public function testRewriteConditionReplacesExpressionColumnByItsExpression()
    {
        $cond = new Equal('duration', 'FOOO');
        $cond->metaData()->set('columnName', 'duration');
        $this->assertSame('duration', $cond->getColumn());
        $this->assertSame('FOOO', $cond->getValue());

        $this->behavior()->rewriteCondition($cond);

        $this->assertSame('FOOO', $cond->getValue());
        $this->assertSame(TestModel::EXPRESSION, $cond->getColumn());
    }

    protected function behavior(): ExpressionInjector
    {
        return (new ExpressionInjector('duration'))
            ->setQuery(
                (new Query())
                    ->setDb(new Connection(['db' => 'mysql']))
                    ->setModel(new TestModel())
            );
    }
}