Skip to content

Commit

Permalink
Test for user roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
k-kojak committed Apr 11, 2012
1 parent cd1f943 commit 4506cf3
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion patterns.info
Expand Up @@ -28,5 +28,5 @@ files[] = tests/node/content.test
files[] = tests/node/node.test
files[] = tests/toolbar/toolbar.test
files[] = tests/shortcut/shortcut.test
;files[] = tests/user/user.test
files[] = tests/user/user.test

65 changes: 58 additions & 7 deletions tests/user/user.test
Expand Up @@ -18,17 +18,67 @@ class PatternsUserTestCase extends PatternRunTestCase {
}

public function testCreateModifyDelete() {
$this->testCreate();
// $this->testModify();
// $this->testDelete();
$this->testRoleCreate();
$this->testRoleModify();
$this->testRoleDelete();
// $this->testCreate();
// $this->testModify();
// $this->testDelete();
}

private function testRoleCreate() {
// The role should not exist at this point.
$role_count = db_select('role', 'r')
->fields('r', array('rid'))
->condition('name', 'test_role')
->countQuery()->execute()->fetchField();
$this->assertIdentical($role_count, '0', t('The role should not exist at this point.'));

// Run the pattern.
parent::runFile('user_role_create.yaml', 'Role (create)', PatternsUserTestCase::USER_TESTS_DIR);

$this->assertUniqueText(t('The role has been added.'));

$role_count = db_select('role', 'r')
->fields('r', array('name'))
->condition('name', 'test_role')
->countQuery()->execute()->fetchField();
$this->assertIdentical($role_count, '1', t('The test role should exist at this point.'));
}

private function testRoleModify() {
// Run the pattern.
parent::runFile('user_role_modify.yaml', 'Role (modify)', PatternsUserTestCase::USER_TESTS_DIR);

// The role should exist with the modified values.
$role_count = db_select('role', 'r')
->fields('r', array('name'))
->condition('name', 'test_role_mod')
->condition('weight', '10')
->countQuery()->execute()->fetchField();
$this->assertIdentical($role_count, '1', t('The role should exist with the modified values.'));
}

private function testRoleDelete() {
// Run the pattern.
parent::runFile('user_role_delete.yaml', 'Role (delete)', PatternsUserTestCase::USER_TESTS_DIR);

// The role should not exist at this point.
$role_count = db_select('role', 'r')
->fields('r', array('name'))
->condition('name', 'test_role_mod')
->countQuery()->execute()->fetchField();
$this->assertIdentical($role_count, '0', t('The role should not exist at this point.'));
}

private function testCreate() {
// The user should not exist at this point.

$user_count = db_select('users', 'u')
->fields('u', array('uid'))
->condition('uid', 'test_uid')
->condition('name', 'test_uid')
->countQuery()->execute()->fetchField();

$this->assertIdentical($user_count, '0', t('The user should not exist at this point.'));

// Run the pattern.
Expand All @@ -40,9 +90,10 @@ class PatternsUserTestCase extends PatternRunTestCase {
// The user should exist with the right values.
$user = db_select('users', 'u')
->fields('u', array('uid'))
->condition('uid', 'test_uid')
->execute()->fetchField();
$this->assertIdentical(count($user), 1);
->condition('name', 'test_uid')
->countQuery()->execute()->fetchField();
$this->verbose('usercount: ' . $user);
$this->assertIdentical($user, 1, t('The test user should exist at this point.'));
// TODO: Check fields.
}

Expand Down
17 changes: 17 additions & 0 deletions tests/user/user_role_create.yaml
@@ -0,0 +1,17 @@
# YAML User Pattern
# QScience

info:
title: Role (create)
description: Creates a new role
author: QScience
category: Users
version: 1.0
core: 7.x
author_website: http://qlectives.eu/

actions:
- create:
tag: role
name: test_role
weight: 8
16 changes: 16 additions & 0 deletions tests/user/user_role_delete.yaml
@@ -0,0 +1,16 @@
# YAML User Pattern
# QScience

info:
title: Role (delete)
description: Removes the test role
author: QScience
category: Users
version: 1.0
core: 7.x
author_website: http://qlectives.eu/

actions:
- delete:
tag: role
rid: test_role_mod
18 changes: 18 additions & 0 deletions tests/user/user_role_modify.yaml
@@ -0,0 +1,18 @@
# YAML User Pattern
# QScience

info:
title: Role (modify)
description: Modifies the test role
author: QScience
category: Users
version: 1.0
core: 7.x
author_website: http://qlectives.eu/

actions:
- modify:
tag: role
rid: test_role
name: test_role_mod
weight: 10

0 comments on commit 4506cf3

Please sign in to comment.