$this->
drupalLogin($this->
drupalCreateUser([ 'administer views',
'administer blocks',
]));
// Check if context was correctly propagated to the block.
$definition =
$this->container->
get('plugin.manager.block'
) ->
getDefinition('views_block:test_view_block_with_context-block_1'
);
$this->
assertInstanceOf(ContextDefinitionInterface::
class,
$definition['context_definitions'
]['nid'
]);
/** @var \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context */
$context =
$definition['context_definitions'
]['nid'
];
$this->
assertEquals('entity:node',
$context->
getDataType(), 'Context definition data type is correct.'
);
$this->
assertEquals('Content: ID',
$context->
getLabel(), 'Context definition label is correct.'
);
$this->
assertFalse($context->
isRequired(), 'Context is not required.'
);
// Place test block via block UI to check if contexts are correctly exposed.
$this->
drupalGet( 'admin/structure/block/add/views_block:test_view_block_with_context-block_1/stark',
['query' =>
['region' => 'content'
]] );
$edit =
[ 'settings[context_mapping][nid]' => '@node.node_route_context:node',
];