1.20.x path_pattern.test PathPatternFunctionalTestCase::testConfigurationUserInterfaces()

File

modules/path/tests/path_pattern.test, line 706
Functionality tests for automatic path generation.

Class

PathPatternFunctionalTestCase
Test basic Path automatic URL alias functionality.

Code

function testConfigurationUserInterfaces() {
  // Test validation.
  $edit = array();
  $edit['max_length'] = 'abc';
  $edit['max_component_length'] = 'abc';
  $this->backdropPost('admin/config/urls/path/patterns/settings', $edit, 'Save configuration');
  $this->assertText('Maximum URL alias length must be a number.');
  $this->assertText('Maximum component length must be a number.');
  $this->assertNoText('The configuration options have been saved.');

  $edit['max_length'] = '0';
  $edit['max_component_length'] = '0';
  $this->backdropPost('admin/config/urls/path/patterns/settings', $edit, 'Save configuration');
  $this->assertText('Maximum URL alias length must be higher or equal to 1.');
  $this->assertText('Maximum component length must be higher or equal to 1.');
  $this->assertNoText('The configuration options have been saved.');

  $edit['max_length'] = '999';
  $edit['max_component_length'] = '999';
  $this->backdropPost('admin/config/urls/path/patterns/settings', $edit, 'Save configuration');
  $this->assertText('Maximum URL alias length must be below or equal to 255.');
  $this->assertText('Maximum component length must be below or equal to 255.');
  $this->assertNoText('The configuration options have been saved.');

  $edit['max_length'] = '50';
  $edit['max_component_length'] = '50';
  $this->backdropPost('admin/config/urls/path/patterns/settings', $edit, 'Save configuration');
  $this->assertText('The configuration options have been saved.');

  // To test alternate interfaces, we need more permissions.
  $permissions = array(
    'administer path patterns',
    'administer content types',
    'administer taxonomy',
    'administer account settings',
  );
  $this->admin_user = $this->backdropCreateUser($permissions);
  $this->backdropLogin($this->admin_user);

  // Test alternate interfaces - node type configuration.
  $this->backdropCreateContentType(array('type' => 'post', 'name' => 'Post'));
  $edit = array('path_pattern' => 'post/[node:title]/foo');
  $this->backdropPost('admin/structure/types/manage/post', $edit, 'Save content type');
  // Check that the page URL alias pattern is on the pathauto form.
  $this->backdropGet('admin/config/urls/path/patterns');
  $this->assertFieldByName('node_post_pattern', 'post/[node:title]/foo', 'URL alias pattern set with node type settings appears on path config page.');

  // Test alternate interfaces - vocab configuration.
  $vocabulary = $this->addVocabulary();
  $pattern = $vocabulary->machine_name . '/[term:name]/foo';
  $edit = array('path_pattern' => $pattern);
  $this->backdropPost('admin/structure/taxonomy/' . $vocabulary->machine_name . '/configure', $edit, 'Save vocabulary');
  // Check that the page URL alias pattern is on the pathauto form.
  $this->backdropGet('admin/config/urls/path/patterns');
  $this->assertFieldByName('taxonomy_term_' . $vocabulary->machine_name . '_pattern', $pattern, 'URL alias pattern set with vocabulary settings appears on path config page.');

  // Test alternate interfaces - user configuration.
  $edit = array('path_pattern' => 'accounts/[user:name]/foo');
  $this->backdropPost('admin/config/people/settings', $edit, 'Save configuration');
  // Check that the page URL alias pattern is on the pathauto form.
  $this->backdropGet('admin/config/urls/path/patterns');
  $this->assertFieldByName('user_pattern', 'accounts/[user:name]/foo', 'URL alias pattern set with user account settings appears on path config page.');
}