Browse Source

Restore IDs in SiteAuthors fixture.

Not having them made non-sqlserver databases unhappy. We'll need another
fixture for composite key + autoincrement.
Mark Story 11 years ago
parent
commit
08173c7263

+ 41 - 0
tests/Fixture/CompositeIncrementsFixture.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.0.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Test\Fixture;
+
+use Cake\TestSuite\Fixture\TestFixture;
+
+class CompositeIncrementsFixture extends TestFixture
+{
+
+    /**
+     * fields property
+     *
+     * @var array
+     */
+    public $fields = [
+        'id' => ['type' => 'integer', 'null' => false, 'autoIncrement' => true],
+        'account_id' => ['type' => 'integer', 'null' => false],
+        'name' => ['type' => 'string', 'default' => null],
+        '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'account_id']]]
+    ];
+
+    /**
+     * records property
+     *
+     * @var array
+     */
+    public $records = [
+    ];
+}

+ 5 - 5
tests/Fixture/SiteAuthorsFixture.php

@@ -25,7 +25,7 @@ class SiteAuthorsFixture extends TestFixture
      * @var array
      */
     public $fields = [
-        'id' => ['type' => 'integer', 'autoIncrement' => true],
+        'id' => ['type' => 'integer'],
         'name' => ['type' => 'string', 'default' => null],
         'site_id' => ['type' => 'integer', 'null' => true],
         '_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'site_id']]]
@@ -37,9 +37,9 @@ class SiteAuthorsFixture extends TestFixture
      * @var array
      */
     public $records = [
-        ['name' => 'mark', 'site_id' => 1],
-        ['name' => 'juan', 'site_id' => 2],
-        ['name' => 'jose', 'site_id' => 2],
-        ['name' => 'andy', 'site_id' => 1]
+        ['id' => 1, 'name' => 'mark', 'site_id' => 1],
+        ['id' => 2, 'name' => 'juan', 'site_id' => 2],
+        ['id' => 3, 'name' => 'jose', 'site_id' => 2],
+        ['id' => 4, 'name' => 'andy', 'site_id' => 1]
     ];
 }

+ 6 - 6
tests/TestCase/ORM/TableTest.php

@@ -55,7 +55,7 @@ class TableTest extends TestCase
         'core.authors',
         'core.tags',
         'core.articles_tags',
-        'core.site_authors',
+        'core.composite_increments',
         'core.site_articles',
     ];
 
@@ -2000,11 +2000,11 @@ class TableTest extends TestCase
     public function testSaveNewCompositeKeyIncrement()
     {
         $this->skipIfSqlite();
-        $articles = TableRegistry::get('SiteAuthors');
-        $article = $articles->newEntity(['site_id' => 3, 'name' => 'new guy']);
-        $this->assertSame($article, $articles->save($article));
-        $this->assertNotEmpty($article->id, 'Primary key should have been populated');
-        $this->assertSame(3, $article->site_id);
+        $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);
     }
 
     /**