Browse Source

Add test for entity clean()

Alexandros Solanos 9 years ago
parent
commit
6b8245dfeb
1 changed files with 30 additions and 1 deletions
  1. 30 1
      tests/TestCase/ORM/TableTest.php

+ 30 - 1
tests/TestCase/ORM/TableTest.php

@@ -1784,7 +1784,6 @@ class TableTest extends TestCase
         $this->assertSame($entity, $table->save($entity));
     }
 
-
     /**
      * Test that save works with replace saveStrategy and are not deleted once they are not null
      *
@@ -2551,6 +2550,7 @@ class TableTest extends TestCase
         $table->save($data);
     }
 
+
     /**
      * Tests that only the properties marked as dirty are actually saved
      * to the database
@@ -6020,6 +6020,35 @@ class TableTest extends TestCase
     }
 
     /**
+     * Tests entity clean()
+     *
+     * @return void
+     */
+    public function testEntityClean()
+    {
+        $table = TableRegistry::get('Articles');
+        $validator = $table->validator()->requirePresence('body');
+        $entity = $table->newEntity(['title' => 'mark']);
+
+        $entity->dirty('title', true);
+        $entity->invalid('title', 'albert');
+
+        $this->assertNotEmpty($entity->errors());
+        $this->assertTrue($entity->dirty());
+        $this->assertEquals(['title' => 'albert'], $entity->invalid());
+
+        $entity->title = 'alex';
+        $this->assertSame($entity->getOriginal('title'), 'mark');
+
+        $entity->clean();
+
+        $this->assertEmpty($entity->errors());
+		$this->assertFalse($entity->dirty());
+        $this->assertEquals([], $entity->invalid());
+        $this->assertSame($entity->getOriginal('title'), 'alex');
+    }
+
+    /**
      * Tests the loadInto() method
      *
      * @return void