Пример #1
0
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     $this->action->setContextValue('bundle', 'test');
     $this->action->execute();
     $entity = $this->action->getProvidedContext('entity')->getContextValue();
     $this->assertEquals(self::ENTITY_REPLACEMENT, $entity);
 }
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     $alias = 'about/team';
     $this->aliasStorage->delete(['alias' => $alias])->shouldBeCalledTimes(1);
     $this->action->setContextValue('alias', $alias);
     $this->action->execute();
 }
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     $path = 'node/1';
     $this->aliasStorage->delete(['path' => $path])->shouldBeCalledTimes(1);
     $this->action->setContextValue('path', $path);
     $this->action->execute();
 }
Пример #4
0
 /**
  * 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.');
 }
Пример #5
0
 /**
  * Tests that the action works if the optional repeat flag is not set.
  *
  * @covers ::execute
  */
 public function testOptionalRepeat()
 {
     $this->action->setContextValue('message', 'test message')->setContextValue('type', 'status');
     $this->action->execute();
     $messages = $this->getMessages('status');
     $this->assertNotNull($messages);
     $this->assertArrayEquals(['test message'], $messages);
 }
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     $list = ['One', 'Two', 'Three'];
     $this->action->setContextValue('list', $list)->setContextValue('item', 'Two');
     $this->action->execute();
     // The second item should be removed from the list.
     $this->assertArrayEquals(['One', 'Three'], array_values($this->action->getContextValue('list')));
 }
Пример #7
0
 /**
  * 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());
 }
Пример #8
0
 /**
  * Tests the action execution when a language is specified.
  *
  * @covers ::execute
  */
 public function testActionExecutionWithLanguage()
 {
     $language = $this->prophesize(LanguageInterface::class);
     $language->getId()->willReturn('en');
     $this->aliasStorage->save('node/1', 'about', 'en')->shouldBeCalledTimes(1);
     $this->action->setContextValue('source', 'node/1')->setContextValue('alias', 'about')->setContextValue('language', $language->reveal());
     $this->action->execute();
 }
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     $account = $this->prophesizeEntity(UserInterface::class);
     $mail_type = 'test_mail_type';
     $this->action->setContextValue('user', $account->reveal())->setContextValue('email_type', $mail_type);
     $this->action->execute();
     // To ge the notifications that were sent, we call the _user_mail_notify()
     // with no parameters.
     $notifications = _user_mail_notify();
     $this->assertSame([$mail_type => 1], $notifications);
 }
 /**
  * Tests the action execution with a saved entity.
  *
  * @covers ::execute
  */
 public function testActionExecutionWithSavedEntity()
 {
     // Test that the alias is only saved once.
     $this->aliasStorage->save('test/1', 'about', 'en')->shouldBeCalledTimes(1);
     $entity = $this->getMockEntity();
     $entity->isNew()->willReturn(FALSE)->shouldBeCalledTimes(1);
     // Test that existing entities are not saved again.
     $entity->save()->shouldNotBeCalled();
     $this->action->setContextValue('entity', $entity->reveal())->setContextValue('alias', 'about');
     $this->action->execute();
 }
Пример #11
0
 /**
  * Tests the action execution.
  *
  * @covers ::execute
  */
 public function testActionExecution()
 {
     // Prepare entity storage to return dummy entity on the 'load' execution.
     $entity = $this->prophesize(EntityInterface::class);
     $entityStorage = $this->prophesize(EntityStorageInterface::class);
     $entityStorage->load(1)->willReturn($entity->reveal())->shouldBeCalledTimes(1);
     $this->entityManager->getStorage('test')->willReturn($entityStorage->reveal())->shouldBeCalledTimes(1);
     $this->action->setContextValue('entity_type_id', 'test')->setContextValue('entity_id', 1)->execute();
     // Entity load with type 'test' and id '1' should return the dummy entity.
     $this->assertEquals($entity->reveal(), $this->action->getProvidedContext('entity')->getContextValue('entity'), 'Action returns the loaded entity for fetching entity by id.');
 }
Пример #12
0
 /**
  * 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.');
 }
Пример #13
0
 /**
  * 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.');
 }
Пример #14
0
 /**
  * Tests the action execution without Context IP set.
  *
  * Should fallback to the current IP of the request.
  *
  * @covers ::execute
  */
 public function testActionExecutionWithoutContextIP()
 {
     // TEST-NET-1 IPv4.
     $ip = '192.0.2.0';
     $this->request->getClientIp()->willReturn($ip)->shouldBeCalledTimes(1);
     $this->banManager->banIp($ip)->shouldBeCalledTimes(1);
     $this->action->execute();
 }
Пример #15
0
 /**
  * Tests the action execution - add non-unique items.
  *
  * @covers ::execute
  */
 public function testActionExecutionNonUnique()
 {
     // Test non-unique.
     $list = ['One', 'Two', 'Three', 'Four'];
     $this->action->setContextValue('list', $list)->setContextValue('item', 'Four')->setContextValue('unique', FALSE)->setContextValue('pos', 'end');
     $this->action->execute();
     // The list should contain five items, with the new item added at the end.
     $this->assertArrayEquals(['One', 'Two', 'Three', 'Four', 'Four'], $this->action->getContextValue('list'));
 }
 /**
  * Tests the use of max operator for 2 input values.
  *
  * @covers ::execute
  */
 public function testMaximumAction()
 {
     $input_1 = mt_rand();
     $input_2 = mt_rand();
     $this->action->setContextValue('input_1', $this->getTypedData('float', $input_1))->setContextValue('operator', $this->getTypedData('string', 'max'))->setContextValue('input_2', $this->getTypedData('float', $input_2));
     $this->action->execute();
     $result = $this->action->getProvidedContext('result')->getContextValue();
     $this->assertEquals(max($input_1, $input_2), $result, "Max calculation correct");
 }
Пример #17
0
 /**
  * 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.');
 }
 /**
  * @covers ::refineContextDefinitions
  */
 public function testRefiningContextDefinitions()
 {
     $this->action->setContextValue('type', 'entity_test');
     $this->action->refineContextdefinitions();
     $this->assertEquals($this->action->getProvidedContextDefinition('entity_fetched')->getDataType(), 'entity:entity_test');
 }
Пример #19
0
 /**
  * Tests the context refining.
  *
  * @covers ::refineContextDefinitions
  */
 public function testRefiningContextDefinitions()
 {
     $this->action->setContextValue('bundle', 'bundle_test');
     $this->action->refineContextDefinitions([]);
     $this->assertEquals($this->action->getProvidedContextDefinition('entity')->getDataType(), 'entity:test:bundle_test');
 }