|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright (c) 2026, Manticore Software LTD (https://manticoresearch.com) |
| 5 | +
|
| 6 | + This program is free software; you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License version 2 or any later |
| 8 | + version. You should have received a copy of the GPL license along with this |
| 9 | + program; if you did not, you can find it at http://www.gnu.org/ |
| 10 | +*/ |
| 11 | + |
| 12 | +use Manticoresearch\Buddy\CoreTest\Lib\SqlEscapingTraitTestClass; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class SqlEscapingTraitTest extends TestCase { |
| 16 | + private SqlEscapingTraitTestClass $testClass; |
| 17 | + |
| 18 | + public function testSqlEscapeSpecialCharacters(): void { |
| 19 | + $reflection = new ReflectionClass($this->testClass); |
| 20 | + $method = $reflection->getMethod('sqlEscape'); |
| 21 | + $method->setAccessible(true); |
| 22 | + |
| 23 | + $result = $method->invoke($this->testClass, "line1\nline2\r\"quoted\"\\slash\0\x1a'"); |
| 24 | + $this->assertEquals('line1\\nline2\\r\\"quoted\\"\\\\slash\\0\\Z\\\'', $result); |
| 25 | + } |
| 26 | + |
| 27 | + public function testQuoteWrapsEscapedString(): void { |
| 28 | + $reflection = new ReflectionClass($this->testClass); |
| 29 | + $method = $reflection->getMethod('quote'); |
| 30 | + $method->setAccessible(true); |
| 31 | + |
| 32 | + $result = $method->invoke($this->testClass, "O'Reilly"); |
| 33 | + $this->assertEquals("'O\\'Reilly'", $result); |
| 34 | + } |
| 35 | + |
| 36 | + protected function setUp(): void { |
| 37 | + $this->testClass = new SqlEscapingTraitTestClass(); |
| 38 | + } |
| 39 | +} |
0 commit comments