summaryrefslogtreecommitdiffstats
path: root/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php')
-rw-r--r--test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php b/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php
new file mode 100644
index 0000000..5481ce9
--- /dev/null
+++ b/test/php/library/X509/Model/Behavior/ExpressionInjectorTest.php
@@ -0,0 +1,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())
+ );
+ }
+}