Skip to content

Commit

Permalink
Add DDLDropTable and DDLCreateTable into phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 21, 2024
1 parent ce2959b commit 171c32b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion htdocs/core/db/mysqli.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public function DDLDropTable($table)
// phpcs:enable
$tmptable = preg_replace('/[^a-z0-9\.\-\_]/i', '', $table);

$sql = "DROP TABLE ".$tmptable;
$sql = "DROP TABLE ".$this->sanitize($tmptable);

if (!$this->query($sql)) {
return -1;
Expand Down
36 changes: 36 additions & 0 deletions test/phpunit/DoliDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@
*/
class DoliDBTest extends CommonClassTest
{
/**
* testDDLUpdateField
*
* @return int
*/
public function testDDLCreateTable()
{
global $conf,$user,$langs,$db;
$conf = $this->savconf;
$user = $this->savuser;
$langs = $this->savlangs;
$db = $this->savdb;

$namedic = MAIN_DB_PREFIX.'tmptesttabletoremove';

$res = $db->DDLDropTable($namedic);

$columns = array(
'rowid' => array('type' => 'integer', 'value' => 11),
'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'),
'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'),
'active' => array('type' => 'integer', 'value' => 3)
);
$primaryKey = 'rowid';

print __METHOD__.' db->type = '.$db->type."\n";

$res = $db->DDLCreateTable($namedic, $columns, $primaryKey, "");

$this->assertEquals(1, $res);
print __METHOD__." result=".$res."\n";
}

/**
* testDDLUpdateField
*
Expand Down Expand Up @@ -84,6 +119,7 @@ public function testDDLUpdateField()
$field_desc = array('type'=>'varchar', 'value'=>'16', 'null'=>'NOT NULL', 'default'=>'aaaabbbbccccdddd');

$result = $db->DDLUpdateField($db->prefix().'c_paper_format', 'code', $field_desc);

$this->assertEquals(1, $result);
print __METHOD__." result=".$result."\n";

Expand Down

0 comments on commit 171c32b

Please sign in to comment.