// 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());
} // Test the getContextDefinitions() method.
$user_context_definition = EntityContextDefinition::
fromEntityTypeId('user'
)->
setLabel('User'
);
$this->
assertEquals($plugin->
getContextDefinitions()['user'
]->
getLabel(),
$user_context_definition->
getLabel());
// Test the getContextDefinition() method for a valid context.
$this->
assertEquals($plugin->
getContextDefinition('user'
)->
getLabel(),
$user_context_definition->
getLabel());
// Try to get a context with valid definition.
$this->
assertNotNull($plugin->
getContext('user'
), 'Succeeded to get a context with a valid definition.'
);
// Try to get a value of a valid context, while this value has not been set.
try { $plugin->
getContextValue('user'
);
}