| 1 |
<?php
|
| 2 |
// $Id: pift.test,v 1.3 2009/04/14 06:41:21 boombatower Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provide test of functionality.
|
| 6 |
*
|
| 7 |
* Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
|
| 8 |
*/
|
| 9 |
|
| 10 |
class PIFTTestCase extends DrupalWebTestCase {
|
| 11 |
|
| 12 |
protected $adminUser;
|
| 13 |
|
| 14 |
protected $drupalProject;
|
| 15 |
|
| 16 |
protected $testProject;
|
| 17 |
|
| 18 |
protected $testRelease;
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of getInfo().
|
| 22 |
*/
|
| 23 |
public static function getInfo() {
|
| 24 |
return array(
|
| 25 |
'name' => t('PIFT'),
|
| 26 |
'description' => t('Confirm that the various workflow elements that PIFT modified work as intended.'),
|
| 27 |
'group' => t('PIFT'),
|
| 28 |
);
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Implementation of setUp().
|
| 33 |
*/
|
| 34 |
public function setUp() {
|
| 35 |
parent::setUp('upload', 'comment_upload', 'project', 'project_release', 'project_issue', 'cvs', 'pift');
|
| 36 |
|
| 37 |
$this->adminUser = $this->drupalCreateUser(array('administer projects', 'maintain projects', 'access project issues',
|
| 38 |
'create project issues', 'administer CVS', 'pift re-test files',
|
| 39 |
'administer content types', 'upload files', 'upload files to comments',
|
| 40 |
'view files uploaded to comments'));
|
| 41 |
$this->drupalLogin($this->adminUser);
|
| 42 |
$this->setUpProject();
|
| 43 |
$this->setUpSettings();
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Setup project related information for test.
|
| 48 |
*/
|
| 49 |
protected function setUpProject() {
|
| 50 |
// Setup core CVS repository.
|
| 51 |
$edit = array(
|
| 52 |
'name' => 'drupal-core',
|
| 53 |
'method' => 1, // Use external script to insert data, thus never retrieve.
|
| 54 |
'root' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal',
|
| 55 |
);
|
| 56 |
$this->drupalPost('admin/project/cvs-repositories/add', $edit, t('Save repository'));
|
| 57 |
$this->assertText(t('Added CVS repository: @name', array('@name' => $edit['name'])));
|
| 58 |
|
| 59 |
// Setup contrib CVS repository.
|
| 60 |
$edit = array(
|
| 61 |
'name' => 'drupal-contrib',
|
| 62 |
'method' => 1, // Use external script to insert data, thus never retrieve.
|
| 63 |
'root' => ':pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib',
|
| 64 |
);
|
| 65 |
$this->drupalPost('admin/project/cvs-repositories/add', $edit, t('Save repository'));
|
| 66 |
$this->assertText(t('Added CVS repository: @name', array('@name' => $edit['name'])));
|
| 67 |
|
| 68 |
// Setup CVS account.
|
| 69 |
$edit = array(
|
| 70 |
'data' => $this->adminUser->name . ':anonymous:anonymous',
|
| 71 |
);
|
| 72 |
$this->drupalPost('admin/project/cvs-accounts/import', $edit, t('Import accounts'));
|
| 73 |
$this->assertText(t('added @user', array('@user' => $this->adminUser->name)));
|
| 74 |
|
| 75 |
// Set project settings.
|
| 76 |
$edit = array(
|
| 77 |
'project_issue_followup_user' => $this->adminUser->name,
|
| 78 |
);
|
| 79 |
$this->drupalPost('admin/project/project-issue-settings', $edit, t('Save configuration'));
|
| 80 |
|
| 81 |
// Enable attachments on project issues.
|
| 82 |
$edit = array(
|
| 83 |
'upload' => 1,
|
| 84 |
'comment_preview' => 0, // Optional.
|
| 85 |
'comment_form_location' => 1, // Display below post or comments.
|
| 86 |
);
|
| 87 |
$this->drupalPost('admin/content/node-type/project-issue', $edit, t('Save content type'));
|
| 88 |
$this->assertRaw(t('The content type %type has been added.', array('%type' => 'Issue')));
|
| 89 |
|
| 90 |
// Setup core project.
|
| 91 |
$edit = array(
|
| 92 |
'title' => 'Drupal',
|
| 93 |
'project[uri]' => 'drupal',
|
| 94 |
'cvs[repository]' => 1, // Core CVS repository.
|
| 95 |
'cvs[directory]' => '/drupal',
|
| 96 |
);
|
| 97 |
$this->drupalPost('node/add/project-project', $edit, t('Save'));
|
| 98 |
$this->drupalProject = node_load(array('title' => $edit['title']));
|
| 99 |
|
| 100 |
// Setup contrib project.
|
| 101 |
$edit = array(
|
| 102 |
'title' => 'Test',
|
| 103 |
'project[uri]' => 'test',
|
| 104 |
'cvs[repository]' => 2, // Contrib CVS repository.
|
| 105 |
'cvs[directory]' => '/modules/simpletest',
|
| 106 |
);
|
| 107 |
$this->drupalPost('node/add/project-project', $edit, t('Save'));
|
| 108 |
$this->testProject = node_load(array('title' => $edit['title']));
|
| 109 |
|
| 110 |
// Create release for contrib project.
|
| 111 |
$this->drupalPost('node/add/project-release/' . $this->testProject->nid, array(), t('Next'));
|
| 112 |
|
| 113 |
$edit = array(
|
| 114 |
'project_release[version_major]' => '1',
|
| 115 |
'project_release[version_minor]' => '0',
|
| 116 |
);
|
| 117 |
$this->drupalPost(NULL, $edit, t('Next'));
|
| 118 |
|
| 119 |
$edit = array(
|
| 120 |
'body' => $this->randomName(32),
|
| 121 |
);
|
| 122 |
$this->drupalPost(NULL, $edit, t('Save'));
|
| 123 |
$this->testRelease = node_load(array('title' => $this->testProject->title . ' 1.0'));
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Setup PIFT settings for test.
|
| 128 |
*/
|
| 129 |
protected function setUpSettings() {
|
| 130 |
$edit = array(
|
| 131 |
'pift_key' => md5($this->randomName()),
|
| 132 |
'pift_server' => url('', array('absolute' => TRUE)),
|
| 133 |
'pift_followup_fail' => 13, // Patch (code needs work).
|
| 134 |
'pift_followup_retest' => 8, // Patch (code needs review).
|
| 135 |
'pift_regex' => '/\.txt$/', // Want to use .txt files since they are available as test files.
|
| 136 |
'pift_status[]' => array(8, 14), // Patch (code needs review), patch (ready to commit).
|
| 137 |
'pift_core[7]' => TRUE, // Test 7.x related branches.
|
| 138 |
'pift_pid' => $this->drupalProject->title,
|
| 139 |
);
|
| 140 |
$this->drupalPost('admin/project/pift', $edit, t('Save configuration'));
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Test the PIFT interface to ensure that adding files are displayed
|
| 145 |
* correctly.
|
| 146 |
*/
|
| 147 |
public function testInterface() {
|
| 148 |
// Upload a patch file and see that it is ignored.
|
| 149 |
$file = array_shift($this->drupalGetTestFiles('text', 1024));
|
| 150 |
$edit = array(
|
| 151 |
'rid' => $this->testRelease->nid,
|
| 152 |
'component' => 'Code',
|
| 153 |
'category' => 'task',
|
| 154 |
'title' => $this->randomName(8),
|
| 155 |
'body' => $this->randomName(32),
|
| 156 |
'files[upload]' => realpath($file->filename),
|
| 157 |
);
|
| 158 |
$this->drupalPost('node/add/project-issue/' . $this->testProject->project['uri'], $edit, t('Save'));
|
| 159 |
$this->assertRaw(t('@type %title has been created', array('@type' => 'Issue', '%title' => $edit['title'])));
|
| 160 |
$issue = node_load(array('title' => $edit['title']));
|
| 161 |
|
| 162 |
$this->checkAttachmentStandard($issue->nid, NULL);
|
| 163 |
|
| 164 |
// Upload file in proper status.
|
| 165 |
$comments = array();
|
| 166 |
$edit = array(
|
| 167 |
'sid' => 8,
|
| 168 |
'files[upload]' => realpath($file->filename),
|
| 169 |
);
|
| 170 |
$this->drupalPost('node/' . $issue->nid, $edit, t('Save'));
|
| 171 |
$comments[] = $this->loadLastComment($issue->nid);
|
| 172 |
|
| 173 |
$this->checkAttachmentStandard($issue->nid, NULL);
|
| 174 |
$this->checkAttachmentStandard($issue->nid, $comments[0]->cid);
|
| 175 |
|
| 176 |
// Enable testing of project.
|
| 177 |
$edit = array(
|
| 178 |
'pift_enable' => TRUE,
|
| 179 |
);
|
| 180 |
$this->drupalPost('node/' . $this->testProject->nid . '/edit/issues', $edit, t('Save'));
|
| 181 |
|
| 182 |
// Upload file when all criteria is matched.
|
| 183 |
$edit = array(
|
| 184 |
'files[upload]' => realpath($file->filename),
|
| 185 |
);
|
| 186 |
$this->drupalPost('node/' . $issue->nid, $edit, t('Save'));
|
| 187 |
$comments[] = $this->loadLastComment($issue->nid);
|
| 188 |
|
| 189 |
$this->checkAttachment($issue->nid, NULL, $file, 'Queued for testing');
|
| 190 |
$this->checkAttachment($issue->nid, $comments[0]->cid, $file, 'Queued for testing');
|
| 191 |
$this->checkAttachment($issue->nid, $comments[1]->cid, $file, 'Queued for testing');
|
| 192 |
|
| 193 |
// Change file regex.
|
| 194 |
$edit = array(
|
| 195 |
'pift_regex' => '/\.patch$/',
|
| 196 |
);
|
| 197 |
$this->drupalPost('admin/project/pift', $edit, t('Save configuration'));
|
| 198 |
|
| 199 |
// Upload non-patch file when all criteria is matched.
|
| 200 |
$edit = array(
|
| 201 |
'files[upload]' => realpath($file->filename),
|
| 202 |
);
|
| 203 |
$this->drupalPost('node/' . $issue->nid, $edit, t('Save'));
|
| 204 |
$comments[] = $this->loadLastComment($issue->nid);
|
| 205 |
|
| 206 |
$this->checkAttachment($issue->nid, NULL, $file, 'Queued for testing');
|
| 207 |
$this->checkAttachment($issue->nid, $comments[0]->cid, $file, 'Queued for testing');
|
| 208 |
$this->checkAttachment($issue->nid, $comments[1]->cid, $file, 'Queued for testing');
|
| 209 |
$this->checkAttachment($issue->nid, $comments[2]->cid, $file, 'Ignored');
|
| 210 |
|
| 211 |
// Change file regex back.
|
| 212 |
$edit = array(
|
| 213 |
'pift_regex' => '/\.txt$/',
|
| 214 |
);
|
| 215 |
$this->drupalPost('admin/project/pift', $edit, t('Save configuration'));
|
| 216 |
|
| 217 |
// Upload patch file when all criteria is matched.
|
| 218 |
$edit = array(
|
| 219 |
'files[upload]' => realpath($file->filename),
|
| 220 |
);
|
| 221 |
$this->drupalPost('node/' . $issue->nid, $edit, t('Save'));
|
| 222 |
$comments[] = $this->loadLastComment($issue->nid);
|
| 223 |
|
| 224 |
$this->checkAttachment($issue->nid, NULL, $file, 'Queued for testing');
|
| 225 |
$this->checkAttachment($issue->nid, $comments[0]->cid, $file, 'Queued for testing');
|
| 226 |
$this->checkAttachment($issue->nid, $comments[1]->cid, $file, 'Queued for testing');
|
| 227 |
$this->checkAttachment($issue->nid, $comments[2]->cid, $file, 'Queued for testing');
|
| 228 |
$this->checkAttachment($issue->nid, $comments[3]->cid, $file, 'Queued for testing');
|
| 229 |
}
|
| 230 |
|
| 231 |
/**
|
| 232 |
* Check that an attachment has the intended values.
|
| 233 |
*/
|
| 234 |
protected function checkAttachment($nid, $cid, $file, $status, $test_result = 'None', $operations = 'None') {
|
| 235 |
$result = $this->xpath('//div[@id="pift-results-' . $nid . ($cid ? "-$cid" : '') . '"]');
|
| 236 |
if ($result) {
|
| 237 |
$result = $result[0]->table->tbody->tr;
|
| 238 |
|
| 239 |
$this->assertEqual($file->basename, $this->asText($result->td[0]), t('Link matches.'));
|
| 240 |
$this->assertEqual(format_size(filesize($file->filename)), $this->asText($result->td[1]), t('Size matches.'));
|
| 241 |
$this->assertEqual($status, $this->asText($result->td[2]), t('Status matches.'));
|
| 242 |
$this->assertEqual($test_result, $this->asText($result->td[3]), t('Test result matches.'));
|
| 243 |
$this->assertEqual($operations, $this->asText($result->td[4]), t('Operations match.'));
|
| 244 |
}
|
| 245 |
else {
|
| 246 |
$this->fail(t('Attachment not found (n: @nid, c: @cid).', array('@nid' => $nid, '@cid' => $cid)));
|
| 247 |
}
|
| 248 |
}
|
| 249 |
|
| 250 |
/**
|
| 251 |
* Check for standard (upload, comment_upload generated) attachment table.
|
| 252 |
*/
|
| 253 |
protected function checkAttachmentStandard($nid, $cid) {
|
| 254 |
$result = $this->xpath('//div[@id="pift-results-' . $nid . ($cid ? "-$cid" : '') . '"]');
|
| 255 |
|
| 256 |
$this->assertFalse($result, t('Attachment not found (n: @nid, c: @cid).', array('@nid' => $nid, '@cid' => $cid)));
|
| 257 |
}
|
| 258 |
|
| 259 |
/**
|
| 260 |
* Load the last submitted comment for the specified node.
|
| 261 |
*
|
| 262 |
* @param integer $nid Node ID.
|
| 263 |
* @return object Comment object.
|
| 264 |
*/
|
| 265 |
protected function loadLastComment($nid) {
|
| 266 |
return db_fetch_object(db_query('SELECT *
|
| 267 |
FROM {comments}
|
| 268 |
WHERE nid = %d
|
| 269 |
ORDER BY cid DESC
|
| 270 |
LIMIT 1', $nid));
|
| 271 |
}
|
| 272 |
|
| 273 |
/**
|
| 274 |
* Extract the text contained by the element.
|
| 275 |
*
|
| 276 |
* @param $element Element to extract text from.
|
| 277 |
* @return Extracted text.
|
| 278 |
*/
|
| 279 |
function asText(SimpleXMLElement $element) {
|
| 280 |
if (!is_object($element)) {
|
| 281 |
return $this->fail('The element is not an element.');
|
| 282 |
}
|
| 283 |
return trim(html_entity_decode(strip_tags($element->asXML())));
|
| 284 |
}
|
| 285 |
}
|