Skip to content
Permalink
Browse files

Use combined getter/setters for virtual & hidden properties.

The rest of CakePHP uses combined get/set methods, follow that pattern
here as well.

Add test cases as well.
  • Loading branch information...
markstory committed Nov 27, 2013
1 parent 5e5af94 commit 14777652621dc1fad43294f343b407805d741291
Showing with 51 additions and 21 deletions.
  1. +21 −11 Cake/ORM/Entity.php
  2. +30 −10 Cake/Test/TestCase/ORM/EntityTest.php
@@ -295,27 +295,37 @@ public function unsetProperty($property) {
}
/**
* Add additional properties to the hidden list.
* Get/Set the hidden properties on this entity.
*
* If the second argument is true, the hidden field list will be reset with
* the properties provided. The counterpart to this method is makeVisible()
* If the properties argument is null, the currently hidden properties
* will be returned. Otherwise the hidden properties will be set.
*
* @param array $properties The properties to hide.
* @param boolean $reset The reset flag.
* @return Entity $this
* @param null|array Either an array of properties to hide or null to get properties
* @return array|Entity
*/
public function hideProperties($properties) {
public function hiddenProperties($properties = null) {
if ($properties === null) {
return $this->_hidden;
}
$this->_hidden = $properties;
return $this;
}
/**
* Get the list of hidden properties on this entity.
* Get/Set the virtual properties on this entity.
*
* @return array
* If the properties argument is null, the currently virtual properties
* will be returned. Otherwise the virtual properties will be set.
*
* @param null|array Either an array of properties to treat as virtual or null to get properties
* @return array|Entity
*/
public function hiddenProperties() {
return $this->_hidden;
public function virtualProperties($properties = null) {
if ($properties === null) {
return $this->_virtual;
}
$this->_virtual = $properties;
return $this;
}
/**
@@ -649,12 +649,40 @@ public function testToArrayWithAccessor() {
$this->assertEquals($expected, $entity->toArray());
}
/**
* Test that toArray respects hidden properties.
*
* @return void
*/
public function testToArrayHiddenProperties() {
$this->markTestIncomplete("not done");
$data = ['secret' => 'sauce', 'name' => 'mark', 'id' => 1];
$entity = new Entity($data);
$entity->hiddenProperties(['secret']);
$this->assertEquals(['name' => 'mark', 'id' => 1], $entity->toArray());
}
/**
* Test toArray includes 'virtual' properties.
*
* @return void
*/
public function testToArrayVirtualProperties() {
$this->markTestIncomplete("not done");
$entity = $this->getMock('\Cake\ORM\Entity', ['getName']);
$entity->expects($this->any())
->method('getName')
->will($this->returnValue('Jose'));
$entity->set(['email' => 'mark@example.com']);
$entity->virtualProperties(['name']);
$expected = ['name' => 'Jose', 'email' => 'mark@example.com'];
$this->assertEquals($expected, $entity->toArray());
$this->assertEquals(['name'], $entity->virtualProperties());
$entity->hiddenProperties(['name']);
$expected = ['email' => 'mark@example.com'];
$this->assertEquals($expected, $entity->toArray());
$this->assertEquals(['name'], $entity->hiddenProperties());
}
/**
@@ -754,12 +782,4 @@ public function testCleanRemovesErrors() {
$this->assertEmpty($entity->errors());
}
public function testHideProperties() {
$this->markTestIncomplete("not done");
}
public function testVisibleProperties() {
$this->markTestIncomplete("not done");
}
}

0 comments on commit 1477765

Please sign in to comment.
You can’t perform that action at this time.