diff --git a/pathologic.test b/pathologic.test index 7318d21..25e12e4 100644 --- a/pathologic.test +++ b/pathologic.test @@ -141,3 +141,76 @@ class PathologicTestCase extends DrupalWebTestCase { ); } } + +class PathologicTestLanguageCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Pathologic path filtering language handling', + 'description' => 'Test Pathologic’s path translation and conversion with language prefix.', + 'group' => 'Filter', + ); + } + + function setUp() { + parent::setUp('locale', 'locale_test', 'pathologic'); + + // Create and login user. + $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'administer url aliases', 'access administration pages', 'create page content', 'edit any page content')); + $this->drupalLogin($admin_user); + + // Add language. + $edit = array('langcode' => 'fr'); + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + + // Set "Basic page" content type to use multilingual support. + $this->drupalGet('admin/structure/types/manage/page'); + $edit = array('language_content_type' => 1); + $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); + + // Enable URL language detection and selection. + $edit = array('language[enabled][locale-url]' => 1); + $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings')); + + // Change user language preference. + $edit = array('language' => 'fr'); + $this->drupalPost("user/{$admin_user->uid}/edit", $edit, t('Save')); + } + + function testPathologicLanguage() { + // Build a phony filter + $filter = new stdClass; + $filter->callback = '_pathologic'; + $filter->settings = array( + 'absolute' => TRUE, + 'local_paths' => "http://example.com/qux/abc", + ); + $filter->format = 0; + + // Create a node. + $title_value = $this->randomName(8); + $custom_path = $this->randomName(8) . "/oranges"; + $edit = array(); + $edit['title'] = $title_value; + $edit['language'] = 'fr'; + $edit['path[alias]'] = $custom_path; + $this->drupalPost('node/add/page', $edit, t('Save')); + $node = $this->drupalGetNodeByTitle($edit['title']); + + // Clear the path lookup cache. + drupal_lookup_path('wipe'); + drupal_static_reset('language_list'); + drupal_static_reset('locale_url_outbound_alter'); + + // Get the language object + $languages = language_list(); + $lang = $languages['fr']; + + // Test with path language prefix + $this->assertEqual( + _pathologic_filter('', $filter, NULL, 'fr', NULL, NULL), + '', + t('URLs with language prefix') + ); + $this->drupalLogout(); + } +}