Skip to content

Commit

Permalink
Merge pull request ezsystems#1215 from ezsystems/fix-EZP-24106-ezpage…
Browse files Browse the repository at this point in the history
…-is-empty

Fix EZP-24106: ez_is_field_empty does not work for a Page field
  • Loading branch information
pspanja committed Mar 25, 2015
2 parents f0c0bb3 + 71f9733 commit 8371799
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
25 changes: 25 additions & 0 deletions eZ/Publish/Core/FieldType/Page/Type.php
Expand Up @@ -118,6 +118,31 @@ public function getEmptyValue()
return new Value();
}

/**
* Returns if the given $value is considered empty by the field type
*
* @param \eZ\Publish\Core\FieldType\Page\Value $value
*
* @return boolean
*/
public function isEmptyValue( SPIValue $value )
{
if ( $value === null || $value == $this->getEmptyValue() )
{
return true;
}

foreach ( $value->page->zones as $zone )
{
if ( !empty( $zone->blocks ) )
{
return false;
}
}

return true;
}

/**
* Converts an $hash to the Value defined by the field type
*
Expand Down
50 changes: 49 additions & 1 deletion eZ/Publish/Core/FieldType/Tests/PageTest.php
Expand Up @@ -274,7 +274,7 @@ public function provideValidInputForAcceptValue()
),
array(
new PageValue( new Page() ),
new PageValue( new Page() )
new PageValue()
)
);
}
Expand Down Expand Up @@ -466,4 +466,52 @@ public function provideDataForGetName()
array( new PageValue( $this->getPageReference() ), "" )
);
}

/**
* Data provider for valid input to isEmptyValue().
*
* Returns an array of data provider sets with 2 arguments:
*
* 1. The valid input to isEmptyValue()
* 2. The expected return value from isEmptyValue()
*
* For example:
*
* <code>
* return array(
* array(
* new PageValue(),
* true
* ),
* array(
* new PageValue( $this->getPageReference() ),
* false
* ),
* // ...
* );
* </code>
*
* @return array
*/
public function providerForTestIsEmptyValue()
{
return array(
array( new PageValue(), true ),
array( new PageValue( $this->getPageReference() ), false ),
);
}

/**
* @dataProvider providerForTestIsEmptyValue
*/
public function testIsEmptyValue( $value, $state )
{
$fieldType = $this->getFieldTypeUnderTest();

$this->assertEquals(
$state,
$fieldType->isEmptyValue( $value ),
"Value did not evaluate as " . ( $state ? "" : "non-" ) . "empty"
);
}
}

0 comments on commit 8371799

Please sign in to comment.