pathauto_i18n_user.test 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the pathauto_i18n user module.
  5. */
  6. module_load_include('inc', 'pathauto_i18n', 'tests/pathauto_i18n.test');
  7. /**
  8. * Test functionality for user.
  9. */
  10. class Pathautoi18nUserTest extends Pathautoi18nTest {
  11. /**
  12. * GetInfo method.
  13. */
  14. public static function getInfo() {
  15. return array(
  16. 'name' => 'Pathauto i18n user',
  17. 'description' => 'Ensure that the Pathauto i18n user works.',
  18. 'group' => 'Pathauto i18n',
  19. );
  20. }
  21. /**
  22. * SetUp method.
  23. */
  24. public function setUp() {
  25. $modules[] = 'pathauto_i18n_user';
  26. $this->prepareTest($modules);
  27. // Configure patterns for all language for easy testing.
  28. $edit = array(
  29. 'pathauto_user_pattern' => 'neutral/users/[user:name]',
  30. );
  31. foreach ($this->availableLanguages as $language) {
  32. $edit['pathauto_user_user_' . $language . '_pattern'] = $language . '/users/[user:name]';
  33. }
  34. $this->drupalPost('admin/config/search/path/patterns', $edit, t('Save configuration'));
  35. }
  36. /**
  37. * Test user alias.
  38. */
  39. public function testUserAlias() {
  40. drupal_static_reset('pathauto_pattern_load_by_entity');
  41. $this->createUser();
  42. // Check aliases.
  43. $this->drupalGet('admin/config/search/path/list/users');
  44. foreach ($this->availableLanguages as $language) {
  45. $alias = $language . '/users/' . $this->title;
  46. $this->assertText($alias, 0, "Exist alias '$alias' for language '$language'.");
  47. }
  48. }
  49. /**
  50. * Test clearing of string.
  51. */
  52. public function testCleanString() {
  53. // Set appropriate title which will allow us remove parts of path.
  54. $initial_title = $this->title;
  55. $this->title .= ' ' . implode(' ', $this->availableLanguages);
  56. $this->setCleanStringSettings();
  57. $this->createUser();
  58. // Check aliases.
  59. $this->drupalGet('admin/config/search/path');
  60. foreach ($this->availableLanguages as $language) {
  61. $suffix = $this->getCleanStringSuffix($language);
  62. $alias = $language . '/' . $initial_title . '/' . $suffix;
  63. $this->assertNoText($alias, 0, "Exist alias '$alias' for language '$language' with excluded string '$language'.");
  64. }
  65. }
  66. /**
  67. * Helper to create users.
  68. */
  69. public function createUser() {
  70. $edit = array();
  71. $edit['name'] = $this->title;
  72. $edit['mail'] = $edit['name'] . '@sanchiz.net';
  73. $edit['pass'] = user_password();
  74. $edit['status'] = 1;
  75. $edit['pathauto_i18n_status'] = 1;
  76. user_save(drupal_anonymous_user(), $edit);
  77. }
  78. }