You are here

public function EntityMetadataIntegrationTestCase::testBookModule in Entity API 7

Test book module integration.

File

./entity.test, line 1543
Entity CRUD API tests.

Class

EntityMetadataIntegrationTestCase
Tests provided entity property info of the core modules.

Code

public function testBookModule() {
  $title = 'Book 1';
  $node = $this
    ->drupalCreateNode(array(
    'title' => $title,
    'type' => 'book',
    'book' => array(
      'bid' => 'new',
    ),
  ));
  $book = array(
    'bid' => $node->nid,
    'plid' => $node->book['mlid'],
  );
  $node2 = $this
    ->drupalCreateNode(array(
    'type' => 'book',
    'book' => $book,
  ));
  $node3 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
  ));
  $node4 = $this
    ->drupalCreateNode(array(
    'type' => 'book',
    'book' => array(
      'bid' => 0,
      'plid' => -1,
    ),
  ));

  // Test whether the properties work.
  $wrapper = entity_metadata_wrapper('node', $node2);
  $this
    ->assertEqual($title, $wrapper->book->title
    ->value(), "Book title returned.");
  $this
    ->assertEqual(array(
    $node->nid,
  ), $wrapper->book_ancestors
    ->value(array(
    'identifier' => TRUE,
  )), "Book ancestors returned.");
  $this
    ->assertEqual($node->nid, $wrapper->book->nid
    ->value(), "Book id returned.");

  // Try using book properties for no book nodes.
  $wrapper = entity_metadata_wrapper('node', $node3);
  $this
    ->assertEmpty($wrapper, 'book');
  $this
    ->assertEmptyArray($wrapper, 'book_ancestors');

  // Test a book node which is not contained in a hierarchy.
  $wrapper = entity_metadata_wrapper('node', $node4);
  $this
    ->assertEmptyArray($wrapper, 'book_ancestors');
}