public function EntityMetadataIntegrationTestCase::testNodeProperties in Entity API 7
Test all properties of a node.
File
- ./
entity.test, line 1663 - Entity CRUD API tests.
Class
- EntityMetadataIntegrationTestCase
- Tests provided entity property info of the core modules.
Code
public function testNodeProperties() {
$title = 'Book 1';
$node = $this
->drupalCreateNode(array(
'title' => $title,
'type' => 'page',
));
$wrapper = entity_metadata_wrapper('node', $node);
foreach ($wrapper as $key => $value) {
if ($key != 'book' && $key != 'book_ancestors' && $key != 'source' && $key != 'last_view') {
$this
->assertValue($wrapper, $key);
}
}
$this
->assertEmpty($wrapper, 'book');
$this
->assertEmptyArray($wrapper, 'book_ancestors');
$this
->assertEmpty($wrapper, 'source');
$this
->assertException($wrapper->source, 'title');
$this
->assertEmpty($wrapper, 'last_view');
// Test statistics module integration access.
$unpriviledged_user = $this
->drupalCreateUser(array(
'access content',
));
$this
->assertTrue($wrapper
->access('view', $unpriviledged_user), 'Unpriviledged user can view the node.');
$this
->assertFalse($wrapper
->access('edit', $unpriviledged_user), 'Unpriviledged user can not edit the node.');
$count_access_user = $this
->drupalCreateUser(array(
'view post access counter',
));
$admin_user = $this
->drupalCreateUser(array(
'access content',
'view post access counter',
'access statistics',
));
$this
->assertFalse($wrapper->views
->access('view', $unpriviledged_user), "Unpriviledged user cannot view the statistics counter property.");
$this
->assertTrue($wrapper->views
->access('view', $count_access_user), "Count access user can view the statistics counter property.");
$this
->assertTrue($wrapper->views
->access('view', $admin_user), "Admin user can view the statistics counter property.");
$admin_properties = array(
'day_views',
'last_view',
);
foreach ($admin_properties as $property_name) {
$this
->assertFalse($wrapper->{$property_name}
->access('view', $unpriviledged_user), "Unpriviledged user cannot view the {$property_name} property.");
$this
->assertFalse($wrapper->{$property_name}
->access('view', $count_access_user), "Count access user cannot view the {$property_name} property.");
$this
->assertTrue($wrapper->{$property_name}
->access('view', $admin_user), "Admin user can view the {$property_name} property.");
}
}