Skip to content

Commit 1947be4

Browse files
committed
Add basic test for Table\TriggersController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 1b8b9bf commit 1947be4

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table;
6+
7+
use PhpMyAdmin\Controllers\Table\TriggersController;
8+
use PhpMyAdmin\Template;
9+
use PhpMyAdmin\Tests\AbstractTestCase;
10+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
11+
12+
/**
13+
* @covers \PhpMyAdmin\Controllers\Table\TriggersController
14+
*/
15+
class TriggersControllerTest extends AbstractTestCase
16+
{
17+
public function testTriggersController(): void
18+
{
19+
$GLOBALS['server'] = 2;
20+
$GLOBALS['db'] = 'test_db';
21+
$GLOBALS['table'] = 'test_table';
22+
$GLOBALS['text_dir'] = 'ltr';
23+
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
24+
$GLOBALS['cfg']['Server']['DisableIS'] = true;
25+
26+
$this->dummyDbi->addResult('SHOW TABLES FROM `test_db`;', [['test_table']], ['Tables_in_test_db']);
27+
$this->dummyDbi->addSelectDb('test_db');
28+
$this->dummyDbi->addResult('SHOW TABLES LIKE \'test_table\';', [['test_table']]);
29+
$this->dummyDbi->addResult(
30+
'SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`SCHEMA_PRIVILEGES`'
31+
. ' WHERE GRANTEE=\'\'\'pma_test\'\'@\'\'localhost\'\'\' AND PRIVILEGE_TYPE=\'TRIGGER\''
32+
. ' AND \'test_db\' LIKE `TABLE_SCHEMA`',
33+
[['TRIGGER']]
34+
);
35+
36+
$template = new Template();
37+
(new TriggersController(new ResponseRenderer(), $template, $this->dbi))();
38+
39+
$items = [
40+
[
41+
'name' => 'test_trigger',
42+
'table' => 'test_table',
43+
'action_timing' => 'AFTER',
44+
'event_manipulation' => 'INSERT',
45+
'definition' => 'BEGIN END',
46+
'definer' => 'definer@localhost',
47+
'full_trigger_name' => '`test_trigger`',
48+
'drop' => 'DROP TRIGGER IF EXISTS `test_trigger`',
49+
'create' => 'CREATE TRIGGER `test_trigger` AFTER INSERT ON `test_table`' . "\n"
50+
. ' FOR EACH ROW BEGIN END' . "\n" . '//' . "\n",
51+
],
52+
];
53+
$rows = $template->render('database/triggers/row', [
54+
'db' => $GLOBALS['db'],
55+
'table' => $GLOBALS['table'],
56+
'trigger' => $items[0],
57+
'has_drop_privilege' => true,
58+
'has_edit_privilege' => true,
59+
'row_class' => '',
60+
]);
61+
62+
$this->expectOutputString($template->render('database/triggers/list', [
63+
'db' => $GLOBALS['db'],
64+
'table' => $GLOBALS['table'],
65+
'items' => $items,
66+
'rows' => $rows,
67+
'has_privilege' => true,
68+
]));
69+
}
70+
}

0 commit comments

Comments
 (0)