diff --git a/entity.test b/entity.test index 89f75dac49a55ef3e24b77ac028b879d5ecaba07..03c2551a5824c0aa120a0ea9a802dd3568dd61e5 100644 --- a/entity.test +++ b/entity.test @@ -1443,6 +1443,11 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { $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) { $this->assertTrue($wrapper->$key->value() !== NULL, check_plain($key) . ' property returned.'); $info = $wrapper->$key->info(); @@ -1470,8 +1475,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { // Try using book properties for no book nodes. $wrapper = entity_metadata_wrapper('node', $node3); - $this->assertException($wrapper, 'book'); - $this->assertException($wrapper, 'book_ancestors'); + $this->assertEmpty($wrapper, 'book'); + $this->assertEmptyArray($wrapper, 'book_ancestors'); } /** @@ -1579,8 +1584,8 @@ class EntityMetadataIntegrationTestCase extends EntityWebTestCase { $this->assertValue($wrapper, $key); } } - $this->assertException($wrapper, 'book'); - $this->assertException($wrapper, 'book_ancestors'); + $this->assertEmpty($wrapper, 'book'); + $this->assertEmptyArray($wrapper, 'book_ancestors'); $this->assertEmpty($wrapper, 'source'); $this->assertException($wrapper->source, 'title'); $this->assertEmpty($wrapper, 'last_view'); diff --git a/modules/callbacks.inc b/modules/callbacks.inc index 6579233ee5503b38f28fbce894093d4ceffd3dbf..3865efd47d744594f4090382fc9f00702f274ac0 100644 --- a/modules/callbacks.inc +++ b/modules/callbacks.inc @@ -20,12 +20,12 @@ function entity_metadata_entity_get_properties($entity, array $options, $name, $ * @see entity_metadata_book_entity_info_alter() */ 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) { case 'book': - return $node->book['bid']; + if (isset($node->book['bid'])) { + return $node->book['bid']; + } + return NULL; case 'book_ancestors': $ancestors = array();