You are here

public function PatternsPathautoTestCase::testUrlalias in Patterns 7

File

tests/pathauto/pathauto.test, line 37
SimpleTests for the Field component of Patterns.

Class

PatternsPathautoTestCase
@file SimpleTests for the Field component of Patterns.

Code

public function testUrlalias() {
  if (!patterns_utils_is_module_enabled('pathauto')) {
    $this
      ->fail('Pathauto module not found. Skipping all related tests');
    return;
  }

  // Make sure that matches the info in the pattern file
  $source = "admin/patterns/quickrun";
  $alias = "pathauto1";

  //module_enable(array('pathauto'));

  //create url aliase
  parent::runFile('url_alias_created.yaml', 'URLs aliases create', $this->pathauto_tests_dir);
  $result = db_select('url_alias', 'u')
    ->fields('u', array(
    'pid',
  ))
    ->condition('source', $source)
    ->condition('alias', $alias)
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertTrue($result, t('Created URL alias correctly.'));

  //modify url alias
  parent::runFile('url_alias_modify.yaml', 'URLs aliases modify', $this->pathauto_tests_dir);
  $sourceM = 'admin/patterns/quickrun';
  $aliasM = 'pathauto';

  // Confirm that the alias works.
  $result = db_select('url_alias', 'u')
    ->fields('u', array(
    'source',
    'alias',
  ))
    ->condition('pid', 1)
    ->execute()
    ->fetchAll();
  $this
    ->assertEqual($result[0]->source, $sourceM, t('Modified alias source correctly.'));
  $this
    ->assertEqual($result[0]->alias, $aliasM, t('Modified alias correctly.'));

  //delete url alias
  parent::runFile('url_alias_delete.yaml', 'URLs aliases delete', $this->pathauto_tests_dir);

  //break;

  // Confirm that the alias works.
  $result = db_select('url_alias', 'u')
    ->fields('u', array(
    'source',
    'alias',
  ))
    ->condition('pid', 1)
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertFalse($result, t('Deleted alias correctly.'));
}