// Start with two plugins.
$definitions =
[];
$definitions['plugin1'
] =
['id' => 'plugin1'
];
$definitions['plugin2'
] =
['id' => 'plugin2'
];
$type = 'the_type';
$consumer = 'the_consumer';
$extra =
['foo' => 'bar'
];
$context_handler =
$this->
prophesize(ContextHandlerInterface::
class);
// Remove the second plugin when context1 is provided.
$context_handler->
filterPluginDefinitionsByContexts(['context1' => 'fake context'
],
$definitions) ->
willReturn(['plugin1' =>
$definitions['plugin1'
]]);
// Remove the first plugin when no contexts are provided.
$context_handler->
filterPluginDefinitionsByContexts([],
$definitions) ->
willReturn(['plugin2' =>
$definitions['plugin2'
]]);
// After context filtering, the alter hook will be invoked.
$module_handler =
$this->
prophesize(ModuleHandlerInterface::
class);
$hooks =
["plugin_filter_{
$type}", "plugin_filter_{
$type}__{
$consumer}"
];
$module_handler->
alter($hooks,
$expected,
$extra,
$consumer)->
shouldBeCalled();
$theme_manager =
$this->
prophesize(ThemeManagerInterface::
class);