$page->
save();
$article = EntityTestWithBundle::
create(['type' => 'article', 'name' =>
$this->
randomMachineName()]);
$article->
save();
$test = EntityTestWithBundle::
create(['type' => 'test', 'name' =>
$this->
randomMachineName()]);
$test->
save();
// Grab the bundle condition and configure it to check against bundle of
// 'article' and set the context to the page type entity.
/** @var \Drupal\Core\Entity\Plugin\Condition\EntityBundle $condition */
$condition =
$this->container->
get('plugin.manager.condition'
)->
createInstance('entity_bundle:entity_test_with_bundle'
) ->
setConfig('bundles',
['article' => 'article'
]) ->
setContextValue('entity_test_with_bundle',
$page);
$this->
assertFalse($condition->
execute(), 'Page type entities fail bundle checks for articles.'
);
// Check for the proper summary.
$this->
assertEquals('Test entity bundle is article',
$condition->
summary());
$this->
assertEquals('entity_test',
$condition->
getPluginDefinition()['provider'
]);
// Set the bundle check to page.
$condition->
setConfig('bundles',
['page' => 'page'
]);
$this->
assertTrue($condition->
execute(), 'Page type entities pass bundle checks for pages'
);
// Check for the proper summary.
$this->
assertEquals('Test entity bundle is page',
$condition->
summary());