Skip to content
Permalink
Browse files

Fix return value of setEntity()

It should return $this as documented. Expand test coverage as there
weren't any explicit tests for the new undeprecated methods.

Refs #11012
  • Loading branch information...
markstory committed Aug 8, 2017
1 parent 2843006 commit f4da682a925ef4453f17a7cccfd81697bca3fe21
Showing with 43 additions and 17 deletions.
  1. +1 −1 src/Datasource/EntityTrait.php
  2. +42 −16 tests/TestCase/ORM/EntityTest.php
@@ -753,7 +753,7 @@ public function setDirty($property, $isDirty)
if ($isDirty === false) {
unset($this->_dirty[$property]);
return false;
return $this;
}
$this->_dirty[$property] = true;
@@ -769,31 +769,57 @@ public function testExtract()
}
/**
* Tests dirty() method on a newly created object
* Tests isDirty() method on a newly created object
*
* @return void
*/
public function testDirty()
public function testIsDirty()
{
$entity = new Entity([
'id' => 1,
'title' => 'Foo',
'author_id' => 3
]);
$this->assertTrue($entity->dirty('id'));
$this->assertTrue($entity->dirty('title'));
$this->assertTrue($entity->dirty('author_id'));
$this->assertTrue($entity->isDirty('id'));
$this->assertTrue($entity->isDirty('title'));
$this->assertTrue($entity->isDirty('author_id'));
$this->assertTrue($entity->dirty());
$this->assertTrue($entity->isDirty());
$entity->dirty('id', false);
$this->assertFalse($entity->dirty('id'));
$this->assertTrue($entity->dirty('title'));
$entity->dirty('title', false);
$this->assertFalse($entity->dirty('title'));
$this->assertTrue($entity->dirty());
$entity->dirty('author_id', false);
$this->assertFalse($entity->dirty());
$entity->setDirty('title', false);
$this->assertFalse($entity->isDirty('title'));
$this->assertTrue($entity->isDirty(), 'should be dirty, one field left');
$entity->setDirty('author_id', false);
$this->assertFalse($entity->isDirty(), 'all fields are clean.');
}
/**
* Test setDirty().
*
* @return void
*/
public function testSetDirty()
{
$entity = new Entity([
'id' => 1,
'title' => 'Foo',
'author_id' => 3
], ['markClean' => true]);
$this->assertFalse($entity->isDirty());
$this->assertSame($entity, $entity->setDirty('title', true));
$this->assertSame($entity, $entity->setDirty('id', false));
$entity->setErrors(['title' => ['badness']]);
$entity->setDirty('title', true);
$this->assertEmpty($entity->getErrors('title'), 'Making a field dirty clears errors.');
}
/**
@@ -807,17 +833,17 @@ public function testDirtyChangingProperties()
'title' => 'Foo',
]);
$entity->dirty('title', false);
$this->assertFalse($entity->dirty('title'));
$entity->setDirty('title', false);
$this->assertFalse($entity->isDirty('title'));
$entity->set('title', 'Foo');
$this->assertTrue($entity->dirty('title'));
$this->assertTrue($entity->isDirty('title'));
$entity->set('title', 'Foo');
$this->assertTrue($entity->dirty('title'));
$this->assertTrue($entity->isDirty('title'));
$entity->set('something', 'else');
$this->assertTrue($entity->dirty('something'));
$this->assertTrue($entity->isDirty('something'));
}
/**
@@ -832,8 +858,8 @@ public function testExtractDirty()
'title' => 'Foo',
'author_id' => 3
]);
$entity->dirty('id', false);
$entity->dirty('title', false);
$entity->setDirty('id', false);
$entity->setDirty('title', false);
$expected = ['author_id' => 3];
$result = $entity->extract(['id', 'title', 'author_id'], true);
$this->assertEquals($expected, $result);

0 comments on commit f4da682

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.