Prophet example

$entity->save();

    static::assertEquals($view_label_access_result$this->accessControlHandler->access($entity, 'view label', $user, TRUE));
    static::assertEquals($view_access_result$this->accessControlHandler->access($entity, 'view', $user, TRUE));
    static::assertEquals($update_access_result$this->accessControlHandler->access($entity, 'update', $user, TRUE));
    static::assertEquals($delete_access_result$this->accessControlHandler->access($entity, 'delete', $user, TRUE));
    static::assertEquals($create_access_result$this->accessControlHandler->createAccess(NULL, $user[], TRUE));
  }

  public function testAccessProvider() {
    $c = new ContainerBuilder();
    $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
    $cache_contexts_manager->reveal();
    $c->set('cache_contexts_manager', $cache_contexts_manager);
    \Drupal::setContainer($c);

    return [
      'permissionless + unlocked' => [
        'permissionless',
        'unlocked',
        AccessResult::allowed(),
        AccessResult::neutral()->addCacheContexts(['user.permissions'])->setReason("The 'administer site configuration' permission is required."),
        


    $this->assertEquals($result$chained_placeholder_strategy->processPlaceholders($placeholders));
  }

  /** * Provides a list of render strategies, placeholders and results. * * @return array */
  public static function providerProcessPlaceholders() {
    $prophet = new Prophet();
    $data = [];

    // 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');
    
$this->renderer->expects($this->any())
      ->method('render')
      ->with($result += ['#printed' => FALSE])
      ->willReturn('Rendered output');

    $this->assertEquals('Rendered output', $this->systemUnderTest->renderVar($input));
  }

  public static function providerTestRenderVar() {
    $data = [];

    $renderable = (new Prophet())->prophesize(RenderableInterface::class);
    $render_array = ['#type' => 'test', '#var' => 'giraffe'];
    $renderable->toRenderable()->willReturn($render_array);
    $data['renderable'] = [$render_array$renderable->reveal()];

    return $data;
  }

  /** * @covers ::escapeFilter * @covers ::bubbleArgMetadata */
  
'configurator' => [new Reference('bar'), 'configureService'],
        'configurator_expected' => [static::getServiceCall('bar'), 'configureService'],
      ] + $base_service_definition;

      $services_provided = [];
      $services_provided[] = [
        [],
        [],
      ];

      foreach ($service_definitions as $service_definition) {
        $definition = (new Prophet())->prophesize('\Symfony\Component\DependencyInjection\Definition');
        $definition->getClass()->willReturn($service_definition['class']);
        $definition->isPublic()->willReturn($service_definition['public']);
        $definition->getFile()->willReturn($service_definition['file']);
        $definition->isSynthetic()->willReturn($service_definition['synthetic']);
        $definition->isLazy()->willReturn($service_definition['lazy']);
        $definition->getArguments()->willReturn($service_definition['arguments']);
        $definition->getProperties()->willReturn($service_definition['properties']);
        $definition->getMethodCalls()->willReturn($service_definition['calls']);
        $definition->isShared()->willReturn($service_definition['shared']);
        $definition->getDecoratedService()->willReturn(NULL);
        $definition->getFactory()->willReturn($service_definition['factory']);
        
$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(),
    ];
    
$plugin->getPluginDefinition()->willReturn($definition);

    $test_class->calculatePluginDependencies($plugin->reveal());
    $this->assertEquals($expected$test_class->getDependencies());
  }

  /** * 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,
      [
public static function providerTestCreate() {
    $data = [];
    $data[] = ['', '', FALSE];
    // Certain tags are filtered.     $data[] = ['<script>teststring</script>', 'teststring', TRUE];
    // Certain tags are not filtered.     $data[] = ['<em>teststring</em>', '<em>teststring</em>', TRUE];
    // HTML will be normalized.     $data[] = ['<em>teststring', '<em>teststring</em>', TRUE];

    // Even safe strings will be escaped.     $safe_string = (new Prophet())->prophesize(MarkupInterface::class);
    $safe_string->__toString()->willReturn('<script>teststring</script>');
    $data[] = [$safe_string->reveal(), 'teststring', TRUE];

    return $data;
  }

  /** * @covers ::displayAllowedTags */
  public function testdisplayAllowedTags() {
    $expected = '<a> <b> <big> <code> <del> <em> <i> <ins> <pre> <q> <small> <span> <strong> <sub> <sup> <tt> <ol> <ul> <li> <p> <br> <img>';

    
public function testNonHtmlResponse($response_class) {
    $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class));

    $non_html_response = new $response_class();
    $this->expectException(\AssertionError::class);
    $big_pipe_response_attachments_processor->processAttachments($non_html_response);
  }

  public static function nonHtmlResponseProvider() {
    return [
      'AjaxResponse, which implements AttachmentsInterface' => [AjaxResponse::class],
      'A dummy that implements AttachmentsInterface' => [get_class((new Prophet())->prophesize(AttachmentsInterface::class)->reveal())],
    ];
  }

  /** * @covers ::processAttachments * * @dataProvider attachmentsProvider */
  public function testHtmlResponse(array $attachments) {
    $big_pipe_response = new BigPipeResponse(new HtmlResponse('original'));
    $big_pipe_response->setAttachments($attachments);

    
if ($field_storage_definition) {
        $this->entityFieldManager->getFieldStorageDefinitions('the_bundle_entity_type_id')
          ->willReturn(['id' => $field_storage_definition]);
      }
    }

    $route = $this->routeProvider->getAddFormRoute($entity_type);
    $this->assertEquals($expected$route);
  }

  public static function providerTestGetAddFormRoute() {
    $prophet = new Prophet();
    $data = [];

    $entity_type1 = static::getEntityType();
    $entity_type1->hasLinkTemplate('add-form')->willReturn(FALSE);

    $data['no_add_form_link_template'] = [NULL, $entity_type1->reveal()];

    $entity_type2 = static::getEntityType();
    $entity_type2->getBundleEntityType()->willReturn(NULL);
    $entity_type2->hasLinkTemplate('add-form')->willReturn(TRUE);
    $entity_type2->id()->willReturn('the_entity_type_id');
    
\Drupal::state()->set('workflow_type_test.required_states', array_filter($states_to_create));
    $this->assertEquals($result$this->accessControlHandler->access($workflow$operation$this->{$user}, TRUE));
  }

  /** * Data provider for ::testCheckAccess. * * @return array */
  public function checkAccessProvider() {
    $container = new ContainerBuilder();
    $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
    $cache_contexts_manager->reveal();
    $container->set('cache_contexts_manager', $cache_contexts_manager);
    \Drupal::setContainer($container);

    return [
      'Admin view' => [
        'adminUser',
        'view',
        AccessResult::allowed()->addCacheContexts(['user.permissions']),
      ],
      


    $validator = $this->createValidator($is_admin);
    $validator->initialize($context->reveal());
    $validator->validate($items$constraint);
  }

  /** * Data provider for ::testValidate(). */
  public static function providerTestValidate() {
    $prophet = new Prophet();
    $cases = [];

    // Case 1: Empty user should be ignored.     $items = $prophet->prophesize(FieldItemListInterface::class);
    $items->getEntity()->willReturn(NULL)->shouldBeCalledTimes(1);
    $cases['Empty user should be ignored'] = [$items->reveal(), FALSE];

    // Case 2: New users without an email should add a violation.     $items = $prophet->prophesize(FieldItemListInterface::class);
    $account = $prophet->prophesize(UserInterface::class);
    $account->isNew()->willReturn(TRUE);
    
$data[] = [$url['alias' => TRUE]$url_without_alias, '/test-path', clone $url_without_alias, '<a href="/test-path">value</a>'];

    // Language flag.     $language = new Language(['id' => 'fr']);
    $url = Url::fromRoute('test_route');
    $url_with_language = Url::fromRoute('test_route');
    $options = ['language' => $language] + static::DEFAULT_URL_OPTIONS;
    $url_with_language->setOptions($options);
    $data[] = [$url['language' => $language]$url_with_language, '/fr/test-path', clone $url_with_language, '<a href="/fr/test-path" hreflang="fr">value</a>'];

    // Entity flag.     $entity = (new Prophet())->prophesize(EntityInterface::class)->reveal();
    $url = Url::fromRoute('test_route');
    $url_with_entity = Url::fromRoute('test_route');
    $options = ['entity' => $entity] + static::DEFAULT_URL_OPTIONS;
    $url_with_entity->setOptions($options);
    $data[] = [$url['entity' => $entity]$url_with_entity, '/test-path', clone $url_with_entity, '<a href="/test-path">value</a>'];

    // Test entity_type flag.     $entity_type_id = 'node';
    $url = Url::fromRoute('test_route');
    $url_with_entity_type = Url::fromRoute('test_route');
    $options = ['entity_type' => $entity_type_id] + static::DEFAULT_URL_OPTIONS;
    
/** * @coversDefaultClass \Drupal\layout_builder\LayoutEntityHelperTrait * * @group layout_builder */
class LayoutEntityHelperTraitTest extends UnitTestCase {

  /** * Data provider method for tests that need sections with inline blocks. */
  public static function providerSectionsWithInlineComponents() {
    $prophet = new Prophet();
    $components = [];

    // Ensure a non-derivative component is not returned.     $non_derivative_component = $prophet->prophesize(SectionComponent::class);
    $non_derivative_component->getPlugin()->willReturn($prophet->prophesize(PluginInspectionInterface::class)->reveal());
    $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');
    

  public function testRenderFromHtml($expected$string$args = []) {
    $markup = new FormattableMarkup($string$args);
    $output = PlainTextOutput::renderFromHtml($markup);
    $this->assertSame($expected$output);
  }

  /** * Data provider for ::testRenderFromHtml() */
  public static function providerRenderFromHtml() {
    $prophet = new Prophet();
    $data = [];

    $data['simple-text'] = ['Giraffes and wombats', 'Giraffes and wombats'];
    $data['simple-html'] = ['Giraffes and wombats', '<a href="/muh">Giraffes</a> and <strong>wombats</strong>'];
    $data['html-with-quote'] = ['Giraffes and quote"s', '<a href="/muh">Giraffes</a> and <strong>quote"s</strong>'];

    $expected = 'The <em> tag makes your text look like "this".';
    $string = 'The &lt;em&gt; tag makes your text look like <em>"this"</em>.';
    $data['escaped-html-with-quotes'] = [$expected$string];

    $safe_string = $prophet->prophesize(MarkupInterface::class);
    
->willReturn([]);
      $map[] = [$plugin_id[]$plugin];
    }
    $this->factory->expects($this->any())
      ->method('createInstance')
      ->willReturnMap($map);

    $this->assertEquals($expected_actions$this->localActionManager->getActionsForRoute($route_appears));
  }

  public static function getActionsForRouteProvider() {
    $cache_contexts_manager = (new Prophet())->prophesize(CacheContextsManager::class);
    $cache_contexts_manager->assertValidTokens(Argument::any())
      ->willReturn(TRUE);

    $container = new Container();
    $container->set('cache_contexts_manager', $cache_contexts_manager->reveal());
    \Drupal::setContainer($container);

    // Single available and single expected plugins.     $data[] = [
      'test_route',
      [
        
Home | Imprint | This part of the site doesn't use cookies.