Skip to content

Commit 687a839

Browse files
committed
Add basic test for Table\GetFieldController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent cfc6461 commit 687a839

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎libraries/classes/Controllers/Table/GetFieldController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use function __;
1717
use function htmlspecialchars;
1818
use function ini_set;
19+
use function mb_strlen;
1920
use function sprintf;
20-
use function strlen;
2121

2222
/**
2323
* Provides download to a given field defined in parameters.
@@ -95,7 +95,7 @@ public function __invoke(): void
9595
Core::downloadHeader(
9696
$table . '-' . $_GET['transform_key'] . '.bin',
9797
Mime::detect($result),
98-
strlen($result)
98+
mb_strlen($result, '8bit')
9999
);
100100
echo $result;
101101
}

‎libraries/classes/Core.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ public static function downloadHeader(
497497
$headers['Content-Length'] = (string) $length;
498498
}
499499

500+
if (defined('TESTSUITE')) {
501+
return;
502+
}
503+
500504
foreach ($headers as $name => $value) {
501505
header(sprintf('%s: %s', $name, $value));
502506
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Table;
6+
7+
use PhpMyAdmin\Controllers\Table\GetFieldController;
8+
use PhpMyAdmin\Core;
9+
use PhpMyAdmin\Template;
10+
use PhpMyAdmin\Tests\AbstractTestCase;
11+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
12+
13+
use function bin2hex;
14+
15+
/**
16+
* @covers \PhpMyAdmin\Controllers\Table\GetFieldController
17+
*/
18+
class GetFieldControllerTest extends AbstractTestCase
19+
{
20+
public function testGetFieldController(): void
21+
{
22+
$GLOBALS['db'] = 'test_db';
23+
$GLOBALS['table'] = 'table_with_blob';
24+
$_GET['transform_key'] = 'file';
25+
$_GET['sql_query'] = 'SELECT * FROM `test_db`.`table_with_blob`';
26+
$_GET['where_clause'] = '`table_with_blob`.`id` = 1';
27+
$_GET['where_clause_sign'] = Core::signSqlQuery('`table_with_blob`.`id` = 1');
28+
29+
$this->dummyDbi->addSelectDb('test_db');
30+
$this->dummyDbi->addResult(
31+
'SHOW COLUMNS FROM `test_db`.`table_with_blob`',
32+
[
33+
['id', 'int(11)', 'NO', 'PRI', null, 'auto_increment'],
34+
['file', 'blob', 'NO', '', null, ''],
35+
],
36+
['Field', 'Type', 'Null', 'Key', 'Default', 'Extra']
37+
);
38+
$this->dummyDbi->addResult(
39+
'SHOW INDEXES FROM `test_db`.`table_with_blob`',
40+
[['table_with_blob', 'PRIMARY', 'id']],
41+
['Table', 'Key_name', 'Column_name']
42+
);
43+
$this->dummyDbi->addResult(
44+
'SELECT `file` FROM `table_with_blob` WHERE `table_with_blob`.`id` = 1;',
45+
[[bin2hex('FILE')]],
46+
['file']
47+
);
48+
49+
(new GetFieldController(new ResponseRenderer(), new Template(), $this->dbi))();
50+
$this->expectOutputString('46494c45');
51+
}
52+
}

0 commit comments

Comments
 (0)