willImplement example



  /** * Provides test data for plugin dependencies. */
  public static function providerTestPluginDependencies() {
    $prophet = new Prophet();
    $data = [];

    $plugin = $prophet->prophesize(PluginInspectionInterface::class);

    $dependent_plugin = $prophet->prophesize(PluginInspectionInterface::class)->willImplement(DependentPluginInterface::class);
    $dependent_plugin->calculateDependencies()->willReturn([
      'module' => ['test_module2'],
    ]);

    $data['dependent_plugin_from_module'] = [
      $dependent_plugin,
      ['provider' => 'test_module1'],
      [
        'module' => [
          'test_module1',
          'test_module2',
        ],
$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 */
  public function testCreateInstanceUsingPluginWithSlashes() {
    
$this->assertEqualsCanonicalizing(['context.example1', 'context.example2', 'route', 'user.permissions']$cacheability->getCacheContexts());
  }

  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']];

      
/** * Tests the getFieldDefinitions() method. * * @covers ::getFieldDefinitions * @covers ::buildBundleFieldDefinitions */
  public function testGetFieldDefinitions() {
    $field_definition = $this->setUpEntityWithFieldDefinition();

    $bundle_field_definition = $this->prophesize()
      ->willImplement(FieldDefinitionInterface::class)
      ->willImplement(FieldStorageDefinitionInterface::class);

    // Define bundle fields to be stored on the default Entity class.     $bundle_fields = [
      'the_entity_id' => [
        'test_entity_bundle' => [
          'id_bundle' => $bundle_field_definition->reveal(),
        ],
        'test_entity_bundle_class' => [
          'some_extra_field' => $bundle_field_definition->reveal(),
        ],
      ],

class BlockPluginHasSettingsTrayFormAccessCheckTest extends UnitTestCase {

  /** * @covers ::access * @covers ::accessBlockPlugin * @dataProvider providerTestAccess */
  public function testAccess($with_forms, array $plugin_definition, AccessResultInterface $expected_access_result) {
    $block_plugin = $this->prophesize()->willImplement(BlockPluginInterface::class);

    if ($with_forms) {
      $block_plugin->willImplement(PluginWithFormsInterface::class);
      $block_plugin->hasFormClass(Argument::type('string'))->will(function D$arguments) use ($plugin_definition) {
        return !empty($plugin_definition['forms'][$arguments[0]]);
      });
    }

    $block = $this->prophesize(BlockInterface::class);
    $block->getPlugin()->willReturn($block_plugin->reveal());

    


    $definitions = [
      'first' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
      'second' => (new SectionStorageDefinition())->setClass(SectionStorageInterface::class),
    ];
    $this->discovery->getDefinitions()->willReturn($definitions);

    // Create a plugin that has cacheability info itself as a cacheable object     // and from within ::isApplicable() but is not applicable.     $first_plugin = $this->prophesize(SectionStorageInterface::class);
    $first_plugin->willImplement(CacheableDependencyInterface::class);
    $first_plugin->getCacheContexts()->shouldNotBeCalled();
    $first_plugin->getCacheTags()->shouldNotBeCalled();
    $first_plugin->getCacheMaxAge()->shouldNotBeCalled();
    $first_plugin->isApplicable($cacheability)->will(function D$arguments) {
      $arguments[0]->addCacheTags(['first_plugin']);
      return FALSE;
    });

    // Create a plugin that adds cacheability info from within ::isApplicable()     // and is applicable.     $second_plugin = $this->prophesize(SectionStorageInterface::class);
    
$data = [];

    $content = new EntityType(['id' => 'test_content']);
    $config = new EntityType(['id' => 'test_config']);

    // Entities without bundles.     $data['content entity, matching type, no value'] = [
      TRUE,
      EntityContextDefinition::fromEntityType($content),
      EntityContextDefinition::fromEntityType($content),
    ];
    $entity = (new Prophet())->prophesize(ContentEntityInterface::class)->willImplement(\IteratorAggregate::class);
    $entity->getIterator()->willReturn(new \ArrayIterator([]));
    $entity->getCacheContexts()->willReturn([]);
    $entity->getCacheTags()->willReturn([]);
    $entity->getCacheMaxAge()->willReturn(0);
    $entity->getEntityTypeId()->willReturn('test_content');
    $data['content entity, matching type, correct value'] = [
      TRUE,
      EntityContextDefinition::fromEntityType($content),
      EntityContextDefinition::fromEntityType($content),
      $entity->reveal(),
    ];
    

  protected $entityStorage;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $serializer = $this->prophesize(SerializerInterface::class);
    $serializer->willImplement(DecoderInterface::class);
    $serializer->decode(Json::encode(['this is an array']), 'json', Argument::type('array'))
      ->willReturn(['this is an array']);
    $this->requestHandler = new RequestHandler($serializer->reveal());
  }

  /** * @covers ::handle */
  public function testHandle() {
    $request = new Request([][][][][]['CONTENT_TYPE' => 'application/json'], Json::encode(['this is an array']));
    $route_match = new RouteMatch('test', (new Route('/rest/test', ['_rest_resource_config' => 'restplugin', 'example' => '']['_format' => 'json']))->setMethods(['GET']));

    
\Drupal::setContainer($container);
  }

  /** * @covers ::onBuildRender * * @dataProvider providerBlockTypes */
  public function testOnBuildRender($refinable_dependent_access) {
    $contexts = [];
    if ($refinable_dependent_access) {
      $block = $this->prophesize(TestBlockPluginWithRefinableDependentAccessInterface::class)->willImplement(PreviewFallbackInterface::class);
      $layout_entity = $this->prophesize(EntityInterface::class);
      $layout_entity = $layout_entity->reveal();
      $context = $this->prophesize(ContextInterface::class);
      $context->getContextValue()->willReturn($layout_entity);
      $contexts['layout_builder.entity'] = $context->reveal();

      $block->setAccessDependency($layout_entity)->shouldBeCalled();
    }
    else {
      $block = $this->prophesize(BlockPluginInterface::class)->willImplement(PreviewFallbackInterface::class);
    }
    
$entity_type_manager->getStorage('node')->willReturn($entity_storage->reveal());
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity_type->getKey('uuid')->willReturn('uuid');
    $entity_type_manager->getDefinition('node')->willReturn($entity_type->reveal());

    $this->normalizer = new JsonApiDocumentTopLevelNormalizer(
      $entity_type_manager->reveal(),
      $resource_type_repository->reveal()
    );

    $serializer = $this->prophesize(DenormalizerInterface::class);
    $serializer->willImplement(SerializerInterface::class);
    $serializer->denormalize(
      Argument::type('array'),
      Argument::type('string'),
      Argument::type('string'),
      Argument::type('array')
    )->willReturnArgument(0);

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

  /** * @covers ::denormalize * @dataProvider denormalizeProvider */
$components[] = $non_derivative_component->reveal();

    // Ensure a derivative component with a different base Id is not returned.     $derivative_non_inline_component = $prophet->prophesize(SectionComponent::class);
    $plugin = $prophet->prophesize(DerivativeInspectionInterface::class);
    $plugin->getBaseId()->willReturn('some_other_base_id_which_we_do_not_care_about_but_it_is_nothing_personal');
    $derivative_non_inline_component->getPlugin()->willReturn($plugin);
    $components[] = $derivative_non_inline_component->reveal();

    // Ensure that inline block component is returned.     $inline_component = $prophet->prophesize(SectionComponent::class);
    $inline_plugin = $prophet->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class);
    $inline_plugin->getBaseId()->willReturn('inline_block');
    $inline_plugin->getConfiguration()->willReturn(['block_revision_id' => 'the_revision_id']);
    $inline_component->getPlugin()->willReturn($inline_plugin->reveal());
    $inline_component = $inline_component->reveal();
    $components[] = $inline_component;

    // Ensure that inline block component without revision is returned.     $inline_component_without_revision_id = $prophet->prophesize(SectionComponent::class);
    $inline_plugin_without_revision_id = $prophet->prophesize(DerivativeInspectionInterface::class)->willImplement(ConfigurableInterface::class);
    $inline_plugin_without_revision_id->getBaseId()->willReturn('inline_block');
    $inline_plugin_without_revision_id->getConfiguration()->willReturn(['other_key' => 'other_value']);
    
'#base_plugin_id' => 'block_plugin_id',
      '#derivative_plugin_id' => NULL,
      'content' => $block_content,
      '#cache' => [
        'contexts' => [],
        'tags' => [],
        'max-age' => -1,
      ],
      '#in_preview' => FALSE,
    ];

    $block = $this->prophesize(BlockPluginInterface::class)->willImplement(PreviewFallbackInterface::class);
    $this->blockManager->createInstance('block_plugin_id', ['id' => 'block_plugin_id'])->willReturn($block->reveal());

    $access_result = AccessResult::allowed();
    $block->access($this->account->reveal(), TRUE)->willReturn($access_result);
    $block->build()->willReturn($block_content);
    $block->getCacheContexts()->willReturn([]);
    $block->getCacheTags()->willReturn([]);
    $block->getCacheMaxAge()->willReturn(Cache::PERMANENT);
    $block->getPluginId()->willReturn('block_plugin_id');
    $block->getBaseId()->willReturn('block_plugin_id');
    $block->getDerivativeId()->willReturn(NULL);
    
Home | Imprint | This part of the site doesn't use cookies.