Skip to content
Permalink
Browse files

Delete unused fixture and add a test which asserts that single column…

… constraint works as expected
  • Loading branch information...
HavokInspiration committed Jun 17, 2015
1 parent 8b45acb commit cd4ac1d89b2f7c8cfdc3d1feae36b58959c1b7a6
@@ -33,7 +33,7 @@ class ArticlesTagsFixture extends TestFixture
'tag_id' => ['type' => 'integer', 'null' => false],
'_constraints' => [
'unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']],
'tag_idx' => [
'tag_id_fk' => [
'type' => 'foreign',
'columns' => ['tag_id'],
'references' => ['tags', 'id'],

This file was deleted.

Oops, something went wrong.
@@ -37,15 +37,10 @@ class OrdersFixture extends TestFixture
'id' => ['type' => 'integer'],
'product_category' => ['type' => 'integer', 'null' => false],
'product_id' => ['type' => 'integer', 'null' => false],
'customer_id' => ['type' => 'integer', 'null' => false],
'_indexes' => [
'product_category' => [
'type' => 'index',
'columns' => ['product_category', 'product_id']
],
'customer_id' => [
'type' => 'index',
'columns' => ['customer_id']
]
],
'_constraints' => [
@@ -58,13 +53,6 @@ class OrdersFixture extends TestFixture
'references' => ['products', ['id', 'category']],
'update' => 'cascade',
'delete' => 'cascade',
],
'order_ibfk_2' => [
'type' => 'foreign',
'columns' => ['customer_id'],
'references' => ['customers', 'id'],
'update' => 'cascade',
'delete' => 'cascade',
]
]
];
@@ -75,6 +63,6 @@ class OrdersFixture extends TestFixture
* @var array
*/
public $records = [
['product_category' => 1, 'product_id' => 1, 'customer_id' => 1]
['product_category' => 1, 'product_id' => 1]
];
}
@@ -25,7 +25,7 @@
class TableTest extends TestCase
{
public $fixtures = ['core.customers', 'core.products', 'core.orders'];
public $fixtures = ['core.articles_tags', 'core.products', 'core.orders'];
/**
* Test construction with columns
@@ -409,12 +409,36 @@ public function testAddConstraintForeignKey()
$this->assertEquals(['author_id_idx'], $table->constraints());
}
/**
* Test single column foreign keys constraint support
*
* @return void
*/
public function testConstraintForeignKey()
{
$table = TableRegistry::get('ArticlesTags');
$compositeConstraint = $table->schema()->constraint('tag_id_fk');
$expected = [
'type' => 'foreign',
'columns' => ['tag_id'],
'references' => ['tags', 'id'],
'update' => 'cascade',
'delete' => 'cascade',
'length' => []
];
$this->assertEquals($expected, $compositeConstraint);
$expectedSubstring = 'CONSTRAINT <tag_id_fk> FOREIGN KEY \(<tag_id>\) REFERENCES <tags> \(<id>\)';
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
}
/**
* Test composite foreign keys support
*
* @return void
*/
public function testAddConstraintForeignKeyTwoColumns()
public function testConstraintForeignKeyTwoColumns()
{
$table = TableRegistry::get('Orders');
$compositeConstraint = $table->schema()->constraint('product_id_fk');
@@ -438,7 +462,7 @@ public function testAddConstraintForeignKeyTwoColumns()
$expectedSubstring = 'CONSTRAINT <product_id_fk> FOREIGN KEY \(<product_id>, <product_category>\)' .
' REFERENCES <products> \(<id>, <category>\)';
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('default'))[0]);
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
}
/**

0 comments on commit cd4ac1d

Please sign in to comment.
You can’t perform that action at this time.