/**
   * {@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);
  }
Exemple #2
0
 /**
  * {@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']);
 }
Exemple #3
0
 /**
  * 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);
 }
Exemple #4
0
 /**
  * @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));
 }