Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/classes/Controllers/LintControllerTest.php')
-rw-r--r--test/classes/Controllers/LintControllerTest.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/classes/Controllers/LintControllerTest.php b/test/classes/Controllers/LintControllerTest.php
new file mode 100644
index 0000000000..d125d9b1ae
--- /dev/null
+++ b/test/classes/Controllers/LintControllerTest.php
@@ -0,0 +1,99 @@
+<?php
+
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Tests\Controllers;
+
+use PhpMyAdmin\Controllers\LintController;
+use PhpMyAdmin\Http\ServerRequest;
+use PhpMyAdmin\Template;
+use PhpMyAdmin\Tests\AbstractTestCase;
+use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
+
+use function json_encode;
+
+/**
+ * @covers \PhpMyAdmin\Controllers\LintController
+ */
+class LintControllerTest extends AbstractTestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $GLOBALS['dbi'] = $this->createDatabaseInterface();
+ }
+
+ public function testWithoutParams(): void
+ {
+ $_POST = [];
+
+ $this->getLintController()($this->createStub(ServerRequest::class));
+
+ $output = $this->getActualOutputForAssertion();
+ $this->assertJson($output);
+ $this->assertJsonStringEqualsJsonString('[]', $output);
+ }
+
+ public function testWithoutSqlErrors(): void
+ {
+ $_POST['sql_query'] = 'SELECT * FROM `actor` WHERE `actor_id` = 1;';
+
+ $this->getLintController()($this->createStub(ServerRequest::class));
+
+ $output = $this->getActualOutputForAssertion();
+ $this->assertJson($output);
+ $this->assertJsonStringEqualsJsonString('[]', $output);
+ }
+
+ public function testWithSqlErrors(): void
+ {
+ $_POST['sql_query'] = 'SELECT * FROM `actor` WHEREE `actor_id` = 1;';
+
+ $expectedJson = json_encode([
+ [
+ 'message' => 'An alias was previously found. (near <code>`actor_id`</code>)',
+ 'fromLine' => 0,
+ 'fromColumn' => 29,
+ 'toLine' => 0,
+ 'toColumn' => 39,
+ 'severity' => 'error',
+ ],
+ [
+ 'message' => 'Unexpected token. (near <code>`actor_id`</code>)',
+ 'fromLine' => 0,
+ 'fromColumn' => 29,
+ 'toLine' => 0,
+ 'toColumn' => 39,
+ 'severity' => 'error',
+ ],
+ [
+ 'message' => 'Unexpected token. (near <code>=</code>)',
+ 'fromLine' => 0,
+ 'fromColumn' => 40,
+ 'toLine' => 0,
+ 'toColumn' => 41,
+ 'severity' => 'error',
+ ],
+ [
+ 'message' => 'Unexpected token. (near <code>1</code>)',
+ 'fromLine' => 0,
+ 'fromColumn' => 42,
+ 'toLine' => 0,
+ 'toColumn' => 43,
+ 'severity' => 'error',
+ ],
+ ]);
+ $this->assertNotFalse($expectedJson);
+
+ $this->getLintController()($this->createStub(ServerRequest::class));
+
+ $output = $this->getActualOutputForAssertion();
+ $this->assertJson($output);
+ $this->assertJsonStringEqualsJsonString($expectedJson, $output);
+ }
+
+ private function getLintController(): LintController
+ {
+ return new LintController(new ResponseRenderer(), new Template());
+ }
+}