Skip to content

Commit

Permalink
Add test for entity clean()
Browse files Browse the repository at this point in the history
  • Loading branch information
hytromo committed Aug 28, 2016
1 parent b3b6859 commit 6b8245d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/TestCase/ORM/TableTest.php
Expand Up @@ -1784,7 +1784,6 @@ public function testSavePrimaryKeyEntityExists()
$this->assertSame($entity, $table->save($entity));
}


/**
* Test that save works with replace saveStrategy and are not deleted once they are not null
*
Expand Down Expand Up @@ -2551,6 +2550,7 @@ public function testAtomicSaveRollbackOnFailure()
$table->save($data);
}


/**
* Tests that only the properties marked as dirty are actually saved
* to the database
Expand Down Expand Up @@ -6019,6 +6019,35 @@ public function testSaveCorrectPrimaryKeyType()
$this->assertSame(self::$nextUserId, $entity->id);
}

/**
* 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
*
Expand Down

0 comments on commit 6b8245d

Please sign in to comment.