Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Created July 29, 2010 16:57
Show Gist options
  • Save mrchrisadams/498656 to your computer and use it in GitHub Desktop.
Save mrchrisadams/498656 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Tests for clientproject.
*/
class clientProjectFeatureTestCase extends DrupalWebTestCase {
/**
* getInfo() returns properties that are displayed in the test selection form.
*/
public static function getInfo() {
return array(
'name' => 'clientproject feature',
'description' => t('Run tests for components of Features.') ,
'group' => 'clientproject',
);
}
/**
* A convenience function to allow us to set the permissions for any roles
* we need to test, in one place, rather than repeatedly in each test case.
* When we need to add extra permissions to roles, just change them here,
* and re-run all tests.
*
* @return Returns an array with permissions needed for role
**/
public function get_roles_permissions($role) {
switch ($role) {
// staff members are basic administrative employees
case 'staff':
$array_of_permissions = array(
'access administration pages',
'administer comments',
'administer users',
'create news_item content',
'edit any news_item content',
'delete any news_item content'
);
break;
case 'admin':
// admins are essentially webmasters for the site
$array_of_permissions = array(
'access administration pages',
'administer features',
'administer content types',
'administer comments',
'administer permissions',
'administer users',
'create news_item content'
);
break;
case 'featured_expert':
// admins are essentially webmasters for the site
$array_of_permissions = array(
'access administration pages',
'create blog_post content',
'delete own blog_post content',
'edit own blog_post content'
);
break;
}
return $array_of_permissions;
}
/**
* Set up test.
*/
public function setUp() {
parent::setUp(
// Note that the test will only run for the components that are
// properly enabled here.
'content',
'fieldgroup',
'text',
'date_api',
'date',
'context',
'ctools',
'views',
'calendar_ical',
'content_copy',
'ctools',
'date',
'filefield',
'imageapi',
'imageapi_gd',
'imagecache',
'imagecache_profiles',
'imagecache_ui',
'imagefield',
'install_profile_api',
'menu',
'messaging',
'messaging_phpmailer',
'nodeaccess',
'nodereference',
'userreference',
'number',
'optionwidgets',
'path',
'pathauto',
'privatemsg',
'features',
'clientproject',
'clientproject_content_type'
);
// Run a features rebuild to ensure our feature is fully installed.
features_rebuild();
$admin = $this->get_roles_permissions('admin');
$this->admin_user = $this->drupalCreateUser($admin);
// Create a user with some basic permissions and log them in.
$staff = $this->get_roles_permissions('staff');
$this->staff = $this->drupalCreateUser($staff);
$featured_expert = $this->get_roles_permissions('featured_expert');
$this->featured_expert = $this->drupalCreateUser($featured_expert);
}
public function testFeaturesCreateNewsItem() {
$this->drupalLogin($this->staff);
// Create node to edit.
$node = $this->drupalCreateNode(array(
'type' => 'news_item'
));
//set the node url the url set
$test_page = 'node/' . $node->nid;
// Make sure we don't get a 401 unauthorized response when editing.
$this->drupalGet($test_page."/edit");
$this->assertResponse(200, t('User is allowed to edit any news item.'));
// Looking for title text in the page to determine whether we were
// successful opening edit form.
$this->assertText(t("@title", array('@title' => $node->title)), "Found title in edit form");
// Logout
$this->drupalLogout();
// retrieve the page as an anonymous user
$this->drupalGet($test_page);
//ensure anonymous users are able to view the created article by checking for
//created nodes title within the page
$this->assertText(t('@title',array('@title' => $node->title)), t('Check that anonymous users can view news items'));
}
public function testFeaturesCreateBlogpost() {
$this->drupalLogin($this->featured_expert);
// Create node to edit.
$node = $this->drupalCreateNode(array(
'type' => 'blog_post',
'body' => 'body copy for a blog post',
'title' => 'sample blog post title'
));
//set the node url the url set
$test_page = 'node/' . $node->nid;
// Make sure we don't get a 401 unauthorized response when editing.
$this->drupalGet($test_page."/edit");
$this->assertResponse(200, t('A featured_expert is allowed to edit their own content.'));
// Looking for title text in the page to determine whether we were
// successful opening edit form.
$this->assertText(t("@title", array('@title' => $node->title)), "Found title in edit form");
// Logout
$this->drupalLogout();
// retrieve the page as an anonymous user
$this->drupalGet($test_page);
//ensure anonymous users are able to view the created article by checking for
//created nodes title within the page
$this->assertText(t('@title',array('@title' => $node->title)), t('Check that anonymous users can view blog posts'));
}
}//end class
[13:53]:php ./scripts/run-tests.sh --verbose --class clientFeatureTestCase testFeaturesCreateNewsItem ; growlnotify -w -m "Tests have finished."
Drupal test run
---------------
Tests to be run:
- (clientFeatureTestCase)
Test run started: Fri, 30/07/2010 - 13:53
Test summary:
-------------
client feature 52 passes, 0 fails, and 0 exceptions
Test run duration: 1 min 36 sec
Detailed test results:
----------------------
---- clientFeatureTestCase ----
Pass System client_feature.test 125
Starting run with db_prefix simpletest672463
Pass Role client_feature.test 145
Created role of name: s672463gV319PPv, id: 3
Pass Role client_feature.test 145
Created permissions: access administration pages, administer features,
administer content types, administer comments, administer permissions,
administer users, create news_item content
Pass User login client_feature.test 145
User created with name s672463KZ939vjL and pass c9LQpLEcQi
Pass Role client_feature.test 151
Created role of name: s672463kbGYP1KP, id: 4
Pass Role client_feature.test 151
Created permissions: access administration pages, administer comments,
administer users, create news_item content, edit any news_item content,
delete any news_item content
Pass User login client_feature.test 151
User created with name s672463v2o9jRqL and pass H2LRR8Zj7X
Pass Role client_feature.test 155
Created role of name: s672463zSwQt0CX, id: 5
Pass Role client_feature.test 155
Created permissions: access administration pages, create blog_post content,
delete own blog_post content, edit own blog_post content
Pass User login client_feature.test 155
User created with name s672463MAvL1qPU and pass m4q9r4vz4U
Pass Browser client_feature.test 165
GET http://client.employer.local/user returned 200 (4.85 KB).
Pass Browser client_feature.test 165
Valid HTML found on "http://client.employer.local/user"
Pass Browser client_feature.test 165
POST http://client.employer.local/user returned 200 (4.57 KB).
Pass Browser client_feature.test 165
Valid HTML found on "http://client.employer.local/users/s672463v2o9jrql"
Pass User login client_feature.test 165
User s672463v2o9jRqL successfully logged in.
Pass Browser client_feature.test 176
GET http://client.employer.local/node/1/edit returned 200 (13.03 KB).
Pass Browser client_feature.test 176
Valid HTML found on "http://client.employer.local/node/1/edit"
Pass Browser client_feature.test 177
User is allowed to edit any news item.
Pass Other client_feature.test 180
Found title in edit form
Pass Browser client_feature.test 183
GET http://client.employer.local/logout?destination=user returned 200 (4.85
KB).
Pass Browser client_feature.test 183
Valid HTML found on "http://client.employer.local/user"
Pass Logout client_feature.test 183
Username field found.
Pass Logout client_feature.test 183
Password field found.
Pass Browser client_feature.test 185
GET http://client.employer.local/content/s672463bnm3ji1h returned 200 (5.57
KB).
Pass Browser client_feature.test 185
Valid HTML found on "http://client.employer.local/content/s672463bnm3ji1h"
Pass Other client_feature.test 189
Check that anonymous users can view news items
Pass System client_feature.test 125
Starting run with db_prefix simpletest483404
Pass Role client_feature.test 145
Created role of name: s483404xKQWx1oW, id: 3
Pass Role client_feature.test 145
Created permissions: access administration pages, administer features,
administer content types, administer comments, administer permissions,
administer users, create news_item content
Pass User login client_feature.test 145
User created with name s483404PMwfUneE and pass s6BLKSuzWX
Pass Role client_feature.test 151
Created role of name: s483404DFgC9jN1, id: 4
Pass Role client_feature.test 151
Created permissions: access administration pages, administer comments,
administer users, create news_item content, edit any news_item content,
delete any news_item content
Pass User login client_feature.test 151
User created with name s483404qlmOhT4b and pass wfhYsmRRiE
Pass Role client_feature.test 155
Created role of name: s4834045x5tfxeI, id: 5
Pass Role client_feature.test 155
Created permissions: access administration pages, create blog_post content,
delete own blog_post content, edit own blog_post content
Pass User login client_feature.test 155
User created with name s483404nlhJa9J1 and pass Jps8J6aYrh
Pass Browser client_feature.test 194
GET http://client.employer.local/user returned 200 (4.85 KB).
Pass Browser client_feature.test 194
Valid HTML found on "http://client.employer.local/user"
Pass Browser client_feature.test 194
POST http://client.employer.local/user returned 200 (4.57 KB).
Pass Browser client_feature.test 194
Valid HTML found on "http://client.employer.local/users/s483404nlhja9j1"
Pass User login client_feature.test 194
User s483404nlhJa9J1 successfully logged in.
Pass Browser client_feature.test 207
GET http://client.employer.local/node/1/edit returned 200 (7.21 KB).
Pass Browser client_feature.test 207
Valid HTML found on "http://client.employer.local/node/1/edit"
Pass Browser client_feature.test 208
A featured_expert is allowed to edit their own content.
Pass Other client_feature.test 211
Found title in edit form
Pass Browser client_feature.test 214
GET http://client.employer.local/logout?destination=user returned 200 (4.85
KB).
Pass Browser client_feature.test 214
Valid HTML found on "http://client.employer.local/user"
Pass Logout client_feature.test 214
Username field found.
Pass Logout client_feature.test 214
Password field found.
Pass Browser client_feature.test 216
GET http://client.employer.local/content/sample-blog-post-title returned 200
(5.58 KB).
Pass Browser client_feature.test 216
Valid HTML found on
"http://client.employer.local/content/sample-blog-post-title"
Pass Other client_feature.test 220
Check that anonymous users can view blog posts
php ./scripts/run-tests.sh --verbose --class clientFeatureTestCase 57.91s user 16.95s system 76% cpu 1:37.55 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment