Translated using Weblate (Czech)
[phpmyadmin.git] / test / classes / LinterTest.php
blob51fea6884a3b200bd81c3af7f72cd558af48c8f2
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tests for Linter.php.
6 * @package PhpMyAdmin-test
7 */
8 declare(strict_types=1);
10 namespace PhpMyAdmin\Tests;
12 use PhpMyAdmin\Linter;
13 use PhpMyAdmin\Tests\PmaTestCase;
15 /**
16 * Tests for PhpMyAdmin\Linter
18 * @package PhpMyAdmin-test
20 class LinterTest extends PmaTestCase
22 /**
23 * Test for Linter::getLines
25 * @return void
27 public function testGetLines()
29 $this->assertEquals([0], Linter::getLines(''));
30 $this->assertEquals([0, 2], Linter::getLines("a\nb"));
31 $this->assertEquals([0, 4, 7], Linter::getLines("abc\nde\n"));
34 /**
35 * Test for Linter::findLineNumberAndColumn
37 * @return void
39 public function testFindLineNumberAndColumn()
41 // Let the analyzed string be:
42 // ^abc$
43 // ^de$
44 // ^$
46 // Where `^` is the beginning of the line and `$` the end of the line.
48 // Positions of each character (by line):
49 // ( a, 0), ( b, 1), ( c, 2), (\n, 3),
50 // ( d, 4), ( e, 5), (\n, 6),
51 // (\n, 7).
52 $this->assertEquals(
57 Linter::findLineNumberAndColumn([0, 4, 7], 4)
59 $this->assertEquals(
64 Linter::findLineNumberAndColumn([0, 4, 7], 5)
66 $this->assertEquals(
71 Linter::findLineNumberAndColumn([0, 4, 7], 6)
73 $this->assertEquals(
78 Linter::findLineNumberAndColumn([0, 4, 7], 7)
82 /**
83 * Test for Linter::lint
85 * @dataProvider lintProvider
87 * @param array $expected The expected result.
88 * @param string $query The query to be analyzed.
90 * @return void
92 public function testLint($expected, $query): void
94 $this->assertEquals($expected, Linter::lint($query));
97 /**
98 * Provides data for `testLint`.
100 * @return array
102 public static function lintProvider()
104 return [
111 'SELECT * FROM tbl',
116 'message' => 'Unrecognized data type. (near ' .
117 '<code>IN</code>)',
118 'fromLine' => 0,
119 'fromColumn' => 22,
120 'toLine' => 0,
121 'toColumn' => 24,
122 'severity' => 'error',
125 'message' => 'A closing bracket was expected. (near ' .
126 '<code>IN</code>)',
127 'fromLine' => 0,
128 'fromColumn' => 22,
129 'toLine' => 0,
130 'toColumn' => 24,
131 'severity' => 'error',
134 'CREATE TABLE tbl ( id IN',
139 'message' => 'Linting is disabled for this query because ' .
140 'it exceeds the maximum length.',
141 'fromLine' => 0,
142 'fromColumn' => 0,
143 'toLine' => 0,
144 'toColumn' => 0,
145 'severity' => 'warning',
148 str_repeat(";", 10001),