/** * @covers ::getContextValues */ public function testGetContextValuesEntityContext() { $input = ['foo' => ['label' => 'Foo', 'type' => 'entity:node', 'value' => 'the_node_uuid']]; $expected = new EntityLazyLoadContext(new ContextDefinition('entity:node', 'Foo'), $this->entityRepository->reveal(), 'the_node_uuid'); $actual = $this->staticContext->getContextValues($input)['foo']; $this->assertEquals($expected, $actual); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->languageManager = $this->prophesize(LanguageManagerInterface::class); $this->entityRepository = new EntityRepository($this->entityTypeManager->reveal(), $this->languageManager->reveal()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class); $this->routeProvider = new TestDefaultHtmlRouteProvider($this->entityTypeManager->reveal(), $this->entityFieldManager->reveal()); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Mock a logger. $this->logger = $this->prophesize(LoggerInterface::class); // Mock the logger service, make it return our mocked logger, and register // it in the container. $this->loggerFactory = $this->prophesize(LoggerChannelFactoryInterface::class); $this->loggerFactory->get('rules')->willReturn($this->logger->reveal()); $this->container->set('logger.factory', $this->loggerFactory->reveal()); // Mock a parameter bag. $this->parameterBag = $this->prophesize(ParameterBag::class); // Mock a request, and set our mocked parameter bag as it attributes // property. $this->currentRequest = $this->prophesize(Request::class); $this->currentRequest->attributes = $this->parameterBag->reveal(); // Mock the request stack, make it return our mocked request when the // current request is requested, and register it in the container. $this->requestStack = $this->prophesize(RequestStack::class); $this->requestStack->getCurrentRequest()->willReturn($this->currentRequest); $this->container->set('request_stack', $this->requestStack->reveal()); // Mock the current path stack. $this->currentPathStack = $this->prophesize(CurrentPathStack::class); $this->container->set('path.current', $this->currentPathStack->reveal()); // Instantiate the redirect action. $this->action = $this->actionManager->createInstance('rules_page_redirect'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->aliasStorage = $this->prophesize(AliasStorageInterface::class); $this->container->set('path.alias_storage', $this->aliasStorage->reveal()); $this->action = $this->actionManager->createInstance('rules_path_alias_delete_by_alias'); }
/** * 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.'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->enableModule('user'); $this->sessionManager = $this->prophesize(SessionManagerInterface::class); $this->container->set('session_manager', $this->sessionManager->reveal()); $this->action = $this->actionManager->createInstance('rules_user_block'); }
/** * {@inheritdoc} * * @covers ::__construct */ protected function setUp() { $this->pageStorage = $this->prophesize(ConfigEntityStorageInterface::class); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeManager->getStorage('page')->willReturn($this->pageStorage); $this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class); $this->routeSubscriber = new PageManagerRoutes($this->entityTypeManager->reveal(), $this->cacheTagsInvalidator->reveal()); }
/** * {@inheritdoc} */ protected function setUp() { $this->pageVariantStorage = $this->prophesize(ConfigEntityStorageInterface::class); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeManager->getStorage('page_variant')->willReturn($this->pageVariantStorage); $this->currentPath = $this->prophesize(CurrentPathStack::class); $this->routeFilter = new VariantRouteFilter($this->entityTypeManager->reveal(), $this->currentPath->reveal()); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->tokenGenerator = $this->prophesize(CsrfTokenGenerator::class); $config_factory = $this->getConfigFactoryStub(['system.theme' => ['default' => 'bartik']]); $this->requestStack = new RequestStack(); $this->negotiator = new AjaxBasePageNegotiator($this->tokenGenerator->reveal(), $config_factory, $this->requestStack); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->logger = $this->prophesize(LoggerInterface::class); $this->mailManager = $this->prophesize(MailManagerInterface::class); $this->container->set('logger.factory', $this->logger->reveal()); $this->container->set('plugin.manager.mail', $this->mailManager->reveal()); $this->action = $this->actionManager->createInstance('rules_send_email'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->keyValueFactory = $this->prophesize(KeyValueFactoryInterface::class); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class); $this->cacheBackend = $this->prophesize(CacheBackendInterface::class); $this->fieldDefinitionListener = new FieldDefinitionListener($this->entityTypeManager->reveal(), $this->entityFieldManager->reveal(), $this->keyValueFactory->reveal(), $this->cacheBackend->reveal()); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Prepare mocked AliasStorageInterface. $this->aliasStorage = $this->prophesize(AliasStorageInterface::class); $this->container->set('path.alias_storage', $this->aliasStorage->reveal()); // Instantiate the action we are testing. $this->action = $this->actionManager->createInstance('rules_entity_path_alias_create:entity:test'); }
public function setUp() { $this->projectRoot = vfsStream::setup('project'); $this->installer = new ComponentInstaller(vfsStream::url('project')); $this->composer = $this->prophesize(Composer::class); $this->io = $this->prophesize(IOInterface::class); $this->installer->activate($this->composer->reveal(), $this->io->reveal()); $this->installationManager = $this->prophesize(InstallationManager::class); $this->composer->getInstallationManager()->willReturn($this->installationManager->reveal()); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // We need the ban module. $this->enableModule('ban'); $this->banManager = $this->prophesize(BanIpManagerInterface::class); $this->container->set('ban.ip_manager', $this->banManager->reveal()); $this->request = $this->prophesize(Request::class); $this->container->set('request', $this->request->reveal()); $this->action = $this->actionManager->createInstance('rules_ban_ip'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->typedDataManager = $this->prophesize(TypedDataManager::class); $container = new ContainerBuilder(); $container->set('string_translation', $this->getStringTranslationStub()); $container->set('typed_data_manager', $this->typedDataManager->reveal()); \Drupal::setContainer($container); $this->page = $this->prophesize(PageInterface::class); $this->event = new PageManagerContextEvent($this->page->reveal()); }
/** * Tests evaluating the condition for an alias that can not be resolved. * * @covers ::evaluate */ public function testConditionEvaluationAliasWithoutPath() { $this->aliasManager->getPathByAlias('alias-for-path-that-does-not-exist', NULL)->willReturn('alias-for-path-that-does-not-exist')->shouldBeCalledTimes(1); $this->aliasManager->getPathByAlias('alias-for-path-that-does-not-exist', 'en')->willReturn('alias-for-path-that-does-not-exist')->shouldBeCalledTimes(1); // First, only set the path context. $this->condition->setContextValue('alias', 'alias-for-path-that-does-not-exist'); // Test without language context set. $this->assertFalse($this->condition->evaluate()); // Test with language context set. $this->condition->setContextValue('language', $this->englishLanguage->reveal()); $this->assertFalse($this->condition->evaluate()); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->logger = $this->prophesize(LoggerInterface::class); $logger_factory = $this->prophesize(LoggerChannelFactoryInterface::class); $logger_factory->get('rules')->willReturn($this->logger->reveal()); $this->mailManager = $this->prophesize(MailManagerInterface::class); // @todo this is wrong, the logger is no factory. $this->container->set('logger.factory', $logger_factory->reveal()); $this->container->set('plugin.manager.mail', $this->mailManager->reveal()); $this->action = $this->actionManager->createInstance('rules_send_email'); }
/** * Tests evaluating the condition for path without an alias. * * @covers ::evaluate */ public function testConditionEvaluationPathWithoutAlias() { $this->aliasManager->getAliasByPath('path-without-alias', NULL)->willReturn('path-without-alias')->shouldBeCalledTimes(1); $this->aliasManager->getAliasByPath('path-without-alias', 'en')->willReturn('path-without-alias')->shouldBeCalledTimes(1); // First, only set the path context. $this->condition->setContextValue('path', 'path-without-alias'); // Test without language context set. $this->assertFalse($this->condition->evaluate()); // Test with language context set. $this->condition->setContextValue('language', $this->englishLanguage->reveal()); $this->assertFalse($this->condition->evaluate()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class); $this->moduleHandler->getImplementations('entity_type_build')->willReturn([]); $this->moduleHandler->alter('entity_type', Argument::type('array'))->willReturn(NULL); $this->cacheBackend = $this->prophesize(CacheBackendInterface::class); $this->translationManager = $this->prophesize(TranslationInterface::class); $this->entityTypeManager = new TestEntityTypeManager(new \ArrayObject(), $this->moduleHandler->reveal(), $this->cacheBackend->reveal(), $this->translationManager->reveal(), $this->getClassResolverStub()); $this->discovery = $this->prophesize(DiscoveryInterface::class); $this->entityTypeManager->setDiscovery($this->discovery->reveal()); }
/** * @covers ::__construct */ public function setUp() { parent::setUp(); $this->contextHandler = $this->prophesize(ContextHandlerInterface::class); $this->entityType = $this->prophesize(EntityTypeInterface::class); $module_handler = $this->prophesize(ModuleHandlerInterface::class); $module_handler->invokeAll(Argument::cetera())->willReturn([]); $this->pageAccess = new PageAccess($this->entityType->reveal(), $this->contextHandler->reveal()); $this->pageAccess->setModuleHandler($module_handler->reveal()); $this->cacheContextsManager = $this->prophesize(CacheContextsManager::class); $container = new ContainerBuilder(); $container->set('cache_contexts_manager', $this->cacheContextsManager->reveal()); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeManager->getDefinitions()->willReturn([$this->entityTypeId => '']); $this->processPlugin = new LinkUri([], 'link_uri', [], $this->entityTypeManager->reveal()); // Url::fromInternalUri() accesses the path validator from the global // container. // @see \Drupal\Core\Url::fromInternalUri() $this->pathValidator = $this->prophesize(PathValidator::class); $container = new ContainerBuilder(); $container->set('path.validator', $this->pathValidator->reveal()); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeRepository = $this->prophesize(EntityTypeRepositoryInterface::class); $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class); $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class); $container = new ContainerBuilder(); $container->set('entity_type.manager', $this->entityTypeManager->reveal()); $container->set('entity_type.repository', $this->entityTypeRepository->reveal()); $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal()); $container->set('entity_field.manager', $this->entityFieldManager->reveal()); $this->entityManager = new EntityManager(); $this->entityManager->setContainer($container); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->pageVariant = new PageVariant(['id' => 'the_page_variant', 'page' => 'the_page'], 'page_variant'); $this->page = $this->prophesize(PageInterface::class); $entity_storage = $this->prophesize(EntityStorageInterface::class); $entity_storage->load('the_page')->willReturn($this->page->reveal()); $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); $entity_type_manager->getStorage('page')->willReturn($entity_storage); $this->contextMapper = $this->prophesize(ContextMapperInterface::class); $container = new ContainerBuilder(); $container->set('entity_type.manager', $entity_type_manager->reveal()); $container->set('page_manager.context_mapper', $this->contextMapper->reveal()); \Drupal::setContainer($container); }
/** * Tests the unique machine name generator. * * @see \Drupal\block\BlockForm::getUniqueMachineName() */ public function testGetUniqueMachineName() { $blocks = array(); $blocks['test'] = $this->getBlockMockWithMachineName('test'); $blocks['other_test'] = $this->getBlockMockWithMachineName('other_test'); $blocks['other_test_1'] = $this->getBlockMockWithMachineName('other_test'); $blocks['other_test_2'] = $this->getBlockMockWithMachineName('other_test'); $query = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface'); $query->expects($this->exactly(5))->method('condition')->will($this->returnValue($query)); $query->expects($this->exactly(5))->method('execute')->will($this->returnValue(array('test', 'other_test', 'other_test_1', 'other_test_2'))); $this->storage->expects($this->exactly(5))->method('getQuery')->will($this->returnValue($query)); $block_form_controller = new BlockForm($this->entityManager, $this->conditionManager, $this->contextRepository, $this->language, $this->themeHandler, $this->pluginFormFactory->reveal()); // Ensure that the block with just one other instance gets the next available // name suggestion. $this->assertEquals('test_2', $block_form_controller->getUniqueMachineName($blocks['test'])); // Ensure that the block with already three instances (_0, _1, _2) gets the // 4th available name. $this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test'])); $this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test_1'])); $this->assertEquals('other_test_3', $block_form_controller->getUniqueMachineName($blocks['other_test_2'])); // Ensure that a block without an instance yet gets the suggestion as // unique machine name. $last_block = $this->getBlockMockWithMachineName('last_test'); $this->assertEquals('last_test', $block_form_controller->getUniqueMachineName($last_block)); }
/** * Tests the clearCachedFieldDefinitions() method. * * @covers ::clearCachedFieldDefinitions */ public function testClearCachedFieldDefinitions() { $this->setUpEntityTypeDefinitions(); $this->cacheTagsInvalidator->invalidateTags(['entity_field_info'])->shouldBeCalled(); $this->container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal())->shouldBeCalled(); $this->typedDataManager->clearCachedDefinitions()->shouldBeCalled(); $this->entityFieldManager->clearCachedFieldDefinitions(); }
/** * Tests that negating a condition works. */ public function testNegation() { $this->trueCondition->getContextDefinitions()->willReturn([]); $this->trueCondition->refineContextDefinitions([])->shouldBeCalledTimes(1); $this->trueCondition->getProvidedContextDefinitions()->willReturn([])->shouldBeCalledTimes(1); $this->conditionManager->createInstance('test_condition', ['negate' => TRUE])->willReturn($this->trueCondition->reveal())->shouldBeCalledTimes(1); // Create a condition which is negated. $condition_expression = new RulesCondition(['condition_id' => 'test_condition', 'negate' => TRUE], '', [], $this->conditionManager->reveal(), $this->processorManager->reveal()); $this->assertFalse($condition_expression->execute()); }
/** * Tests that nested rules are properly executed. * * @covers ::execute */ public function testNestedRules() { $this->testActionExpression->executeWithState(Argument::type(ExecutionStateInterface::class))->shouldBeCalledTimes(1); $nested = new Rule([], 'rules_rule', [], $this->expressionManager->reveal()); // We need to replace the action and conditon container to not have the same // instances as in the outer rule. $nested->setConditions(new RulesAnd([], 'rules_and', [], $this->expressionManager->reveal())); $nested->setActions(new ActionSet([], 'rules_action_set', [], $this->expressionManager->reveal())); $nested->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($this->testActionExpression->reveal()); $this->rule->addExpressionObject($this->trueConditionExpression->reveal())->addExpressionObject($nested)->execute(); }
/** * @dataProvider getInvokeParameters */ public function testInvoke(Request $request, ProphecyInterface $twigProphecy) { $resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class); $resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection(['Foo', 'Bar']))->shouldBeCalled(); $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class); $resourceMetadataFactoryProphecy->create('Foo')->willReturn(new ResourceMetadata('F'))->shouldBeCalled(); $serializerProphecy = $this->prophesize(SerializerInterface::class); $serializerProphecy->serialize(Argument::type(Documentation::class), 'json')->willReturn('hello')->shouldBeCalled(); $action = new SwaggerUiAction($resourceNameCollectionFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), $serializerProphecy->reveal(), $twigProphecy->reveal()); $action($request); }
/** * @dataProvider getCreateDependencies */ public function testCreate(ProphecyInterface $reader, ProphecyInterface $decorated = null, $expectedShortName, $expectedDescription) { $factory = new AnnotationResourceMetadataFactory($reader->reveal(), $decorated ? $decorated->reveal() : null); $metadata = $factory->create(Dummy::class); $this->assertEquals($expectedShortName, $metadata->getShortName()); $this->assertEquals($expectedDescription, $metadata->getDescription()); $this->assertEquals('http://example.com', $metadata->getIri()); $this->assertEquals(['foo' => ['bar' => true]], $metadata->getItemOperations()); $this->assertEquals(['baz' => ['tab' => false]], $metadata->getCollectionOperations()); $this->assertEquals(['a' => 1], $metadata->getAttributes()); }