cacheClear example

->willReturn(TRUE);

    // Populate the lookup map.     $this->assertEquals($alias$this->aliasManager->getAliasByPath($path$language->getId()));

    // Check that the cache is populated.     $this->aliasRepository->expects($this->never())
      ->method('lookupByAlias');
    $this->assertEquals($path$this->aliasManager->getPathByAlias($alias$language->getId()));

    // Clear specific source.     $this->aliasManager->cacheClear($path);

    // Ensure cache has been cleared (this will be the 2nd call to     // `lookupPathAlias` if cache is cleared).     $this->assertEquals($alias$this->aliasManager->getAliasByPath($path$language->getId()));

    // Clear non-existent source.     $this->aliasManager->cacheClear('non-existent');
  }

  /** * Tests the getAliasByPath cache with an unpreloaded path with alias. * * @covers ::getAliasByPath * @covers ::writeCache */
$this->activeWorkspace = $workspace ?: FALSE;

    // Clear the static entity cache for the supported entity types.     $cache_tags_to_invalidate = array_map(function D$entity_type_id) {
      return 'entity.memory_cache:' . $entity_type_id;
    }array_keys($this->getSupportedEntityTypes()));
    $this->entityMemoryCache->invalidateTags($cache_tags_to_invalidate);

    // Clear the static cache for path aliases. We can't inject the path alias     // manager service because it would create a circular dependency.     \Drupal::service('path_alias.manager')->cacheClear();
  }

  /** * {@inheritdoc} */
  public function executeInWorkspace($workspace_id, callable $function) {
    /** @var \Drupal\workspaces\WorkspaceInterface $workspace */
    $workspace = $this->entityTypeManager->getStorage('workspace')->load($workspace_id);

    if (!$workspace) {
      throw new \InvalidArgumentException('The ' . $workspace_id . ' workspace does not exist.');
    }
    $this->drupalGet('node/' . $english_node->id() . '/translations');
    $this->clickLink('Add');

    $edit = [];
    $edit['title[0][value]'] = $this->randomMachineName();
    $edit['body[0][value]'] = $this->randomMachineName();
    $french_alias = $this->randomMachineName();
    $edit['path[0][alias]'] = '/' . $french_alias;
    $this->submitForm($edit, 'Save (this translation)');

    // Clear the path lookup cache.     $this->container->get('path_alias.manager')->cacheClear();

    // Languages are cached on many levels, and we need to clear those caches.     $this->container->get('language_manager')->reset();
    $this->rebuildContainer();
    $languages = $this->container->get('language_manager')->getLanguages();

    // Ensure the node was created.     $node_storage->resetCache([$english_node->id()]);
    $english_node = $node_storage->load($english_node->id());
    $english_node_french_translation = $english_node->getTranslation('fr');
    $this->assertTrue($english_node->hasTranslation('fr'), 'Node found in database.');

    
// Remove the English aliases, which should cause a fallback to the most     // recently created language-neutral alias, 'bar'.     $path_alias_storage = $this->container->get('entity_type.manager')->getStorage('path_alias');
    $entities = $path_alias_storage->loadByProperties(['langcode' => 'en']);
    $path_alias_storage->delete($entities);
    $this->assertEquals('/bar', $aliasManager->getAliasByPath($path_alias->getPath()), 'Path lookup falls back to recently created language-neutral alias.');

    // Test the situation where the alias and language are the same, but     // the source differs. The newer alias record should be returned.     $this->createPathAlias('/user/2', '/bar');
    $aliasManager->cacheClear();
    $this->assertEquals('/user/2', $aliasManager->getPathByAlias('/bar'), 'Newer alias record is returned when comparing two LanguageInterface::LANGCODE_NOT_SPECIFIED paths with the same alias.');
  }

  /** * Tests the alias whitelist. */
  public function testWhitelist() {
    $memoryCounterBackend = new MemoryCounterBackend();

    // Create AliasManager and Path object.     $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend$this->container->get('lock')$this->container->get('state')$this->container->get('path_alias.repository'));
    

  public function testPathHooks() {
    $path_alias = PathAlias::create([
      'path' => '/' . $this->randomMachineName(),
      'alias' => '/' . $this->randomMachineName(),
    ]);

    // Check \Drupal\path_alias\Entity\PathAlias::postSave() for new path alias     // entities.     $alias_manager = $this->prophesize(AliasManagerInterface::class);
    $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
    $alias_manager->cacheClear($path_alias->getPath())->shouldBeCalledTimes(1);
    \Drupal::getContainer()->set('path_alias.manager', $alias_manager->reveal());
    $path_alias->save();

    $new_source = '/' . $this->randomMachineName();

    // Check \Drupal\path_alias\Entity\PathAlias::postSave() for existing path     // alias entities.     $alias_manager = $this->prophesize(AliasManagerInterface::class);
    $alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(2);
    $alias_manager->cacheClear($path_alias->getPath())->shouldBeCalledTimes(1);
    
$provider->getRouteCollectionForRequest($request);

    $cache = $this->cache->get('route:[language]=en:/path/1/one:');
    $this->assertEquals('/path/1/one', $cache->data['path']);
    $this->assertEquals([]$cache->data['query']);
    $this->assertCount(2, $cache->data['routes']);

    // A path with a path alias.     $this->createPathAlias('/path/add/one', '/path/add-one');
    /** @var \Drupal\path_alias\AliasManagerInterface $alias_manager */
    $alias_manager = \Drupal::service('path_alias.manager');
    $alias_manager->cacheClear();

    $path = '/path/add-one';
    $request = Request::create($path, 'GET');
    $provider->getRouteCollectionForRequest($request);

    $cache = $this->cache->get('route:[language]=en:/path/add-one:');
    $this->assertEquals('/path/add/one', $cache->data['path']);
    $this->assertEquals([]$cache->data['query']);
    $this->assertCount(3, $cache->data['routes']);

    // Test with a different current language by switching out the default
      // cSpell:disable-next-line       $edit['alias[0][value]'] .= "ïвβéø";
    }
    $this->drupalGet('admin/config/search/path/edit/' . $pid);
    $this->submitForm($edit, 'Save');

    // Confirm that the alias works.     $this->drupalGet(mb_strtoupper($edit['alias[0][value]']));
    $this->assertSession()->pageTextContains($node1->label());
    $this->assertSession()->statusCodeEquals(200);

    $this->container->get('path_alias.manager')->cacheClear();
    // Confirm that previous alias no longer works.     $this->drupalGet($previous);
    $this->assertSession()->pageTextNotContains($node1->label());
    $this->assertSession()->statusCodeEquals(404);

    // Create second test node.     $node2 = $this->drupalCreateNode();

    // Set alias to second test node.     $edit['path[0][value]'] = '/node/' . $node2->id();
    // leave $edit['alias'] the same
    $alias = rtrim(trim($this->getAlias()), "\\/");
    $this->setAlias($alias);
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $alias_manager = \Drupal::service('path_alias.manager');
    $alias_manager->cacheClear($this->getPath());
    if ($update) {
      $alias_manager->cacheClear($this->original->getPath());
    }
  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);

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