Index: l10n_community/tests/l10n_community.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/tests/Attic/l10n_community.test,v retrieving revision 1.1.2.4 diff -u -p -u -p -r1.1.2.4 l10n_community.test --- l10n_community/tests/l10n_community.test 8 Sep 2009 14:38:39 -0000 1.1.2.4 +++ l10n_community/tests/l10n_community.test 9 Sep 2009 08:48:04 -0000 @@ -8,6 +8,9 @@ class L10nServerTestCase extends DrupalWebTestCase { + private $version_base = '3.5'; + private $version_js = '5.7'; + public static function getInfo() { return array( 'name' => t('Localization server'), @@ -41,7 +44,7 @@ class L10nServerTestCase extends DrupalW $this->drupalPost('admin/l10n_server/l10n_localpacks', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Local package directory set.')); - $this->package_files = $this->project_names = array(); + $this->project_names = array(); } /** @@ -80,9 +83,10 @@ class L10nServerTestCase extends DrupalW $this->assertText(t('No strings to translate.'), t('Language now recognized, but still no strings to translate.')); $this->drupalGet('user/logout'); - // Add and parse a project in the environment. + // Add and parse projects in the environment. $this->addProject(5); $this->addProject(6); + $this->addProject(6, FALSE); $this->addProject(7); $this->drupalLogin($this->u_auth); @@ -97,16 +101,122 @@ class L10nServerTestCase extends DrupalW foreach ($this->project_names as $api => $name) { $this->drupalGet('translate/projects/'. $name); $this->assertText('Hungarian', t('Language shows up on project page.')); - $this->assertText(t('1 release known'), t('One release known on project.')); - $this->assertText(t('1 release parsed'), t('One release parsed on project.')); - //$this->outputScreenContents(); + if ($api == 6) { + $this->assertText(t('@count releases known', array('@count' => 2)), t('Two releases known on project.')); + $this->assertText(t('@count releases parsed', array('@count' => 2)), t('Two releases parsed on project.')); + } + else { + $this->assertText(t('1 release known'), t('One release known on project.')); + $this->assertText(t('1 release parsed'), t('One release parsed on project.')); + } + } - $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $name)); - //$this->outputScreenContents(); + // Check that the base list of strings are there. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50')); + $this->assertMsgID('This is a test string.'); + $this->assertMsgID('Test menu item in 5'); + $this->assertMsgID('test potx permission'); + $this->assertMsgIDPlural('1 test string'); + $this->assertMsgIDPlural('@count test strings'); + $this->assertMsgIDPlural('1 test string in JS'); + $this->assertMsgIDPlural('@count test strings in JS'); + $this->assertMsgIDContext('Test string in context', 'Test context'); + + // Check Drupal 5 specific pattern with strings. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[5])); + $this->assertMsgID('This is a test string.'); + $this->assertMsgID('Test menu item in 5'); + $this->assertMsgID('test potx permission'); + $this->assertMsgIDPlural('1 test string'); + $this->assertMsgIDPlural('@count test strings'); + $this->assertMsgIDPlural('1 test string in JS', FALSE); + $this->assertMsgIDPlural('@count test strings in JS', FALSE); + $this->assertMsgIDContext('Test string in context', 'Test context', FALSE); + + // Check Drupal 6 specific pattern with strings. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6])); + $this->assertMsgID('This is a test string.'); + $this->assertMsgID('Test menu item in 5', FALSE); + $this->assertMsgID('test potx permission'); + $this->assertMsgIDPlural('1 test string'); + $this->assertMsgIDPlural('@count test strings'); + $this->assertMsgIDPlural('1 test string in JS'); + $this->assertMsgIDPlural('@count test strings in JS'); + $this->assertMsgIDContext('Test string in context', 'Test context', FALSE); + + // No JS release should not have JS strings. + $rid = db_result(db_query("SELECT rid FROM {l10n_community_project} p LEFT JOIN {l10n_community_release} r ON p.pid = r.pid WHERE p.uri = '%s' AND r.title = '6.x-". $this->version_base . "'", $this->project_names[6])); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6] .'&release='. $rid)); + $this->assertMsgIDPlural('1 test string in JS', FALSE); + $this->assertMsgIDPlural('@count test strings in JS', FALSE); + + // JS release should have JS strings. + $rid = db_result(db_query("SELECT rid FROM {l10n_community_project} p LEFT JOIN {l10n_community_release} r ON p.pid = r.pid WHERE p.uri = '%s' AND r.title = '6.x-". $this->version_js . "'", $this->project_names[6])); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6] .'&release='. $rid)); + $this->assertMsgIDPlural('1 test string in JS'); + $this->assertMsgIDPlural('@count test strings in JS'); + + // Check Drupal 7 specific pattern with strings. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[7])); + $this->assertMsgID('This is a test string.'); + $this->assertMsgID('Test menu item in 5', FALSE); + $this->assertMsgID('test potx permission', FALSE); + $this->assertMsgIDPlural('1 test string'); + $this->assertMsgIDPlural('@count test strings'); + $this->assertMsgIDPlural('1 test string in JS'); + $this->assertMsgIDPlural('@count test strings in JS'); + $this->assertMsgIDContext('Test string in context', 'Test context'); + + //$this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $name)); + //$this->outputScreenContents(); + } + + /** + * Look for a string appearance on the page for $raw. + */ + private function assertMsgID($raw, $match = TRUE) { + if ($match) { + $message = t('String "@raw" found', array('@raw' => check_plain($raw))); + } + else { + $message = t('String "@raw" not found', array('@raw' => check_plain($raw))); } + $found = strpos($this->content, ''); + $found = $match ? ($found !== FALSE) : ($found === FALSE); + return $this->assert($found, $message); } /** + * Look for a singular/plural string appearance on the page for $raw. + */ + private function assertMsgIDPlural($raw, $match = TRUE) { + if ($match) { + $message = t('Singular/plural string "@raw" found', array('@raw' => check_plain($raw))); + } + else { + $message = t('Singular/plural string "@raw" not found', array('@raw' => check_plain($raw))); + } + // Look for the string wrapped in a list item on its own line. Only used + // for singular and plural strings. + $found = (bool) preg_match('!