Index: project.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.test,v
retrieving revision 1.1
diff -u -p -r1.1 project.test
--- project.test	18 Apr 2010 22:05:11 -0000	1.1
+++ project.test	18 Apr 2010 23:09:27 -0000
@@ -1,4 +1,5 @@
 <?php
+// $Id$
 
 class ProjectWebTestCase extends DrupalWebTestCase {
   /**
@@ -7,7 +8,7 @@ class ProjectWebTestCase extends DrupalW
   function setUp() {
     // Setup the required modules for all tests.
     $modules = func_get_args();
-    $modules = array_merge(array('project', 'path'), $modules);
+    $modules = array_merge(array('project'), $modules);
     // We can't call parent::setUp() with a single array argument, so we need
     // this ugly call_user_func_array().
     call_user_func_array(array($this, 'parent::setUp'), $modules);
@@ -36,7 +37,7 @@ class ProjectWebTestCase extends DrupalW
     $this->drupalPost('node/add/project-project', $edit, t('Save'));
     $this->assertRaw(t('!post %title has been created.', array('!post' => 'Project', '%title' => $edit["title"])), t('Project created.'));
 
-    return $edit['project[uri]'];
+    return node_load(array('title' => $edit['title']));
   }
 }
 
@@ -51,7 +52,7 @@ class ProjectTestCase extends ProjectWeb
   }
 
   function setUp() {
-    parent::setUp();
+    parent::setUp('path');
 
     $maintain_user = $this->drupalCreateUser(array('maintain projects'));
     $this->drupalLogin($maintain_user);
@@ -100,3 +101,246 @@ class ProjectTestCase extends ProjectWeb
   }
 }
 
+class ProjectDrupalOrgWebTestCase extends ProjectWebTestCase {
+
+  /**
+   * Admin level user that can access all necessary pages.
+   *
+   * @var object
+   */
+  protected $admin_user;
+
+  /**
+   * List of project nodes created for testing.
+   *
+   * @var array
+   */
+  protected $projects = array();
+
+  /**
+   * List of release nodes created for testing.
+   *
+   * @var array
+   */
+  protected $releases = array();
+
+  /**
+   * Associative array of PIFT settings used for testing.
+   *
+   * @var array
+   */
+  protected $settings = array();
+
+  function setUp() {
+    parent::setUp(
+      'taxonomy',
+      'project',
+      'project_issue',
+      'project_release',
+      'cvs',
+      'views',
+      'comment_upload',
+      'upload'
+    );
+
+
+    // Create administrator user which can access all necessary pages.
+    $this->admin_user = $this->drupalCreateUser(array(
+      'access projects',
+      'administer projects',
+      'maintain projects',
+      'access project issues',
+      'create project issues',
+      'administer CVS',
+      'administer content types',
+      'upload files',
+      'upload files to comments',
+      'view uploaded files',
+      'view files uploaded to comments',
+      'administer site configuration',
+      'administer taxonomy',
+    ));
+
+    // Temporarily set vocabulary to remove notices during login.
+    _project_get_vid();
+    variable_set('project_release_api_vocabulary', 1);
+
+    // Login and setup environment.
+    $this->drupalLogin($this->admin_user);
+
+    $this->setUpTaxonomy();
+    $this->setUpProject();
+  }
+
+  /**
+   * Create project and release taxonomy.
+   */
+  protected function setUpTaxonomy() {
+    // Project types
+    _project_get_vid();
+    $this->setUpTaxonomyTerms(1, array('Drupal project', 'Modules'));
+
+    // Release type.
+    $edit = array(
+      'name' => 'Release type',
+      'nodes[project_release]' => TRUE,
+    );
+    $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, t('Save'));
+
+    $this->setUpTaxonomyTerms(2, array('Bug fixes', 'New features', 'Security release'));
+
+    // Core compatibility.
+    $edit = array(
+      'name' => 'Core compatibility',
+      'nodes[project_release]' => TRUE,
+      'required' => TRUE,
+    );
+    $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, t('Save'));
+
+    db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", 'project_release', 3);
+
+    // Set the variable to ensure that _project_release_get_api_vid() works.
+    variable_set('project_release_api_vocabulary', 3);
+
+    $this->setUpTaxonomyTerms(3, array('5.x', '6.x', '7.x', '8.x'));
+  }
+
+  /**
+   * Create taxonomy terms for given vocabulary ID.
+   *
+   * @param integer $vid Vocabulary ID.
+   * @param array $terms List of terms to add to vocabulary.
+   */
+  protected function setUpTaxonomyTerms($vid, array $terms) {
+    // Visit taxonomy page ahead of time to remove all get requests from loop.
+    $this->drupalGet('admin/content/taxonomy/' . $vid . '/add/term');
+
+    foreach ($terms as $term) {
+      $edit = array(
+        'name' => $term,
+      );
+      $this->drupalPost(NULL, $edit, t('Save'));
+    }
+  }
+
+  /**
+   * Setup project related information and create dumy projects/releases.
+   *
+   * Projects:
+   *   - Drupal: 7.x-dev
+   *   - Foo: 7.x-1.x-dev
+   *   - Bar: 7.x-1.x-dev
+   */
+  protected function setUpProject() {
+    // Setup core CVS repository.
+    $edit = array(
+      'name' => 'Drupal',
+      'method' => 1, // Use external script to insert data, thus never retrieve.
+      'root' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal',
+      'modules' => 'drupal',
+    );
+    $this->drupalPost('admin/project/cvs-repositories/add', $edit, t('Save repository'));
+    $this->assertText(t('Added CVS repository: @name', array('@name' => $edit['name'])));
+
+    // Setup contrib CVS repository.
+    $edit = array(
+      'name' => 'Contributions',
+      'method' => 1, // Use external script to insert data, thus never retrieve.
+      'root' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib',
+      'modules' => 'contributions',
+    );
+    $this->drupalPost('admin/project/cvs-repositories/add', $edit, t('Save repository'));
+    $this->assertText(t('Added CVS repository: @name', array('@name' => $edit['name'])));
+
+    // Setup CVS account.
+    $edit = array(
+      'data' => $this->admin->name . ':anonymous:anonymous',
+    );
+    $this->drupalPost('admin/project/cvs-accounts/import', $edit, t('Import accounts'));
+    $this->assertText(t('added @user', array('@user' => $this->admin->name)));
+
+    // Set project settings, required for auto-followups to function.
+    $edit = array(
+      'project_issue_followup_user' => $this->admin->name,
+    );
+    $this->drupalPost('admin/project/project-issue-settings', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'));
+
+    // Set project release to work with 6.x and 7.x compatibility terms and use
+    // the drupal.org style version format.
+    $edit = array(
+      'project_release_default_version_format' => '!api#major%patch#extra',
+      'project_release_active_compatibility_tids[7]' => TRUE, // 6.x.
+      'project_release_active_compatibility_tids[8]' => TRUE, // 7.x.
+    );
+    $this->drupalPost('admin/project/project-release-settings', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'));
+
+    // Enable attachments on project issues.
+    $edit = array(
+      'upload' => 1,
+      'comment_preview' => 0, // Optional.
+      'comment_form_location' => 1, // Display below post or comments.
+    );
+    $this->drupalPost('admin/content/node-type/project-issue', $edit, t('Save content type'));
+    $this->assertRaw(t('The content type %type has been added.', array('%type' => 'Issue')));
+
+    // Allow uploading of .patch and .diff files.
+    $edit = array(
+      'upload_extensions_default' => 'txt patch diff',
+    );
+    $this->drupalPost('admin/settings/uploads', $edit, t('Save configuration'));
+    $this->assertText(t('The configuration options have been saved.'));
+
+    // Setup Drupal core and contrib projects.
+    foreach (array('drupal', 'foo', 'bar') as $project) {
+      // Drupal core must be treated differently.
+      $core = $project == 'drupal';
+
+      // Create project and load project node for later use.
+      $edit = array(
+        'project_type' => $core ? 1 : 2,
+        'title' => ucfirst($project),
+        'project[uri]' => $project,
+        'body' => $this->randomString(64),
+        'cvs[repository]' => $core ? 1 : 2,
+        'cvs[directory]' => $core ? '/' : '/modules/' . $project . '/',
+      );
+      $this->drupalPost('node/add/project-project', $edit, t('Save'));
+      $this->projects[$project] = node_load(array('title' => $edit['title']));
+
+      // Drupal core requires a special version format string.
+      if ($core) {
+        $edit = array(
+          'version_format' => '!major%minor%patch#extra',
+        );
+        $this->drupalPost('node/' . $this->projects[$project]->nid . '/edit/releases', $edit, t('Save'));
+      }
+
+      // Enable testing of proeject.
+      $edit = array(
+        'pift_enable' => TRUE,
+      );
+      $this->drupalPost('node/' . $this->projects[$project]->nid . '/edit/issues', $edit, t('Save'));
+      $this->assertText(t('Issue settings have been saved.'));
+
+      // Create 7.x release for project.
+      $this->drupalPost('node/add/project-release/' . $this->projects[$project]->nid, array(), t('Next'));
+
+      $edit = array(
+        'taxonomy[3]' => 8, // 7.x.
+        'project_release[version_major]' => $core ? '7' : '1',
+        'project_release[version_patch]' => 'x',
+        'project_release[version_extra]' => 'dev',
+      );
+      $this->drupalPost(NULL, $edit, t('Next'));
+
+      $edit = array(
+        'body' => $this->randomString(32),
+      );
+      $this->drupalPost(NULL, $edit, t('Save'));
+      $this->releases[$project] = node_load(array('title' => $this->projects[$project]->title . ' 7.x' . ($core ? '' : '-1.x') . '-dev'));
+    }
+  }
+
+}
