public function FlagActionTest::testExecute in Flag 8.4
Tests the execute method.
@covers ::execute
File
- tests/
src/ Unit/ Plugin/ Action/ FlagActionTest.php, line 46
Class
- FlagActionTest
- Unit tests for the flag action plugin.
Namespace
Drupal\Tests\flag\Unit\Plugin\ActionCode
public function testExecute() {
// Test 'flag' op.
$config = [
'flag_id' => $this->flag
->id(),
'flag_action' => 'flag',
];
$flag_service = $this
->prophesize(FlagServiceInterface::class);
$flag_service
->getFlagById($this->flag
->id())
->willReturn($this->flag);
$entity = $this
->prophesize(EntityInterface::class)
->reveal();
$flag_service
->flag($this->flag, $entity)
->shouldBeCalled();
$plugin = new FlagAction($config, 'flag_action:' . $this->flag
->id() . '_flag', [], $flag_service
->reveal());
$plugin
->execute($entity);
// Test 'uflag' op.
$config = [
'flag_id' => $this->flag
->id(),
'flag_action' => 'unflag',
];
$flag_service = $this
->prophesize(FlagServiceInterface::class);
$flag_service
->getFlagById($this->flag
->id())
->willReturn($this->flag);
$entity = $this
->prophesize(EntityInterface::class)
->reveal();
$flag_service
->unflag($this->flag, $entity)
->shouldBeCalled();
$plugin = new FlagAction($config, 'flag_action:' . $this->flag
->id() . '_flag', [], $flag_service
->reveal());
$plugin
->execute($entity);
}