Browse Source

Move composite key tests into CompositeKeys test suite.

I forgot we had this suite when I made the original tests.
Mark Story 11 years ago
parent
commit
6617d6f2ad
2 changed files with 48 additions and 47 deletions
  1. 48 0
      tests/TestCase/ORM/CompositeKeysTest.php
  2. 0 47
      tests/TestCase/ORM/TableTest.php

+ 48 - 0
tests/TestCase/ORM/CompositeKeysTest.php

@@ -45,6 +45,7 @@ class CompositeKeyTest extends TestCase
      * @var array
      */
     public $fixtures = [
+        'core.composite_increments',
         'core.site_articles',
         'core.site_authors',
         'core.site_tags',
@@ -103,6 +104,39 @@ class CompositeKeyTest extends TestCase
     }
 
     /**
+     * Test that you cannot save rows with composite keys if some columns are missing.
+     *
+     * @group save
+     * @expectedException \RuntimeException
+     * @expectedExceptionMessage Cannot insert row, some of the primary key values are missing
+     * @return void
+     */
+    public function testSaveNewErrorCompositeKeyNoIncrement()
+    {
+        $articles = TableRegistry::get('SiteArticles');
+        $article = $articles->newEntity(['site_id' => 1, 'author_id' => 1, 'title' => 'testing']);
+        $articles->save($article);
+    }
+
+    /**
+     * Test that saving into composite primary keys where one column is missing & autoIncrement works.
+     *
+     * SQLite is skipped because it doesn't support autoincrement composite keys.
+     *
+     * @group save
+     * @return void
+     */
+    public function testSaveNewCompositeKeyIncrement()
+    {
+        $this->skipIfSqlite();
+        $table = TableRegistry::get('CompositeIncrements');
+        $thing = $table->newEntity(['account_id' => 3, 'name' => 'new guy']);
+        $this->assertSame($thing, $table->save($thing));
+        $this->assertNotEmpty($thing->id, 'Primary key should have been populated');
+        $this->assertSame(3, $thing->account_id);
+    }
+
+    /**
      * Tests that HasMany associations are correctly eager loaded and results
      * correctly nested when multiple foreignKeys are used
      *
@@ -636,4 +670,18 @@ class CompositeKeyTest extends TestCase
         ];
         $this->assertEquals($expected, $formatter($items)->toArray());
     }
+
+    /**
+     * Helper method to skip tests when connection is SQLite.
+     *
+     * @return void
+     */
+    public function skipIfSqlite()
+    {
+        $this->skipIf(
+            $this->connection->driver() instanceof \Cake\Database\Driver\Sqlite,
+            'SQLite does not support the requrirements of this test.'
+        );
+    }
+
 }

+ 0 - 47
tests/TestCase/ORM/TableTest.php

@@ -55,7 +55,6 @@ class TableTest extends TestCase
         'core.authors',
         'core.tags',
         'core.articles_tags',
-        'core.composite_increments',
         'core.site_articles',
     ];
 
@@ -1975,39 +1974,6 @@ class TableTest extends TestCase
     }
 
     /**
-     * Test that you cannot save rows with composite keys if some columns are missing.
-     *
-     * @group save
-     * @expectedException \RuntimeException
-     * @expectedExceptionMessage Cannot insert row, some of the primary key values are missing
-     * @return void
-     */
-    public function testSaveNewErrorCompositeKeyNoIncrement()
-    {
-        $articles = TableRegistry::get('SiteArticles');
-        $article = $articles->newEntity(['site_id' => 1, 'author_id' => 1, 'title' => 'testing']);
-        $articles->save($article);
-    }
-
-    /**
-     * Test that saving into composite primary keys where one column is missing & autoIncrement works.
-     *
-     * SQLite is skipped because it doesn't support autoincrement composite keys.
-     *
-     * @group save
-     * @return void
-     */
-    public function testSaveNewCompositeKeyIncrement()
-    {
-        $this->skipIfSqlite();
-        $table = TableRegistry::get('CompositeIncrements');
-        $thing = $table->newEntity(['account_id' => 3, 'name' => 'new guy']);
-        $this->assertSame($thing, $table->save($thing));
-        $this->assertNotEmpty($thing->id, 'Primary key should have been populated');
-        $this->assertSame(3, $thing->account_id);
-    }
-
-    /**
      * Tests that save is wrapped around a transaction
      *
      * @group save
@@ -4059,19 +4025,6 @@ class TableTest extends TestCase
     }
 
     /**
-     * Helper method to skip tests when connection is SQLite.
-     *
-     * @return void
-     */
-    public function skipIfSqlite()
-    {
-        $this->skipIf(
-            $this->connection->driver() instanceof \Cake\Database\Driver\Sqlite,
-            'SQLite does not support the requrirements of this test.'
-        );
-    }
-
-    /**
      * Helper method to skip tests when connection is SQLServer.
      *
      * @return void