reveal example

// Empty placeholders.     $data['empty placeholders'] = [[][][]];

    // Placeholder removing strategy.     $placeholders = [
      'remove-me' => ['#markup' => 'I-am-a-llama-that-will-be-removed-sad-face.'],
    ];

    $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface');
    $prophecy->processPlaceholders($placeholders)->willReturn([]);
    $dev_null_strategy = $prophecy->reveal();

    $data['placeholder removing strategy'] = [[$dev_null_strategy]$placeholders[]];

    // Fake Single Flush strategy.     $placeholders = [
      '67890' => ['#markup' => 'special-placeholder'],
    ];

    $prophecy = $prophet->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface');
    $prophecy->processPlaceholders($placeholders)->willReturn($placeholders);
    $single_flush_strategy = $prophecy->reveal();

    
$this->themeHandler->themeExists('theme_a')->willReturn(TRUE);
    $this->themeHandler->themeExists('core')->willReturn(FALSE);
    $this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE);

    $theme_a = new Extension('vfs://root', 'theme', 'themes/theme_a/theme_a.layouts.yml');
    $this->themeHandler->getTheme('theme_a')->willReturn($theme_a);
    $this->themeHandler->getThemeDirectories()->willReturn(['theme_a' => vfsStream::url('root/themes/theme_a')]);

    $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);

    $namespaces = new \ArrayObject(['Drupal\Core' => vfsStream::url('root/core/lib/Drupal/Core')]);
    $this->layoutPluginManager = new LayoutPluginManager($namespaces$this->cacheBackend->reveal()$this->moduleHandler->reveal()$this->themeHandler->reveal());
  }

  /** * @covers ::getDefinitions * @covers ::providerExists */
  public function testGetDefinitions() {
    $expected = [
      'module_a_provided_layout',
      'theme_a_provided_layout',
      'plugin_provided_layout',
    ];

class ExceptionJsonSubscriberTest extends UnitTestCase {

  /** * @covers ::on4xx * @dataProvider providerTestOn4xx */
  public function testOn4xx(HttpExceptionInterface $exception$expected_response_class) {
    $kernel = $this->prophesize(HttpKernelInterface::class);
    $request = Request::create('/test');
    $event = new ExceptionEvent($kernel->reveal()$request, HttpKernelInterface::MAIN_REQUEST, $exception);
    $subscriber = new ExceptionJsonSubscriber();
    $subscriber->on4xx($event);
    $response = $event->getResponse();

    $this->assertInstanceOf($expected_response_class$response);
    $this->assertEquals('{"message":"test message"}', $response->getContent());
    $this->assertEquals(405, $response->getStatusCode());
    $this->assertEquals('POST, PUT', $response->headers->get('Allow'));
    $this->assertEquals('application/json', $response->headers->get('Content-Type'));
  }

  

class TextfieldTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$input) {
    $element = [];
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, Textfield::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [NULL, FALSE];
    $data[] = [NULL, NULL];
    $data[] = ['', ['test']];
    
class DefaultExceptionSubscriberTest extends UnitTestCase {

  /** * @covers ::on4xx */
  public function testOn4xx() {
    $kernel = $this->prophesize(HttpKernelInterface::class);
    $request = Request::create('/test');
    $request->setRequestFormat('json');

    $e = new MethodNotAllowedHttpException(['POST', 'PUT'], 'test message');
    $event = new ExceptionEvent($kernel->reveal()$request, HttpKernelInterface::MAIN_REQUEST, $e);
    $subscriber = new DefaultExceptionSubscriber(new Serializer([][new JsonEncoder()])[]);
    $subscriber->on4xx($event);
    $response = $event->getResponse();

    $this->assertInstanceOf(Response::class$response);
    $this->assertEquals('{"message":"test message"}', $response->getContent());
    $this->assertEquals(405, $response->getStatusCode());
    $this->assertEquals('POST, PUT', $response->headers->get('Allow'));
    $this->assertEquals('application/json', $response->headers->get('Content-Type'));
  }

}

class PasswordConfirmTest extends UnitTestCase {

  /** * @covers ::valueCallback * * @dataProvider providerTestValueCallback */
  public function testValueCallback($expected$element$input) {
    $form_state = $this->prophesize(FormStateInterface::class)->reveal();
    $this->assertSame($expected, PasswordConfirm::valueCallback($element$input$form_state));
  }

  /** * Data provider for testValueCallback(). */
  public function providerTestValueCallback() {
    $data = [];
    $data[] = [['pass1' => '', 'pass2' => ''][], NULL];
    $data[] = [['pass1' => '', 'pass2' => '']['#default_value' => ['pass2' => 'value']], NULL];
    $data[] = [['pass2' => 'value', 'pass1' => '']['#default_value' => ['pass2' => 'value']], FALSE];
    

class StateTest extends UnitTestCase {

  /** * @covers ::__construct * @covers ::id * @covers ::label * @covers ::weight */
  public function testGetters() {
    $state = new State(
      $this->prophesize(WorkflowTypeInterface::class)->reveal(),
      'draft',
      'Draft',
      3
    );
    $this->assertEquals('draft', $state->id());
    $this->assertEquals('Draft', $state->label());
    $this->assertEquals(3, $state->weight());
  }

  /** * @covers ::canTransitionTo */

class AccountProxyTest extends UnitTestCase {

  /** * @covers ::id * @covers ::setInitialAccountId */
  public function testId() {
    $dispatcher = $this->prophesize(EventDispatcherInterface::class);
    $dispatcher->dispatch(Argument::any(), Argument::any())->willReturn(new Event());
    $account_proxy = new AccountProxy($dispatcher->reveal());
    $this->assertSame(0, $account_proxy->id());
    $account_proxy->setInitialAccountId(1);
    $this->assertFalse(\Drupal::hasContainer());
    // If the following call loaded the user entity it would call     // AccountProxy::loadUserEntity() which would fail because the container     // does not exist.     $this->assertSame(1, $account_proxy->id());
    $current_user = $this->prophesize(AccountInterface::class);
    $current_user->id()->willReturn(2);
    $account_proxy->setAccount($current_user->reveal());
    $this->assertSame(2, $account_proxy->id());
  }

  protected function setUp(): void {
    parent::setUp();

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

    $this->entityType = $this->prophesize(EntityTypeInterface::class);
    $this->entityType->getSingularLabel()->willReturn('foo');
    $this->entityType->getPluralLabel()->willReturn('bar');
    $this->storage->getEntityType()->willReturn($this->entityType->reveal());
    $this->storage->getEntityTypeId()->willReturn('foo');
  }

  /** * Tests that revision destination fails for unrevisionable entities. */
  public function testUnrevisionable() {
    $this->entityType->getKey('id')->willReturn('id');
    $this->entityType->getKey('revision')->willReturn('');
    $this->entityFieldManager->getBaseFieldDefinitions('foo')
      ->willReturn([
        

class MigratePostRowSaveEventTest extends EventBaseTest {

  /** * Tests getDestinationIdValues method. * * @covers ::__construct * @covers ::getDestinationIdValues */
  public function testGetDestinationIdValues() {
    $migration = $this->prophesize('\Drupal\migrate\Plugin\MigrationInterface')->reveal();
    $message_service = $this->prophesize('\Drupal\migrate\MigrateMessageInterface')->reveal();
    $row = $this->prophesize('\Drupal\migrate\Row')->reveal();
    $event = new MigratePostRowSaveEvent($migration$message_service$row[1, 2, 3]);
    $this->assertSame([1, 2, 3]$event->getDestinationIdValues());
  }

  /** * Tests getRow method. * * @covers ::__construct * @covers ::getRow */
$objects[$i] = $this->randomObject();
    }

    // Create a key/value collection.     $database = Database::getConnection();
    // Mock the current user service so that isAnonymous returns FALSE.     $current_user = $this->prophesize(AccountProxyInterface::class);
    $factory = new SharedTempStoreFactory(
      new KeyValueExpirableFactory(\Drupal::getContainer()),
      new DatabaseLockBackend($database),
      $this->container->get('request_stack'),
      $current_user->reveal()
    );
    $collection = $this->randomMachineName();

    // Create two mock users.     for ($i = 0; $i <= 1; $i++) {
      $users[$i] = mt_rand(500, 5000000);

      // Storing the SharedTempStore objects in a class member variable causes a       // fatal exception, because in that situation garbage collection is not       // triggered until the test class itself is destructed, after tearDown()       // has deleted the database tables. Store the objects locally instead.
$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));
    assert($response instanceof HtmlResponse);
    $content = $response->getContent();

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

    // Create a container so that the plugin manager and workflow type can be     // mocked.     $container = new ContainerBuilder();
    $workflow_manager = $this->prophesize(WorkflowTypeManager::class);
    $workflow_manager->createInstance('content_moderation', Argument::any())->willReturn(new TestType([], '', []));
    $container->set('plugin.manager.workflows.type', $workflow_manager->reveal());
    \Drupal::setContainer($container);

    $this->workflow = new Workflow(['id' => 'process', 'type' => 'content_moderation'], 'workflow');
    $this->workflow
      ->getTypePlugin()
      ->addState('draft', 'draft')
      ->addState('needs_review', 'needs_review')
      ->addState('published', 'published')
      ->addTransition('draft', 'draft', ['draft'], 'draft')
      ->addTransition('review', 'review', ['draft'], 'needs_review')
      ->addTransition('publish', 'publish', ['needs_review', 'published'], 'published');
  }
$namespaces = new \ArrayObject([
      'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData',
      'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation',
    ]);
    $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())
    );

    $container = TestKernel::setContainerWithKernel();
    $container->set('typed_data_manager', $type_data_manager);
    \Drupal::setContainer($container);
  }

  /** * @covers ::checkRequirements * * @dataProvider providerTestCheckRequirements */


    $field_manager = $this->prophesize(EntityFieldManagerInterface::class);
    $field_definition = $this->prophesize(FieldConfig::class);
    $item_definition = $this->prophesize(FieldItemDataDefinition::class);
    $item_definition->getMainPropertyName()->willReturn('bunny');
    $item_definition->getSetting('target_type')->willReturn('fake_entity_type');
    $item_definition->getSetting('handler_settings')->willReturn([
      'target_bundles' => ['dummy_bundle'],
    ]);
    $field_definition->getItemDefinition()
      ->willReturn($item_definition->reveal());
    $storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
    $storage_definition->isMultiple()->willReturn(TRUE);
    $field_definition->getFieldStorageDefinition()->willReturn($storage_definition->reveal());

    $field_definition2 = $this->prophesize(FieldConfig::class);
    $field_definition2->getItemDefinition()
      ->willReturn($item_definition->reveal());
    $storage_definition2 = $this->prophesize(FieldStorageDefinitionInterface::class);
    $storage_definition2->isMultiple()->willReturn(FALSE);
    $field_definition2->getFieldStorageDefinition()->willReturn($storage_definition2->reveal());

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