Browse Source

Changing the SaveOptionsBuilder integration test

Florian Krämer 9 years ago
parent
commit
f4903c69aa
1 changed files with 39 additions and 10 deletions
  1. 39 10
      tests/TestCase/ORM/TableTest.php

+ 39 - 10
tests/TestCase/ORM/TableTest.php

@@ -3823,20 +3823,49 @@ class TableTest extends TestCase
      */
     public function testSaveWithOptionBuilder()
     {
-        $table = $this->getMockBuilder('\Cake\ORM\Table')
-            ->setMethods(['_processSave'])
-            ->getMock();
+        $articles = new Table([
+            'table' => 'articles',
+            'connection' => $this->connection,
+        ]);
+        $articles->belongsTo('Authors');
 
-        $optionBuilder = new SaveOptionsBuilder($table, [
-            'associated' => []
+        $optionBuilder = new SaveOptionsBuilder($articles, [
+            'associated' => [
+                'Authors'
+            ]
         ]);
 
-        $entity = new \Cake\ORM\Entity(
-            ['id' => 'foo'],
-            ['markNew' => false, 'markClean' => true]
-        );
+        $entity = $articles->newEntity([
+            'title' => 'test save options',
+            'author' => [
+                'name' => 'author name'
+            ]
+        ]);
+
+        $articles->save($entity, $optionBuilder);
+        $this->assertFalse($entity->isNew());
+        $this->assertEquals('test save options', $entity->title);
+        $this->assertNotEmpty($entity->id);
+        $this->assertNotEmpty($entity->author->id);
+        $this->assertEquals('author name', $entity->author->name);
+
+        $entity = $articles->newEntity([
+            'title' => 'test save options 2',
+            'author' => [
+                'name' => 'author name'
+            ]
+        ]);
+
+        $optionBuilder = new SaveOptionsBuilder($articles, [
+            'associated' => []
+        ]);
 
-        $this->assertSame($entity, $table->save($entity, $optionBuilder));
+        $articles->save($entity, $optionBuilder);
+        $this->assertFalse($entity->isNew());
+        $this->assertEquals('test save options 2', $entity->title);
+        $this->assertNotEmpty($entity->id);
+        $this->assertEmpty($entity->author->id);
+        $this->assertTrue($entity->author->isNew());
     }
 
     /**