1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for PhpMyAdmin\CreateAddField
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\CreateAddField;
use PHPUnit\Framework\TestCase;
/**
* This class is for testing PhpMyAdmin\CreateAddField methods
*
* @package PhpMyAdmin-test
*/
class CreateAddFieldTest extends TestCase
{
/**
* @var CreateAddField
*/
private $createAddField;
/**
* Set up for test cases
*
* @return void
*/
protected function setUp(): void
{
$this->createAddField = new CreateAddField($GLOBALS['dbi']);
}
/**
* Test for getPartitionsDefinition
*
* @param string $expected Expected result
* @param array $request $_REQUEST array
*
* @dataProvider providerGetPartitionsDefinition
*
* @return void
*/
public function testGetPartitionsDefinition($expected, $request): void
{
$_POST = $request;
$actual = $this->createAddField->getPartitionsDefinition();
$this->assertEquals($expected, $actual);
}
/**
* Data provider for testGetPartitionsDefinition
*
* @return array
*/
public function providerGetPartitionsDefinition()
{
return [
[
'',
[],
],
[
' PARTITION BY HASH (EXPR()) PARTITIONS 2',
[
'partition_by' => 'HASH',
'partition_expr' => 'EXPR()',
'partition_count' => '2',
],
],
];
}
/**
* Test for getTableCreationQuery
*
* @param string $expected Expected result
* @param string $db Database name
* @param string $table Table name
* @param array $request $_REQUEST array
*
* @dataProvider providerGetTableCreationQuery
*
* @return void
*/
public function testGetTableCreationQuery($expected, $db, $table, $request): void
{
$_POST = $request;
$actual = $this->createAddField->getTableCreationQuery($db, $table);
$this->assertEquals($expected, $actual);
}
/**
* Data provider for testGetTableCreationQuery
*
* @return array
*/
public function providerGetTableCreationQuery()
{
return [
[
'CREATE TABLE `db`.`table` ();',
'db',
'table',
[
'field_name' => [],
'primary_indexes' => '{}',
'indexes' => '{}',
'unique_indexes' => '{}',
'fulltext_indexes' => '{}',
'spatial_indexes' => '{}',
],
],
[
'CREATE TABLE `db`.`table` () ENGINE = Inno\\\'DB CHARSET=armscii8 COMMENT = \'my \\\'table\';',
'db',
'table',
[
'field_name' => [],
'primary_indexes' => '{}',
'indexes' => '{}',
'unique_indexes' => '{}',
'fulltext_indexes' => '{}',
'spatial_indexes' => '{}',
'tbl_storage_engine' => 'Inno\'DB',
'tbl_collation' => 'armscii8',
'connection' => 'aaaa',
'comment' => 'my \'table',
],
],
];
}
/**
* Test for getNumberOfFieldsFromRequest
*
* @param string $expected Expected result
* @param array $request $_REQUEST array
*
* @dataProvider providerGetNumberOfFieldsFromRequest
*
* @return void
*/
public function testGetNumberOfFieldsFromRequest($expected, $request): void
{
$_POST = $request;
$actual = $this->createAddField->getNumberOfFieldsFromRequest();
$this->assertEquals($expected, $actual);
}
/**
* Data provider for testGetNumberOfFieldsFromRequest
*
* @return array
*/
public function providerGetNumberOfFieldsFromRequest()
{
return [
[
4,
[],
],
];
}
}
|