/** * Tests the action execution when saving is postponed. * * @covers ::execute */ public function testActionExecutionPostponed() { $this->entity->save()->shouldNotBeCalled(); $this->action->setContextValue('entity', $this->entity->reveal()); $this->action->execute(); $this->assertEquals($this->action->autoSaveContext(), ['entity'], 'Action returns the entity context name for auto saving.'); }
/** * Tests that a variable can be set to NULL. */ public function testSetToNull() { // We don't need to set the 'value' context, it is NULL by default. $this->action->setContextValue('data', 'original'); $this->action->execute(); $this->assertNull($this->action->getContextValue('data')); $this->assertSame([], $this->action->autoSaveContext()); }
/** * Tests removing non-existing role from user. * * @covers ::execute */ public function testRemoveNonExistingRole() { // Set-up a mock user with role 'editor'. $account = $this->prophesizeEntity(UserInterface::class); $account->hasRole('editor')->willReturn(FALSE); $account->removeRole('editor')->shouldNotBeCalled(); // Mock the 'editor' user role. $editor = $this->prophesize(RoleInterface::class); $editor->id()->willReturn('editor'); // Test removing of one role. $this->action->setContextValue('user', $account->reveal())->setContextValue('roles', [$editor->reveal()])->execute(); $this->assertNotEquals($this->action->autoSaveContext(), ['user'], 'Action returns the user context name for auto saving.'); }
/** * Test execute() method for users with different status. * @dataProvider userProvider * @covers ::execute */ public function testUnblockUser($active, $authenticated, $expects, $autosave_names) { // Set-up a mock user. $account = $this->prophesizeEntity(UserInterface::class); // Mock isBlocked. $account->isBlocked()->willReturn(!$active); // Mock isAuthenticated. $account->isAuthenticated()->willReturn($authenticated); // Mock activate. $account->activate()->shouldBeCalledTimes($expects); // We do noe expect call of the 'save' method because user should be // auto-saved later. $account->save()->shouldNotBeCalled(); // Test unblocking the user. $this->action->setContextValue('user', $account->reveal())->execute(); $this->assertEquals($this->action->autoSaveContext(), $autosave_names, 'Action returns correct context name for auto saving.'); }
/** * Tests adding of one existing and one nonexistent role to user. * * @covers ::execute */ public function testAddExistingAndNonexistentRole() { // Set-up a mock user with role 'administrator' but without 'editor'. $account = $this->prophesizeEntity(UserInterface::class); $account->hasRole('administrator')->willReturn(TRUE)->shouldBeCalledTimes(1); $account->hasRole('editor')->willReturn(FALSE)->shouldBeCalledTimes(1); // We expect only one call of the 'addRole' method. $account->addRole('editor')->shouldBeCalledTimes(1); // Mock user roles. $editor = $this->prophesize(RoleInterface::class); $editor->id()->willReturn('editor'); $administrator = $this->prophesize(RoleInterface::class); $administrator->id()->willReturn('administrator'); // Test adding one role. $this->action->setContextValue('user', $account->reveal())->setContextValue('roles', [$administrator->reveal(), $editor->reveal()])->execute(); $this->assertEquals($this->action->autoSaveContext(), ['user'], 'Action returns the user context name for auto saving.'); }