cetera example

protected function setupFactoryAndLocalTaskPlugins(array $definitions$active_plugin_id) {
    $map = [];
    $access_manager_map = [];

    foreach ($definitions as $plugin_id => $info) {
      $info += ['access' => AccessResult::allowed()];

      $mock = $this->prophesize(LocalTaskInterface::class);
      $mock->willImplement(CacheableDependencyInterface::class);
      $mock->getRouteName()->willReturn($info['route_name']);
      $mock->getTitle()->willReturn($info['title']);
      $mock->getRouteParameters(Argument::cetera())->willReturn([]);
      $mock->getOptions(Argument::cetera())->willReturn([]);
      $mock->getActive()->willReturn($plugin_id === $active_plugin_id);
      $mock->getWeight()->willReturn($info['weight'] ?? 0);
      $mock->getCacheContexts()->willReturn($info['cache_contexts'] ?? []);
      $mock->getCacheTags()->willReturn($info['cache_tags'] ?? []);
      $mock->getCacheMaxAge()->willReturn($info['cache_max_age'] ?? Cache::PERMANENT);

      $access_manager_map[] = [$info['route_name'][]$this->account, TRUE, $info['access']];

      $map[] = [$info['id'][]$mock->reveal()];
    }

    
$container->set('config.manager', $this->configManager->reveal());
    $container->set('language_manager', $this->languageManager->reveal());
    \Drupal::setContainer($container);

  }

  /** * @covers ::create * @covers ::doCreate */
  public function testCreateWithPredefinedUuid() {
    $this->cacheTagsInvalidator->invalidateTags(Argument::cetera())->shouldNotBeCalled();

    $entity = $this->getMockEntity();
    $entity->set('id', 'foo');
    $entity->set('langcode', 'hu');
    $entity->set('uuid', 'baz');
    $entity->setOriginalId('foo');
    $entity->enforceIsNew();

    $this->moduleHandler->invokeAll('test_entity_type_create', [$entity])
      ->shouldBeCalled();
    $this->moduleHandler->invokeAll('entity_create', [$entity, 'test_entity_type'])
      

  protected $translation;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->translation = $this->getObjectForTrait('\Drupal\Core\StringTranslation\StringTranslationTrait');
    $mock = $this->prophesize(TranslationInterface::class);
    $mock->translate(Argument::cetera())->shouldNotBeCalled();
    $mock->formatPlural(Argument::cetera())->shouldNotBeCalled();
    $mock->translateString(Argument::cetera())->will(function D$args) {
      return $args[0]->getUntranslatedString();
    });
    $this->translation->setStringTranslation($mock->reveal());
    $this->reflection = new \ReflectionClass(get_class($this->translation));
  }

  /** * @covers ::t */
  
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->entityRepository = $this->prophesize(EntityRepositoryInterface::class);
    $this->normalizer = new EntityReferenceFieldItemNormalizer($this->entityRepository->reveal());

    $this->serializer = $this->prophesize(Serializer::class);
    // Set up the serializer to return an entity property.     $this->serializer->normalize(Argument::cetera())
      ->willReturn('test');

    $this->normalizer->setSerializer($this->serializer->reveal());

    $this->fieldItem = $this->prophesize(EntityReferenceItem::class);
    $this->fieldItem->getIterator()
      ->willReturn(new \ArrayIterator(['target_id' => []]));

    $this->fieldDefinition = $this->prophesize(FieldDefinitionInterface::class);
    $this->fieldDefinition->getItemDefinition()
      ->willReturn($this->prophesize(FieldItemDataDefinition::class)->reveal());

  }
$theme = 'stark';
    // When the theme is the system default, an empty string is provided as the     // theme token. See system_js_settings_alter().     $theme_token = '';

    $request = new Request([]);
    $request->query->set('ajax_page_state', ['theme' => $theme, 'theme_token' => $theme_token]);
    $request->request = new InputBag($request->request->all());
    $this->requestStack->push($request);
    $route_match = RouteMatch::createFromRequest($request);

    $this->tokenGenerator->validate(Argument::cetera())->shouldNotBeCalled();

    $result = $this->negotiator->determineActiveTheme($route_match);
    $this->assertSame($theme$result);
  }

}
// \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called       // by \Drupal\Core\Entity\EntityTypeManager::processDefinition() so it must       // always be mocked.       $entity_type->getLinkTemplates()->willReturn([]);

      // Give the entity type a legitimate class to return.       $entity_type->getClass()->willReturn(EntityInterface::class);

      $definitions[$key] = $entity_type->reveal();
    }

    $this->entityTypeManager->getDefinition(Argument::cetera())
      ->will(function D$args) use ($definitions) {
        $entity_type_id = $args[0];
        $exception_on_invalid = $args[1];
        if (isset($definitions[$entity_type_id])) {
          return $definitions[$entity_type_id];
        }
        elseif (!$exception_on_invalid) {
          return NULL;
        }
        else {
          throw new PluginNotFoundException($entity_type_id);
        }
return $data;
  }

  /** * @covers ::getSectionStorageForEntity * * @dataProvider providerTestGetSectionStorageForEntity */
  public function testGetSectionStorageForEntity($entity_type_id$values$expected_context_keys) {
    $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class);
    $section_storage_manager->load('')->willReturn(NULL);
    $section_storage_manager->findByContext(Argument::cetera())->will(function D$arguments) {
      return $arguments[0];
    });
    $this->container->set('plugin.manager.layout_builder.section_storage', $section_storage_manager->reveal());
    $entity = $this->container->get('entity_type.manager')->getStorage($entity_type_id)->create($values);
    $entity->save();
    $class = new TestLayoutEntityHelperTrait();
    $result = $class->getSectionStorageForEntity($entity);
    $this->assertEquals($expected_context_keysarray_keys($result));
    if ($entity instanceof EntityViewDisplayInterface) {
      $this->assertEquals(EntityContext::fromEntity($entity)$result['display']);
    }
    

  protected $tokenGenerator;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Create the machine name controller.     $this->tokenGenerator = $this->prophesize(CsrfTokenGenerator::class);
    $this->tokenGenerator->validate(Argument::cetera())->will(function D$args) {
      return $args[0] === 'token-' . $args[1];
    });

    $this->machineNameController = new MachineNameController(new PhpTransliteration()$this->tokenGenerator->reveal());
  }

  /** * Data provider for testMachineNameController(). * * @see testMachineNameController() * * @return array * An array containing: * - An array of request parameters. * - The expected content of the JSONresponse. */

  protected $resultHandler;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $storage = $this->prophesize(View::class);
    $storage->label()->willReturn('ResultTest');
    $storage->set(Argument::cetera())->willReturn(NULL);

    $user = $this->prophesize(AccountInterface::class)->reveal();
    $views_data = $this->prophesize(ViewsData::class)->reveal();
    $route_provider = $this->prophesize(RouteProviderInterface::class)->reveal();
    $this->view = new ViewExecutable($storage->reveal()$user$views_data$route_provider);

    $this->resultHandler = new Result([], 'result', []);
    $this->resultHandler->view = $this->view;
  }

  /** * Tests the query method. */
$time->getCurrentTime()->willReturn($this->currentTime);
    $time->getCurrentMicroTime()->willReturn(100.0);
    $time->getRequestTime()->willReturn($this->currentTime);
    \Drupal::getContainer()->set('datetime.time', $time->reveal());
    $this->assertEquals($this->currentTime, \Drupal::time()->getCurrentTime());
    $this->assertEquals($this->currentTime, \Drupal::time()->getRequestTime());

    $realQueueFactory = $this->container->get('queue');
    $queue_factory = $this->prophesize(get_class($realQueueFactory));
    $database = new DatabaseQueue('cron_queue_test_database_delay_exception', $this->connection);
    $memory = new Memory('cron_queue_test_memory_delay_exception');
    $queue_factory->get('cron_queue_test_database_delay_exception', Argument::cetera())->willReturn($database);
    $queue_factory->get('cron_queue_test_memory_delay_exception', Argument::cetera())->willReturn($memory);
    $queue_factory->get(Argument::any(), Argument::cetera())->will(function D$args) use ($realQueueFactory) {
      return $realQueueFactory->get($args[0]$args[1] ?? FALSE);
    });

    $this->container->set('queue', $queue_factory->reveal());
  }

  /** * Tests that DelayedRequeueException behaves as expected when running cron. */
  
$plugin->hasFormClass('standard_class')->willReturn(TRUE);
    $plugin->getFormClass('standard_class')->willReturn(get_class($expected));

    $form_object = $this->manager->createInstance($plugin->reveal(), 'standard_class');
    $this->assertSame($expected$form_object);
  }

  /** * @covers ::createInstance */
  public function testCreateInstanceUsingPlugin() {
    $this->classResolver->getInstanceFromDefinition(Argument::cetera())->shouldNotBeCalled();

    $plugin = $this->prophesize(PluginWithFormsInterface::class)->willImplement(PluginFormInterface::class);
    $plugin->hasFormClass('configure')->willReturn(TRUE);
    $plugin->getFormClass('configure')->willReturn(get_class($plugin->reveal()));

    $form_object = $this->manager->createInstance($plugin->reveal(), 'configure');
    $this->assertSame($plugin->reveal()$form_object);
  }

  /** * @covers ::createInstance */
$entity->get('the_field_name')->willReturn($field->reveal());
    $field->view(Argument::type('array'))->will($promise);

    $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $field_definition->getLabel()->willReturn('The Field Label');
    $this->entityFieldManager->getFieldDefinitions('entity_test', 'entity_test')->willReturn(['the_field_name' => $field_definition]);

    if ($log_message) {
      $this->logger->warning($log_message$log_arguments)->shouldBeCalled();
    }
    else {
      $this->logger->warning(Argument::cetera())->shouldNotBeCalled();
    }

    $block = $this->getTestBlock($entity);
    $expected = [
      '#cache' => [
        'contexts' => [],
        'tags' => [],
        'max-age' => 0,
      ],
    ];
    if ($expected_markup) {
      
$url_resolver = $this->prophesize('\Drupal\media\OEmbed\UrlResolverInterface');
    $resource_fetcher = $this->prophesize('\Drupal\media\OEmbed\ResourceFetcherInterface');

    $provider = new Provider('YouTube', 'https://youtube.com', [
      [
        'url' => 'https://youtube.com/foo',
      ],
    ]);
    $resource = Resource::rich('<iframe src="https://youtube.com/watch?feature=oembed"></iframe>', 320, 240, $provider);

    $resource_fetcher->fetchResource(Argument::cetera())->willReturn($resource);

    $this->container->set('media.oembed.url_resolver', $url_resolver->reveal());
    $this->container->set('media.oembed.resource_fetcher', $resource_fetcher->reveal());

    $request = new Request([
      'url' => '',
      'hash' => $hash,
    ]);
    $response = $this->container->get('html_response.attachments_processor')
      ->processAttachments(OEmbedIframeController::create($this->container)
        ->render($request));
    
    $this->assertGenerateFromRoute('test_1', [][]$url(new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));

    $path = $this->generator->getPathFromRoute('test_1');
    $this->assertEquals('test/one', $path);
  }

  /** * @covers ::generateFromRoute */
  public function testUrlGenerationWithDisabledPathProcessing() {
    $path_processor = $this->prophesize(OutboundPathProcessorInterface::class);
    $path_processor->processOutbound(Argument::cetera())->shouldNotBeCalled();

    $generator = new UrlGenerator($this->provider, $path_processor->reveal()$this->routeProcessorManager, $this->requestStack, ['http', 'https']);
    $generator->setContext($this->context);

    $url = $this->generator->generateFromRoute('test_1', []['path_processing' => FALSE]);
    $this->assertEquals('/test/one', $url);
  }

  /** * @covers ::generateFromRoute */
  
$fieldable_entity = $this->prophesize(FieldableEntityInterface::class);
    $fieldable_entity->getEntityTypeId()->willReturn($entity_type_id);
    $fieldable_entity->bundle()->willReturn('the_bundle_id');

    $route_match = $this->prophesize(RouteMatchInterface::class);
    $route_match->getParameter($entity_type_id)->willReturn($fieldable_entity->reveal());

    // \Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplay() is a     // static method and can not be mocked on its own. All of the expectations     // of that method are mocked in the next code block.     $entity_query = $this->prophesize(QueryInterface::class);
    $entity_query->condition(Argument::cetera())->willReturn($entity_query);
    $entity_query->execute()->willReturn([
      'a_fieldable_entity_type.the_bundle_id.full' => 'a_fieldable_entity_type.the_bundle_id.full',
    ]);
    $entity_storage = $this->prophesize(EntityStorageInterface::class);
    $entity_storage->getQuery('AND')->willReturn($entity_query->reveal());
    $entity_storage->loadMultiple(Argument::type('array'))->willReturn([
      'a_fieldable_entity_type.the_bundle_id.full' => $entity_display->reveal(),
    ]);
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager->getStorage('entity_view_display')->willReturn($entity_storage->reveal());
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    
Home | Imprint | This part of the site doesn't use cookies.