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.5 diff -u -p -u -p -r1.1.2.5 l10n_community.test --- l10n_community/tests/l10n_community.test 9 Sep 2009 08:51:24 -0000 1.1.2.5 +++ l10n_community/tests/l10n_community.test 9 Sep 2009 12:46:18 -0000 @@ -26,6 +26,7 @@ class L10nServerTestCase extends DrupalW // Prepare users on different permission levels. $this->u_anon = $this->drupalCreateUser(); $this->u_auth = $this->drupalCreateUser(array('access localization community')); + $this->u_member = $this->drupalCreateUser(array('access localization community', 'submit suggestions')); $this->u_admin = $this->drupalCreateUser(array('administer languages', 'administer localization community', 'administer localization community for local packages')); // Set up temporary directory for our work. Because this is inside the @@ -65,7 +66,7 @@ class L10nServerTestCase extends DrupalW } /** - * Test basic functionality on languages screen. + * Test languages and projects and basic project addition. */ public function testLanguagesProjects() { // Non-priviledged users should not have access to the welcome screen. @@ -111,8 +112,10 @@ class L10nServerTestCase extends DrupalW } } + // PROJECTS ==== + // Check that the base list of strings are there. - $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50')); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30')); $this->assertMsgID('This is a test string.'); $this->assertMsgID('Test menu item in 5'); $this->assertMsgID('test potx permission'); @@ -121,9 +124,10 @@ class L10nServerTestCase extends DrupalW $this->assertMsgIDPlural('1 test string in JS'); $this->assertMsgIDPlural('@count test strings in JS'); $this->assertMsgIDContext('Test string in context', 'Test context'); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[5])); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[5])); $this->assertMsgID('This is a test string.'); $this->assertMsgID('Test menu item in 5'); $this->assertMsgID('test potx permission'); @@ -132,9 +136,10 @@ class L10nServerTestCase extends DrupalW $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); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6])); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&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'); @@ -143,31 +148,153 @@ class L10nServerTestCase extends DrupalW $this->assertMsgIDPlural('1 test string in JS'); $this->assertMsgIDPlural('@count test strings in JS'); $this->assertMsgIDContext('Test string in context', 'Test context', FALSE); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=30&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->assertCount('project_names[6])); - $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6] .'&release='. $rid)); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[6] .'&release='. $rid)); $this->assertMsgIDPlural('1 test string in JS', FALSE); $this->assertMsgIDPlural('@count test strings in JS', FALSE); + $this->assertCount('project_names[6])); - $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[6] .'&release='. $rid)); + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[6] .'&release='. $rid)); $this->assertMsgIDPlural('1 test string in JS'); $this->assertMsgIDPlural('@count test strings in JS'); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $this->project_names[7])); + // CONTEXT ==== + + // Filtering for context in general works. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&context=Test%20context')); + $this->assertMsgIDContext('Test string in context', 'Test context'); + $this->assertMsgID('This is a test string.', FALSE); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[7] .'&context=Test%20context')); + $this->assertMsgIDContext('Test string in context', 'Test context'); + $this->assertMsgID('This is a test string.', FALSE); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[6] .'&context=Test%20context')); + $this->assertRaw(t('No strings found with this filter. Try adjusting the filter options.')); + + // SEARCH ==== + + // Filtering for text contained works. + $this->drupalGet('translate/languages/hu/view', array('query' => 'limit=30&search=is%20a')); $this->assertMsgID('This is a test string.'); - $this->assertMsgID('Test menu item in 5', FALSE); + $this->assertMsgID('This is a test menu item in 5'); + $this->assertMsgID('This is a test menu item'); $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->assertMsgIDPlural('1 test string', FALSE); + $this->assertCount('drupalGet('translate/languages/hu/view', array('query' => 'limit=30&project='. $this->project_names[6] .'&search=is%20a')); + $this->assertMsgID('This is a test string.'); + $this->assertMsgID('This is a test menu item in 5', FALSE); + $this->assertMsgID('This is a test menu item'); + $this->assertMsgID('test potx permission', FALSE); + $this->assertMsgIDPlural('1 test string', FALSE); + $this->assertCount('drupalGet('translate/details/hu/'. $sid); + $this->assertRaw(''. $this->project_names[5] .': 5.x-'. $this->version_js .' (1)'); + $this->assertRaw(''. $this->project_names[6] .': 6.x-'. $this->version_js .' (1), 6.x-'. $this->version_base .' (1)'); + $this->assertRaw(''. $this->project_names[7] .': 7.x-'. $this->version_js .' (1)'); + } + + /** + * Test submitting suggestions. + */ + public function testSuggetions() { + $this->addLanguage(); + $this->addProject(5); + $this->addProject(6); + $this->addProject(6, FALSE); + $this->addProject(7); - //$this->drupalGet('translate/languages/hu/view', array('query' => 'limit=50&project='. $name)); + // Verify that we can see the suggestion submission screen. + $this->drupalLogin($this->u_member); + $this->drupalGet('translate/languages/hu/edit', array('query' => 'limit=30')); + $this->assertMsgID('This is a test string.'); + + // SUBMIT SUGGESTIONS ==== + + // Add suggestions for four strings. + $edit = array(); + $sid1 = db_result(db_query("SELECT sid FROM {l10n_community_string} WHERE value = '%s'", 'This is a test string.')); + $edit[$sid1 .'[translation][value]'] = 'This is a test string. suggestion'; + $sid2 = db_result(db_query("SELECT sid FROM {l10n_community_string} WHERE value = '%s' AND context = ''", 'Test string in context')); + $edit[$sid2 .'[translation][value]'] = 'Test string in context. suggestion-1'; + $sid3 = db_result(db_query("SELECT sid FROM {l10n_community_string} WHERE value = '%s' AND context = '%s'", 'Test string in context', 'Test context')); + $edit[$sid3 .'[translation][value]'] = 'Test string in context. suggestion-2'; + $sid4 = db_result(db_query("SELECT sid FROM {l10n_community_string} WHERE value = '%s'", "1 test string\0@count test strings")); + $edit[$sid4 .'[translation][value][0]'] = '1 test string suggestion'; + $edit[$sid4 .'[translation][value][1]'] = '@count test strings suggestion'; + $this->drupalPost('translate/languages/hu/edit', $edit, t('Save suggestions'), array('query' => 'limit=30')); + $this->assertRaw(t('@count new suggestions added.', array('@count' => 4))); + + // Add second suggestions to test for that later. + $edit = array(); + $edit[$sid1 .'[translation][value]'] = 'This is a test string. suggestion-2'; + $edit[$sid3 .'[translation][value]'] = 'Test string in context. suggestion-3'; + $this->drupalPost('translate/languages/hu/edit', $edit, t('Save suggestions'), array('query' => 'limit=30')); + $this->assertRaw(t('@count new suggestions added.', array('@count' => 2))); + + // CHECK SUGGESTIONS ==== + + $this->drupalGet('translate/suggestions/hu/'. $sid1); + $this->assertMsgID('This is a test string. suggestion'); + $this->assertMsgID('This is a test string. suggestion-2'); + $this->assertRaw('by '. $this->u_member->name .''); + + $this->drupalGet('translate/suggestions/hu/'. $sid2); + $this->assertMsgID('Test string in context. suggestion-1'); + $this->assertRaw('by '. $this->u_member->name .''); + + $this->drupalGet('translate/suggestions/hu/'. $sid3); + $this->assertMsgID('Test string in context. suggestion-2'); + $this->assertMsgID('Test string in context. suggestion-3'); + $this->assertRaw('by '. $this->u_member->name .''); + + $this->drupalGet('translate/suggestions/hu/'. $sid4); + // Plural suggestions are encoded with a "; " separator. + $this->assertMsgID('1 test string suggestion; @count test strings suggestion'); + $this->assertRaw('by '. $this->u_member->name .''); + + // CHECK LISTINGS ==== + + $this->drupalGet('translate/languages/hu/edit', array('query' => 'limit=30')); + $this->assertCount('drupalGet('translate/languages/hu/edit', array('query' => 'status=8&limit=30')); + $this->assertCount('drupalGet('translate/languages/hu/edit', array('query' => 'status=4&limit=30')); + $this->assertCount('outputScreenContents(); } @@ -176,10 +303,10 @@ class L10nServerTestCase extends DrupalW */ private function assertMsgID($raw, $match = TRUE) { if ($match) { - $message = t('String "@raw" found', array('@raw' => check_plain($raw))); + $message = t('String "@raw" found', array('@raw' => $raw)); } else { - $message = t('String "@raw" not found', array('@raw' => check_plain($raw))); + $message = t('String "@raw" not found', array('@raw' => $raw)); } $found = strpos($this->content, ''); $found = $match ? ($found !== FALSE) : ($found === FALSE); @@ -191,10 +318,10 @@ class L10nServerTestCase extends DrupalW */ private function assertMsgIDPlural($raw, $match = TRUE) { if ($match) { - $message = t('Singular/plural string "@raw" found', array('@raw' => check_plain($raw))); + $message = t('Singular/plural string "@raw" found', array('@raw' => $raw)); } else { - $message = t('Singular/plural string "@raw" not found', array('@raw' => check_plain($raw))); + $message = t('Singular/plural string "@raw" not found', array('@raw' => $raw)); } // Look for the string wrapped in a list item on its own line. Only used // for singular and plural strings. @@ -207,16 +334,24 @@ class L10nServerTestCase extends DrupalW */ private function assertMsgIDContext($raw, $context, $match = TRUE) { if ($match) { - $message = t('String "@raw" found in context "@context"', array('@raw' => check_plain($raw), '@context' => check_plain($context))); + $message = t('String "@raw" found in context "@context"', array('@raw' => $raw, '@context' => $context)); } else { - $message = t('String "@raw" not found in context "@context"', array('@raw' => check_plain($raw), '@context' => check_plain($context))); + $message = t('String "@raw" not found in context "@context"', array('@raw' => $raw, '@context' => $context)); } $found = (bool) preg_match('!.*
'. preg_quote(t('in context: @context', array('@context' => $context))) . '
!', $this->drupalGetContent()); return $this->assert($match ? $found : !$found, $message); } /** + * Assert count of substring occurance in the output. + */ + private function assertCount($raw, $count) { + $message = t('"@raw" found @count times', array('@raw' => $raw, '@count' => $count)); + return $this->assert(substr_count($this->content, $raw) === $count, $message); + } + + /** * Helper function to add a language. Used by other tests. */ private function addLanguage() {