コード例 #1
0
 /**
  * Returns the table definition for the URL alias fixtures.
  *
  * @return array
  *   Table definitions.
  */
 public function tableDefinition()
 {
     $tables = array();
     // Prime the drupal_get_filename() cache with the location of the system
     // module as its location is known and shouldn't change.
     // @todo Remove as part of https://www.drupal.org/node/2186491
     drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml');
     module_load_install('system');
     $schema = system_schema();
     $tables['url_alias'] = AliasStorage::schemaDefinition();
     $tables['key_value'] = $schema['key_value'];
     return $tables;
 }
コード例 #2
0
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');

    $this->installConfig('subpathauto');

    // Create the node bundles required for testing.
    $type = NodeType::create([
      'type' => 'page',
      'name' => 'page',
    ]);
    $type->save();

    $this->aliasStorage = $this->container->get('path.alias_storage');
    $this->sut = $this->container->get('path_processor_subpathauto');
    $this->aliasWhiteList = $this->container->get('path.alias_whitelist');

    Node::create(['type' => 'page', 'title' => 'test'])->save();
    $this->aliasStorage->save('/node/1', '/kittens');
    $this->aliasWhiteList->set('node', TRUE);
  }
コード例 #3
0
ファイル: UrlAlias.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $path = $this->aliasStorage->save($row->getDestinationProperty('source'), $row->getDestinationProperty('alias'), $row->getDestinationProperty('langcode'), $old_destination_id_values ? $old_destination_id_values[0] : NULL);
     return array($path['pid']);
 }
コード例 #4
0
ファイル: AliasTest.php プロジェクト: anatalsceo/en-classe
 /**
  * Tests the alias whitelist.
  */
 function testWhitelist()
 {
     // Prepare database table.
     $connection = Database::getConnection();
     $this->fixtures->createTables($connection);
     $memoryCounterBackend = new MemoryCounterBackend('default');
     // Create AliasManager and Path object.
     $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler'));
     $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $aliasStorage);
     $aliasManager = new AliasManager($aliasStorage, $whitelist, $this->container->get('language_manager'), $memoryCounterBackend);
     // No alias for user and admin yet, so should be NULL.
     $this->assertNull($whitelist->get('user'));
     $this->assertNull($whitelist->get('admin'));
     // Non-existing path roots should be NULL too. Use a length of 7 to avoid
     // possible conflict with random aliases below.
     $this->assertNull($whitelist->get($this->randomMachineName()));
     // Add an alias for user/1, user should get whitelisted now.
     $aliasStorage->save('user/1', $this->randomMachineName());
     $aliasManager->cacheClear();
     $this->assertTrue($whitelist->get('user'));
     $this->assertNull($whitelist->get('admin'));
     $this->assertNull($whitelist->get($this->randomMachineName()));
     // Add an alias for admin, both should get whitelisted now.
     $aliasStorage->save('admin/something', $this->randomMachineName());
     $aliasManager->cacheClear();
     $this->assertTrue($whitelist->get('user'));
     $this->assertTrue($whitelist->get('admin'));
     $this->assertNull($whitelist->get($this->randomMachineName()));
     // Remove the user alias again, whitelist entry should be removed.
     $aliasStorage->delete(array('source' => 'user/1'));
     $aliasManager->cacheClear();
     $this->assertNull($whitelist->get('user'));
     $this->assertTrue($whitelist->get('admin'));
     $this->assertNull($whitelist->get($this->randomMachineName()));
     // Destruct the whitelist so that the caches are written.
     $whitelist->destruct();
     $this->assertEqual($memoryCounterBackend->getCounter('set', 'path_alias_whitelist'), 1);
     $memoryCounterBackend->resetCounter();
     // Re-initialize the whitelist using the same cache backend, should load
     // from cache.
     $whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $aliasStorage);
     $this->assertNull($whitelist->get('user'));
     $this->assertTrue($whitelist->get('admin'));
     $this->assertNull($whitelist->get($this->randomMachineName()));
     $this->assertEqual($memoryCounterBackend->getCounter('get', 'path_alias_whitelist'), 1);
     $this->assertEqual($memoryCounterBackend->getCounter('set', 'path_alias_whitelist'), 0);
     // Destruct the whitelist, should not attempt to write the cache again.
     $whitelist->destruct();
     $this->assertEqual($memoryCounterBackend->getCounter('get', 'path_alias_whitelist'), 1);
     $this->assertEqual($memoryCounterBackend->getCounter('set', 'path_alias_whitelist'), 0);
 }
コード例 #5
0
ファイル: AliasStorageTest.php プロジェクト: ddrozdik/dmaps
 /**
  * @covers ::aliasExists
  */
 public function testAliasExists()
 {
     $this->storage->save('/test-source-Case', '/test-alias-Case');
     $this->assertTrue($this->storage->aliasExists('/test-alias-Case', LanguageInterface::LANGCODE_NOT_SPECIFIED));
     $this->assertTrue($this->storage->aliasExists('/test-alias-case', LanguageInterface::LANGCODE_NOT_SPECIFIED));
 }