Beispiel #1
0
 /**
  * @covers ::load
  */
 public function testLoad()
 {
     $this->storage->save('/test-source-Case', '/test-alias-Case');
     $expected = ['pid' => 1, 'alias' => '/test-alias-Case', 'source' => '/test-source-Case', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED];
     $this->assertEquals($expected, $this->storage->load(['alias' => '/test-alias-Case']));
     $this->assertEquals($expected, $this->storage->load(['alias' => '/test-alias-case']));
     $this->assertEquals($expected, $this->storage->load(['source' => '/test-source-Case']));
     $this->assertEquals($expected, $this->storage->load(['source' => '/test-source-case']));
 }
Beispiel #2
0
 function testCRUD()
 {
     //Prepare database table.
     $connection = Database::getConnection();
     $this->fixtures->createTables($connection);
     //Create Path object.
     $aliasStorage = new AliasStorage($connection, $this->container->get('module_handler'));
     $aliases = $this->fixtures->sampleUrlAliases();
     //Create a few aliases
     foreach ($aliases as $idx => $alias) {
         $aliasStorage->save($alias['source'], $alias['alias'], $alias['langcode']);
         $result = $connection->query('SELECT * FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'], ':langcode' => $alias['langcode']));
         $rows = $result->fetchAll();
         $this->assertEqual(count($rows), 1, format_string('Created an entry for %alias.', array('%alias' => $alias['alias'])));
         //Cache the pid for further tests.
         $aliases[$idx]['pid'] = $rows[0]->pid;
     }
     //Load a few aliases
     foreach ($aliases as $alias) {
         $pid = $alias['pid'];
         $loadedAlias = $aliasStorage->load(array('pid' => $pid));
         $this->assertEqual($loadedAlias, $alias, format_string('Loaded the expected path with pid %pid.', array('%pid' => $pid)));
     }
     // Load alias by source path.
     $loadedAlias = $aliasStorage->load(array('source' => '/node/1'));
     $this->assertEqual($loadedAlias['alias'], '/alias_for_node_1_und', 'The last created alias loaded by default.');
     //Update a few aliases
     foreach ($aliases as $alias) {
         $fields = $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']);
         $this->assertEqual($alias['alias'], $fields['original']['alias']);
         $result = $connection->query('SELECT pid FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', array(':source' => $alias['source'], ':alias' => $alias['alias'] . '_updated', ':langcode' => $alias['langcode']));
         $pid = $result->fetchField();
         $this->assertEqual($pid, $alias['pid'], format_string('Updated entry for pid %pid.', array('%pid' => $pid)));
     }
     //Delete a few aliases
     foreach ($aliases as $alias) {
         $pid = $alias['pid'];
         $aliasStorage->delete(array('pid' => $pid));
         $result = $connection->query('SELECT * FROM {url_alias} WHERE pid = :pid', array(':pid' => $pid));
         $rows = $result->fetchAll();
         $this->assertEqual(count($rows), 0, format_string('Deleted entry with pid %pid.', array('%pid' => $pid)));
     }
 }