Skip to content

Commit

Permalink
Additional test that indexes are dropped when a table is dropped. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed May 20, 2019
1 parent 84a56f8 commit b645345
Showing 1 changed file with 125 additions and 114 deletions.
239 changes: 125 additions & 114 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,19 @@ public function testCreateTable()
{
$this->forge->dropTable('forge_test_table', true);

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'mobile' => [
'type' => 'INTEGER',
'constraint' => 10,
'unsigned' => true,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'mobile' => [
'type' => 'INTEGER',
'constraint' => 10,
'unsigned' => true,
],
]);

$unsignedAttributes = [
'INTEGER',
Expand Down Expand Up @@ -141,15 +139,15 @@ public function testCreateTableWithArrayFieldConstraints()
{
$this->forge->dropTable('forge_array_constraint', true);
$this->forge->addField([
'status' => [
'type' => 'ENUM',
'constraint' => [
'sad',
'ok',
'happy',
],
],
]);
'status' => [
'type' => 'ENUM',
'constraint' => [
'sad',
'ok',
'happy',
],
],
]);
$this->forge->createTable('forge_array_constraint');

$fields = $this->db->getFieldData('forge_array_constraint');
Expand Down Expand Up @@ -288,37 +286,33 @@ public function testForeignKey()
$attributes = ['ENGINE' => 'InnoDB'];
}

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('forge_test_users', true, $attributes);

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('users_id', 'forge_test_users', 'id', 'CASCADE', 'CASCADE');

Expand Down Expand Up @@ -353,37 +347,33 @@ public function testForeignKeyFieldNotExistException()
$attributes = ['ENGINE' => 'InnoDB'];
}

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('forge_test_users', true, $attributes);

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('user_id', 'forge_test_users', 'id', 'CASCADE', 'CASCADE');

Expand All @@ -404,32 +394,32 @@ public function testDropForeignKey()
}

$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('forge_test_users', true, $attributes);

$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'users_id' => [
'type' => 'INTEGER',
'constraint' => 11,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('users_id', 'forge_test_users', 'id', 'CASCADE', 'CASCADE');

Expand All @@ -449,16 +439,14 @@ public function testAddColumn()
{
$this->forge->dropTable('forge_test_table', true);

$this->forge->addField(
[
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
'unsigned' => false,
'auto_increment' => true,
],
]
);
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 11,
'unsigned' => false,
'auto_increment' => true,
],
]);

$this->forge->addKey('id', true);
$this->forge->createTable('forge_test_table');
Expand All @@ -474,8 +462,8 @@ public function testAddColumn()
$this->forge->addColumn('forge_test_table', $newField);

$fieldNames = $this->db->table('forge_test_table')
->get()
->getFieldNames();
->get()
->getFieldNames();

$this->forge->dropTable('forge_test_table', true);

Expand Down Expand Up @@ -715,4 +703,27 @@ public function testConnectWithArrayGroup()

$this->assertInstanceOf(Forge::class, $forge);
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1983
*/
public function testDropTableSuccess()
{
// Add an index to user table so we have
// something to work with
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 3,
],
]);
$this->forge->addKey('id');
$this->forge->createTable('droptest');

$this->assertCount(1, $this->db->getIndexData('droptest'));

$this->forge->dropTable('droptest', true);

$this->assertCount(0, $this->db->getIndexData('droptest'));
}
}

0 comments on commit b645345

Please sign in to comment.