assertEqualsCanonicalizing example


  public function testContextBubblingEdgeCases(array $element, array $expected_top_level_contexts, array $expected_cache_items) {
    $this->setUpRequest();
    $this->setupMemoryCache();
    $this->cacheContextsManager->expects($this->any())
      ->method('convertTokensToKeys')
      ->willReturnArgument(0);

    $this->renderer->renderRoot($element);

    $this->assertEqualsCanonicalizing($expected_top_level_contexts$element['#cache']['contexts'], 'Expected cache contexts found.');
    foreach ($expected_cache_items as $cid => $expected_cache_item) {
      $this->assertRenderCacheItem($cid$expected_cache_item);
    }
  }

  public function providerTestContextBubblingEdgeCases() {
    $data = [];

    // Cache contexts of inaccessible children aren't bubbled (because those     // children are not rendered at all).     $test_element = [
      

  public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected) {
    $cache_contexts_manager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
      ->disableOriginalConstructor()
      ->getMock();
    $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);

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

    $this->assertEqualsCanonicalizing($expected$a->merge($b));
  }

  /** * @covers ::addCacheableDependency * @dataProvider providerTestMerge * * This only tests at a high level, because it reuses existing logic. Detailed * tests exist for the existing logic: * * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeTags() * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges() * @see \Drupal\Tests\Core\Cache\CacheContextsTest */
foreach ($cases as $case) {
      [$title$uri$options$expected_cacheability$expected_attachments] = $case;
      $expected_cacheability['contexts'] = Cache::mergeContexts($expected_cacheability['contexts']['languages:language_interface', 'theme', 'user.permissions']);
      $link = [
        '#type' => 'link',
        '#title' => $title,
        '#options' => $options,
        '#url' => Url::fromUri($uri),
      ];
      \Drupal::service('renderer')->renderRoot($link);
      $this->assertEqualsCanonicalizing($expected_cacheability$link['#cache']);
      $this->assertEquals($expected_attachments$link['#attached']);
    }
  }

  /** * Tests that default and custom attributes are handled correctly on links. */
  public function testLinkAttributes() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');

    

    $this->entity->set('field_test_text', $value)->save();

    $this->initAuthentication();
    $url = $this->getEntityResourceUrl();
    $url->setOption('query', ['_format' => static::$format]);
    $request_options = $this->getAuthenticationRequestOptions('GET');
    $this->provisionEntityResource();
    $this->setUpAuthorization('GET');
    $response = $this->request('GET', $url$request_options);
    $expected_cache_tags = Cache::mergeTags($expected_cache_tags, parent::getExpectedCacheTags());
    $this->assertEqualsCanonicalizing($expected_cache_tagsexplode(' ', $response->getHeader('X-Drupal-Cache-Tags')[0]));
  }

  public function providerTestGetWithFormat() {
    return [
      'format specified (different from fallback format)' => [
        'pablo',
        ['config:filter.format.pablo'],
      ],
      'format specified (happens to be the same as fallback format)' => [
        'plain_text',
        ['config:filter.format.plain_text'],
      ],
// Get the response.     $resource_type = $this->container->get('jsonapi.resource_type.repository')->get('node', 'article');
    $response = $entity_resource->getCollection($resource_type$request);

    // Assertions.     $this->assertInstanceOf(CacheableResourceResponse::class$response);
    $this->assertInstanceOf(JsonApiDocumentTopLevel::class$response->getResponseData());
    $this->assertInstanceOf(Data::class$response->getResponseData()->getData());
    $data = $response->getResponseData()->getData();
    $this->assertCount(1, $data);
    $this->assertEquals($this->node2->uuid()$data->toArray()[0]->getId());
    $this->assertEqualsCanonicalizing(['node:2', 'node_list']$response->getCacheableMetadata()->getCacheTags());
  }

  /** * @covers ::getCollection */
  public function testGetEmptyCollection() {
    $request = Request::create('/jsonapi/node/article');
    $request->query = new InputBag(['filter' => ['id' => 'invalid']]);

    // Get the response.     $resource_type = new ResourceType('node', 'article', NULL);
    
$field = $this->assertSession()->selectExists($name);
    $options = $field->findAll('xpath', 'option');
    $optgroups = $field->findAll('xpath', 'optgroup');
    $nested_options = [];
    foreach ($optgroups as $optgroup) {
      $nested_options[] = $optgroup->findAll('xpath', 'option');
    }
    $options = array_merge($options, ...$nested_options);
    array_walk($optionsfunction DNodeElement &$option) {
      $option = $option->getAttribute('value');
    });
    $this->assertEqualsCanonicalizing($expected_options$options);
  }

}

  public function testBuildOnFrontpage() {
    $this->pathMatcher->expects($this->once())
      ->method('isFrontPage')
      ->willReturn(TRUE);

    $breadcrumb = $this->builder->build($this->createMock('Drupal\Core\Routing\RouteMatchInterface'));
    $this->assertEquals([]$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing(['url.path.is_front', 'url.path.parent']$breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing([]$breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
  }

  /** * Tests the build method with one path element. * * @covers ::build */
  public function testBuildWithOnePathElement() {
    $this->context->expects($this->once())
      


  /** * Ensures that the expected cacheability metadata is applied. * * @param array $build * The render array * * @internal */
  protected function assertCacheabilityMetadata(array $build): void {
    $this->assertEqualsCanonicalizing([
      'config:core.entity_view_display.entity_test.entity_test.foobar',
      'config:views.view.test_field_entity_test_rendered',
      'entity_test:1',
      'entity_test:2',
      'entity_test:3',
      'entity_test_list',
      'entity_test_view',
    ]$build['#cache']['tags']);

    $this->assertEqualsCanonicalizing([
      'entity_test_view_grants',
      
$this->routeMatch->expects($this->any())
      ->method('getRouteName')
      ->willReturn('menu_local_task_test_tasks_view');
    $this->routeMatch->expects($this->any())
      ->method('getRawParameters')
      ->willReturn(new InputBag());

    $cacheability = new CacheableMetadata();
    $this->manager->getTasksBuild('menu_local_task_test_tasks_view', $cacheability);

    // Ensure that all cacheability metadata is merged together.     $this->assertEqualsCanonicalizing(['tag.example1', 'tag.example2']$cacheability->getCacheTags());
    $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);
      
/** * Tests that the correct cache contexts are set. */
  public function testCacheContexts() {
    /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
    $list_builder = $this->container->get('entity_type.manager')->getListBuilder('node');

    $build = $list_builder->render();
    $this->container->get('renderer')->renderRoot($build);

    $this->assertEqualsCanonicalizing(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions']$build['#cache']['contexts']);
  }

}

  public function testBasics(array $embed_attributes$expected_view_mode, array $expected_attributes, CacheableMetadata $expected_cacheability) {
    $content = $this->createEmbedCode($embed_attributes);

    $result = $this->applyFilter($content);

    $this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="' . $expected_view_mode . '"]'));
    $this->assertHasAttributes($this->cssSelect('div[data-media-embed-test-view-mode="' . $expected_view_mode . '"]')[0]$expected_attributes);
    $this->assertEqualsCanonicalizing($expected_cacheability->getCacheTags()$result->getCacheTags());
    $this->assertEqualsCanonicalizing($expected_cacheability->getCacheContexts()$result->getCacheContexts());
    $this->assertSame($expected_cacheability->getCacheMaxAge()$result->getCacheMaxAge());
    $this->assertSame(['library']array_keys($result->getAttachments()));
    $this->assertSame(['media/filter.caption']$result->getAttachments()['library']);
  }

  /** * Data provider for testBasics(). */
  public function providerTestBasics() {
    $default_cacheability = (new CacheableMetadata())
      
$menu_link_content = MenuLinkContent::create([
        'link' => ['uri' => $expectation['uri']],
        'menu_name' => 'tools',
        'title' => 'Link test',
      ]);
      $menu_link_content->save();
      $tree = $menu_tree->load('tools', new MenuTreeParameters());
      $build = $menu_tree->build($tree);
      $renderer->renderRoot($build);

      $expected_cacheability = $default_menu_cacheability->merge($expectation['cacheability']);
      $this->assertEqualsCanonicalizing($expected_cacheability, BubbleableMetadata::createFromRenderArray($build));

      $menu_link_content->delete();
    }

    // Now test them all together in one menu: the rendered menu's cacheability     // metadata should be the combination of the cacheability of all links, and     // thus of all tested outbound path & route processors.     $expected_cacheability = new BubbleableMetadata();
    foreach ($test_cases as $expectation) {
      $menu_link_content = MenuLinkContent::create([
        'link' => ['uri' => $expectation['uri']],
        
$browser->request('PATCH', $this->getRootProxyUrl('/switch-customer')[
            'salesChannelId' => $salesChannel['id'],
            'customerId' => $customerId,
            'permissions' => $permissions,
        ]);

        $response = $this->getBrowser()->getResponse();

        // assert permissions exist in payload         $payload = $this->contextPersister->load($response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN, '')$salesChannel['id']);
        static::assertArrayHasKey('permissions', $payload);
        static::assertEqualsCanonicalizing(\array_fill_keys($permissions, true)$payload['permissions']);
    }

    public function testModifyShippingCostsWithoutChannelId(): void
    {
        $this->getBrowser()->request('PATCH', $this->getRootProxyUrl('/modify-shipping-costs')[
            'shippingCosts' => [
                'unitPrice' => 20,
                'totalPrice' => 20,
            ],
        ]);

        
// Purge the field data.     field_purge_batch(1000);

    $all_modules = \Drupal::service('extension.list.module')->getList();
    $database_module = \Drupal::service('database')->getProvider();
    $expected_modules = ['path_alias', 'system', 'user', 'standard', $database_module];

    // Ensure that only core required modules and the install profile can not be uninstalled.     $validation_reasons = \Drupal::service('module_installer')->validateUninstall(array_keys($all_modules));
    $validation_modules = array_keys($validation_reasons);
    $this->assertEqualsCanonicalizing($expected_modules$validation_modules);

    $modules_to_uninstall = array_filter($all_modulesfunction D$module) {
      // Filter required and not enabled modules.       if (!empty($module->info['required']) || $module->status == FALSE) {
        return FALSE;
      }
      return TRUE;
    });

    // Can not uninstall config and use admin/config/development/configuration!     unset($modules_to_uninstall['config']);

    
->with('node')
      ->willReturn($forum_node);

    // First test.     $expected1 = [
      Link::createFromRoute('Home', '<front>'),
      Link::createFromRoute('Forums', 'forum.index'),
      Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
    ];
    $breadcrumb = $breadcrumb_builder->build($route_match);
    $this->assertEquals($expected1$breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing(['route']$breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing(['taxonomy_term:1', 'taxonomy_vocabulary:5']$breadcrumb->getCacheTags());
    $this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());

    // Second test.     $expected2 = [
      Link::createFromRoute('Home', '<front>'),
      Link::createFromRoute('Forums', 'forum.index'),
      Link::createFromRoute('Something else', 'forum.page', ['taxonomy_term' => 2]),
      Link::createFromRoute('Something', 'forum.page', ['taxonomy_term' => 1]),
    ];
    $breadcrumb = $breadcrumb_builder->build($route_match);
    
Home | Imprint | This part of the site doesn't use cookies.