/** * 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() { // 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.'); }
/** * Tests the action execution. * * @covers ::execute */ public function testActionExecution() { $entity_type = 'entity_test'; // Prepare entity storage to return dummy entity on the 'load' execution. $entity = $this->prophesize(EntityInterface::class); $entity_storage = $this->prophesize(EntityStorageInterface::class); $entity_storage->load(1)->willReturn($entity->reveal())->shouldBeCalledTimes(1); $this->entityTypeManager->getStorage($entity_type)->willReturn($entity_storage->reveal())->shouldBeCalledTimes(1); // Set context values for EntityFetchByField action and execute. $this->action->setContextValue('type', $entity_type)->setContextValue('entity_id', 1)->execute(); // Test that entity load with type 'test' and id '1' should return the // dummy entity. $this->assertEquals($entity->reveal(), $this->action->getProvidedContext('entity_fetched')->getContextValue('entity_fetched'), 'Action returns the loaded entity for fetching entity by id.'); }
/** * Tests action execution when a value for limit is provided. * * @covers ::execute */ public function testActionExecutionWithLimit() { $entity_type = 'entity_test'; $field_name = 'test_field'; $field_value = 'llama'; $limit = 2; // Create an array of dummy entities. $entities = array_map(function () { return $this->prophesize(EntityInterface::class)->reveal(); }, range(1, $limit)); // Creates entity ids for new dummy array of entities. $entity_ids = range(1, $limit); // Create dummy query object. $query = $this->prophesize(QueryInterface::class); $query->condition($field_name, $field_value, '=')->willReturn($query->reveal())->shouldBeCalledTimes(1); $query->range(0, $limit)->willReturn($query->reveal())->shouldBeCalledTimes(1); $query->execute()->willReturn($entity_ids)->shouldBeCalledTimes(1); // Create dummy entity storage object. $entityStorage = $this->prophesize(EntityStorageInterface::class); $entityStorage->loadMultiple($entity_ids)->willReturn($entities)->shouldBeCalledTimes(1); $entityStorage->getQuery()->willReturn($query)->shouldBeCalledTimes(1); $this->entityManager->getStorage($entity_type)->willReturn($entityStorage->reveal())->shouldBeCalledTimes(1); // Set context values for EntityFetchByField action and execute. $this->action->setContextValue('type', $entity_type)->setContextValue('field_name', $field_name)->setContextValue('field_value', $field_value)->setContextValue('limit', $limit)->execute(); // Test that executing action with a value for limit returns the dummy entities array. $this->assertEquals($entities, $this->action->getProvidedContext('entity_fetched')->getContextValue('entity_fetched')); }
/** * 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"); }