will example

parent::setUp();

    $this->plugin = new FileField([], 'file', []);

    $migration = $this->prophesize(MigrationInterface::class);

    // The plugin's defineValueProcessPipeline() method will call     // mergeProcessOfProperty() and return nothing. So, in order to examine the     // process pipeline created by the plugin, we need to ensure that     // getProcess() always returns the last input to mergeProcessOfProperty().     $migration->mergeProcessOfProperty(Argument::type('string'), Argument::type('array'))
      ->will(function D$arguments) use ($migration) {
        $migration->getProcess()->willReturn($arguments[1]);
      });
    $this->migration = $migration->reveal();
  }

  /** * @covers ::defineValueProcessPipeline */
  public function testDefineValueProcessPipeline($method = 'defineValueProcessPipeline') {
    $this->plugin->$method($this->migration, 'field_name', []);

    
public function testHtmlResponse(array $attachments) {
    $big_pipe_response = new BigPipeResponse(new HtmlResponse('original'));
    $big_pipe_response->setAttachments($attachments);

    // This mock is the main expectation of this test: verify that the decorated     // service (that is this mock) never receives BigPipe placeholder     // attachments, because it doesn't know (nor should it) how to handle them.     $html_response_attachments_processor = $this->prophesize(AttachmentsResponseProcessorInterface::class);
    $html_response_attachments_processor->processAttachments(Argument::that(function D$response) {
      return $response instanceof HtmlResponse && empty(array_intersect(['big_pipe_placeholders', 'big_pipe_nojs_placeholders']array_keys($response->getAttachments())));
    }))
      ->will(function D$args) {
        /** @var \Symfony\Component\HttpFoundation\Response|\Drupal\Core\Render\AttachmentsInterface $response */
        $response = $args[0];
        // Simulate its actual behavior.         $attachments = array_diff_key($response->getAttachments()['html_response_attachment_placeholders' => TRUE]);
        $response->setContent('processed');
        $response->setAttachments($attachments);
        return $response;
      })
      ->shouldBeCalled();

    $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($html_response_attachments_processor);
    

        $amqpConnection = $this->createMock(\AMQPConnection::class);
        $amqpChannel = $this->createMock(\AMQPChannel::class);
        $amqpExchange = $this->createMock(\AMQPExchange::class);
        $amqpQueue0 = $this->createMock(\AMQPQueue::class);
        $amqpQueue1 = $this->createMock(\AMQPQueue::class);

        $factory = $this->createMock(AmqpFactory::class);
        $factory->method('createConnection')->willReturn($amqpConnection);
        $factory->method('createChannel')->willReturn($amqpChannel);
        $factory->method('createExchange')->willReturn($amqpExchange);
        $factory->method('createQueue')->will($this->onConsecutiveCalls($amqpQueue0$amqpQueue1));

        $amqpExchange->expects($this->once())->method('declareExchange');
        $amqpExchange->expects($this->once())->method('publish')->with('body', 'routing_key', \AMQP_NOPARAM, ['headers' => [], 'delivery_mode' => 2, 'timestamp' => time()]);
        $amqpQueue0->expects($this->once())->method('declareQueue');
        $amqpQueue0->expects($this->exactly(2))->method('bind')
            ->willReturnCallback(function D...$args) {
                static $series = [
                    [self::DEFAULT_EXCHANGE_NAME, 'binding_key0', []],
                    [self::DEFAULT_EXCHANGE_NAME, 'binding_key1', []],
                ];

                
parent::setUp();

    $this->plugin = new TextField([], 'text', []);

    $migration = $this->prophesize(MigrationInterface::class);

    // The plugin's defineValueProcessPipeline() method will call     // setProcessOfProperty() and return nothing. So, in order to examine the     // process pipeline created by the plugin, we need to ensure that     // getProcess() always returns the last input to setProcessOfProperty().     $migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
      ->will(function D$arguments) use ($migration) {
        $migration->getProcess()->willReturn($arguments[1]);
      });

    $this->migration = $migration->reveal();
  }

  /** * @covers ::defineValueProcessPipeline */
  public function testFilteredTextValueProcessPipeline() {
    $field_info = [
      

  public function testGenerateExternal() {
    $this->urlAssembler->expects($this->once())
      ->method('assemble')
      ->with('https://www.drupal.org', ['set_active_class' => TRUE, 'external' => TRUE] + $this->defaultOptions)
      ->will($this->returnArgument(0));

    $this->moduleHandler->expects($this->once())
      ->method('alter')
      ->with('link', $this->isType('array'));

    $this->urlAssembler->expects($this->once())
      ->method('assemble')
      ->with('https://www.drupal.org', ['set_active_class' => TRUE, 'external' => TRUE] + $this->defaultOptions)
      ->willReturnArgument(0);

    $url = Url::fromUri('https://www.drupal.org');
    
    $this->assertTrue($module_handler->hasImplementations('hook'));
  }

  /** * Tests getImplementations. * * @covers ::invokeAllWith */
  public function testCachedGetImplementations() {
    $this->cacheBackend->expects($this->exactly(1))
      ->method('get')
      ->will($this->onConsecutiveCalls(
        (object) ['data' => ['hook' => ['module_handler_test' => 'test']]]
      ));

    // Ensure buildImplementationInfo doesn't get called and that we work off cached results.     $module_handler = $this->getMockBuilder(ModuleHandler::class)
      ->setConstructorArgs([
        $this->root, [
          'module_handler_test' => [
            'type' => 'module',
            'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml',
            'filename' => 'module_handler_test.module',
          ],
$entity->getTargetEntityTypeId()->willReturn('entity_test_with_bundle');
    $entity->getTargetBundle()->willReturn('target_bundle');

    // An initially hidden field, with a submitted region change.     $entity->getComponent('new_field_mismatch_type_visible')->willReturn([]);
    $field_values['new_field_mismatch_type_visible'] = [
      'weight' => 0,
      'type' => 'textfield',
      'region' => 'hidden',
    ];
    $entity->removeComponent('new_field_mismatch_type_visible')
      ->will(function Darray $args) use ($entity) {
        // On subsequent calls, getComponent() will return an empty array.         $entity->getComponent($args[0])->willReturn([]);
      })
      ->shouldBeCalled();

    // An initially visible field, with identical submitted values.     $entity->getComponent('field_visible_no_changes')
      ->willReturn([
        'weight' => 0,
        'type' => 'textfield',
        'region' => 'content',
      ]);

        [],
        $definition_save_1['definitions'],
        $definition_save_1['definitions'],
      );
    $config->expects($this->exactly(2))
      ->method('set')
      ->withConsecutive(
        ['definitions', $definition_save_1['definitions']],
        ['definitions', $definitions_save_2['definitions']],
      )
      ->will($this->returnSelf());
    $config->expects($this->exactly(2))
      ->method('save');

    $config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
    $config_factory->expects($this->once())
      ->method('getEditable')
      ->willReturn($config);

    $static_override = new StaticMenuLinkOverrides($config_factory);

    $static_override->saveOverride('test1', ['parent' => 'test0']);
    

  public function testBuildWithException($exception_class$exception_argument) {
    $this->context->expects($this->once())
      ->method('getPathInfo')
      ->willReturn('/example/bar');
    $this->setupStubPathProcessor();

    $this->requestMatcher->expects($this->any())
      ->method('matchRequest')
      ->will($this->throwException(new $exception_class($exception_argument)));

    $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface'));

    // No path matched, though at least the frontpage is displayed.     $this->assertEquals([0 => new Link('Home', new Url('<front>'))]$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent']$breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing([]$breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
  }

  /** * Provides exception types for testBuildWithException. * * @return array * The list of exception test cases. * * @see \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithException() */
public function testDispatchOutOfAnotherHandlerDispatchesAndRemoveStamp()
    {
        $event = new DummyEvent('First event');

        $middleware = new DispatchAfterCurrentBusMiddleware();
        $handlingMiddleware = $this->createMock(MiddlewareInterface::class);

        $handlingMiddleware
            ->method('handle')
            ->with($this->expectHandledMessage($event))
            ->will($this->willHandleMessage());

        $eventBus = new MessageBus([
            $middleware,
            $handlingMiddleware,
        ]);

        $enveloppe = $eventBus->dispatch($event[new DispatchAfterCurrentBusStamp()]);

        self::assertNull($enveloppe->last(DispatchAfterCurrentBusStamp::class));
    }

    
$resource_type_repository
      ->getByTypeName(Argument::any())
      ->willReturn(new ResourceType('node', 'article', NULL));

    $entity_storage = $this->prophesize(EntityStorageInterface::class);
    $self = $this;
    $uuid_to_id = [
      '76dd5c18-ea1b-4150-9e75-b21958a2b836' => 1,
      'fcce1b61-258e-4054-ae36-244d25a9e04c' => 2,
    ];
    $entity_storage->loadByProperties(Argument::type('array'))
      ->will(function D$args) use ($self$uuid_to_id) {
        $result = [];
        foreach ($args[0]['uuid'] as $uuid) {
          $entity = $self->prophesize(EntityInterface::class);
          $entity->uuid()->willReturn($uuid);
          $entity->id()->willReturn($uuid_to_id[$uuid]);
          $result[$uuid] = $entity->reveal();
        }
        return $result;
      });
    $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager->getStorage('node')->willReturn($entity_storage->reveal());
    
parent::setUp();

    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
      'Drupal\\Tests\\Core\\Plugin\\Fixtures' => $this->root . '/core/tests/Drupal/Tests/Core/Plugin/Fixtures',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    $string_translation = new TranslationManager(new LanguageDefault([]));

    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $type_data_manager);
    
parent::setUp();

    $namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
      'Drupal\\Core\\Entity' => $this->root . '/core/lib/Drupal/Core/Entity',
    ]);
    $cache_backend = new NullBackend('cache');
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);

    $class_resolver = $this->prophesize(ClassResolverInterface::class);
    $class_resolver->getInstanceFromDefinition(Argument::type('string'))->will(function D$arguments) {
      $class_name = $arguments[0];
      return new $class_name();
    });

    $type_data_manager = new TypedDataManager($namespaces$cache_backend$module_handler->reveal()$class_resolver->reveal());
    $type_data_manager->setValidationConstraintManager(new ConstraintManager($namespaces$cache_backend$module_handler->reveal()));

    $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
    $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);

    $string_translation = new TranslationManager(new LanguageDefault([]));

    
->willThrowException($exception);
    $linkItem->expects($this->any())
      ->method('__get')
      ->with('options')
      ->willReturn([]);
    $fieldDefinition = $this->createMock(FieldDefinitionInterface::class);
    $fieldList = new FieldItemList($fieldDefinition, '', $linkItem);

    $fieldTypePluginManager = $this->createMock(FieldTypePluginManagerInterface::class);
    $fieldTypePluginManager->expects($this->once())
      ->method('createFieldItem')
      ->will($this->returnValue($linkItem));
    $urlGenerator = $this->createMock(UrlGenerator::class);
    $urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with('<none>', [][], FALSE)
      ->willReturn('http://example.com');
    $container = new ContainerBuilder();
    $container->set('plugin.manager.field.field_type', $fieldTypePluginManager);
    $container->set('url_generator', $urlGenerator);
    \Drupal::setContainer($container);
    $fieldList->setValue([$linkItem]);

    
      // 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);
        }
      });
Home | Imprint | This part of the site doesn't use cookies.