Commit 106d3995 authored by fago's avatar fago

Issue #1330086 by drumm, wodenx, fago | mwidner: Wrapper throws exceptions for...

Issue #1330086 by drumm, wodenx, fago | mwidner: Wrapper throws exceptions for properties that are declared in the info.
parent 8aafdcae
...@@ -1443,6 +1443,11 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { ...@@ -1443,6 +1443,11 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase {
$this->assertTrue($wrapper->$name->value() === NULL, 'Property ' . check_plain($name) . ' is empty.'); $this->assertTrue($wrapper->$name->value() === NULL, 'Property ' . check_plain($name) . ' is empty.');
} }
protected function assertEmptyArray($wrapper, $name) {
$this->assertTrue(isset($wrapper->$name), 'Property ' . check_plain($name) . ' exists.');
$this->assertTrue($wrapper->$name->value() === array(), 'Property ' . check_plain($name) . ' is an empty array.');
}
protected function assertValue($wrapper, $key) { protected function assertValue($wrapper, $key) {
$this->assertTrue($wrapper->$key->value() !== NULL, check_plain($key) . ' property returned.'); $this->assertTrue($wrapper->$key->value() !== NULL, check_plain($key) . ' property returned.');
$info = $wrapper->$key->info(); $info = $wrapper->$key->info();
...@@ -1470,8 +1475,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { ...@@ -1470,8 +1475,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase {
// Try using book properties for no book nodes. // Try using book properties for no book nodes.
$wrapper = entity_metadata_wrapper('node', $node3); $wrapper = entity_metadata_wrapper('node', $node3);
$this->assertException($wrapper, 'book'); $this->assertEmpty($wrapper, 'book');
$this->assertException($wrapper, 'book_ancestors'); $this->assertEmptyArray($wrapper, 'book_ancestors');
} }
/** /**
...@@ -1579,8 +1584,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { ...@@ -1579,8 +1584,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase {
$this->assertValue($wrapper, $key); $this->assertValue($wrapper, $key);
} }
} }
$this->assertException($wrapper, 'book'); $this->assertEmpty($wrapper, 'book');
$this->assertException($wrapper, 'book_ancestors'); $this->assertEmptyArray($wrapper, 'book_ancestors');
$this->assertEmpty($wrapper, 'source'); $this->assertEmpty($wrapper, 'source');
$this->assertException($wrapper->source, 'title'); $this->assertException($wrapper->source, 'title');
$this->assertEmpty($wrapper, 'last_view'); $this->assertEmpty($wrapper, 'last_view');
......
...@@ -20,12 +20,12 @@ function entity_metadata_entity_get_properties($entity, array $options, $name, $ ...@@ -20,12 +20,12 @@ function entity_metadata_entity_get_properties($entity, array $options, $name, $
* @see entity_metadata_book_entity_info_alter() * @see entity_metadata_book_entity_info_alter()
*/ */
function entity_metadata_book_get_properties($node, array $options, $name, $entity_type) { function entity_metadata_book_get_properties($node, array $options, $name, $entity_type) {
if (!isset($node->book['bid'])) {
throw new EntityMetadataWrapperException('This node is no book page.');
}
switch ($name) { switch ($name) {
case 'book': case 'book':
return $node->book['bid']; if (isset($node->book['bid'])) {
return $node->book['bid'];
}
return NULL;
case 'book_ancestors': case 'book_ancestors':
$ancestors = array(); $ancestors = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment