/**
* Tests basic context definition and value getters and setters.
*/
public function testContext() { $this->
installEntitySchema('user'
);
$this->
installEntitySchema('node'
);
$type = NodeType::
create(['type' => 'page', 'name' => 'Page'
]);
$type->
save();
$name =
$this->
randomMachineName();
$manager =
new MockBlockManager();
$plugin =
$manager->
createInstance('user_name'
);
// Create a node, add it as context, catch the exception.
$node = Node::
create(['type' => 'page', 'title' =>
$name]);
// Try to get context that is missing its definition.
try { $plugin->
getContextDefinition('not_exists'
);
$this->
fail('The user context should not yet be set.'
);
} catch (ContextException
$e) { $this->
assertEquals('The not_exists context is not a valid context.',
$e->
getMessage());
}