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, '<span class="original hidden">'. $raw .'</span>');
+    $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('!<li.*<span class="original hidden">'. preg_quote($raw) . '</span>.*</li>!', $this->drupalGetContent());
+    return $this->assert($match ? $found : !$found, $message);
+  }
+
+  /**
+   * Look for a string appearance on the page for $raw related to $context.
+   */
+  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)));
+    }
+    else {
+      $message = t('String "@raw" not found in context "@context"', array('@raw' => check_plain($raw), '@context' => check_plain($context)));
+    }
+    $found = (bool) preg_match('!<span class="original hidden">'. preg_quote($raw) . '</span>.*<div class="string-context">'. preg_quote(t('in context: @context', array('@context' => $context))) . '</div>!', $this->drupalGetContent());
+    return $this->assert($match ? $found : !$found, $message);
+  }
+
+  /**
    * Helper function to add a language. Used by other tests.
    */
   private function addLanguage() {
@@ -119,13 +229,26 @@ class L10nServerTestCase extends DrupalW
     $this->drupalGet('user/logout');
   }
   
-  private function addProject($api_version = 6) {
+  /**
+   * Add a project with the given API version.
+   */
+  private function addProject($api_version = 6, $include_js = TRUE) {
     include_once 'Archive/Tar.php';
+    
+    $version = $api_version .'.x-'. ($include_js ?  $this->version_js : $this->version_base); 
+    
     // Follow the required file name format, so the package connector finds it.
-    $this->package_files[$api_version] = ($package_file = tempnam($this->temp_path, 'l10n_test') .'-'. $api_version . '.x-3.5.tar.gz');
-    // Store project name as start of filename.
-    list($project_name) = explode('-', basename($package_file));
-    $this->project_names[$api_version] = $project_name;
+    // Include api version name in file basename too (before version string),
+    // to ensure that it is easier to debug what strings appear where.
+    if (!isset($this->project_names[$api_version])) {
+      $temp_file = tempnam($this->temp_path, 'l10n_test') .'_'. $api_version;
+      $this->project_names[$api_version] = $project_name = basename($temp_file);
+    }
+    else {
+      $temp_file = $this->temp_path .'/'. $this->project_names[$api_version];
+      $project_name = $this->project_names[$api_version];
+    }
+    $package_file = $temp_file .'-'. $version .'.tar.gz';
     $tar = new Archive_Tar($package_file, 'gz');
     
     // Add the files as strings, so we can control their placement/name.
@@ -133,9 +256,11 @@ class L10nServerTestCase extends DrupalW
     // Add .info file tailored to the module filename (although this is not
     // important for potx, just to be clear about identification).
     $tar->addString('potx_test_'. $api_version .'.info', file_get_contents(drupal_get_path('module', 'potx') .'/tests/potx_test_6.info'));
-    // Add .js file regardless of api version. Although Drupal 5 parsing should
-    // not pick this up, this packaging allows us to test for that exactly.
-    $tar->addString('potx_test_'. $api_version .'.js', file_get_contents(drupal_get_path('module', 'potx') .'/tests/potx_test.js'));
+    if ($include_js) {
+      // Add .js file regardless of api version. Although Drupal 5 parsing should
+      // not pick this up, this packaging allows us to test for that exactly.
+      $tar->addString('potx_test_'. $api_version .'.js', file_get_contents(drupal_get_path('module', 'potx') .'/tests/potx_test.js'));
+    }
     
     $this->assertTrue(file_exists($package_file), t('Test package created.'));
     $this->assertTrue(filesize($package_file) > 0, t('Test package contains data.'));
