class ProtectedNodeViewMode in Protected Node 1.0.x
Same name and namespace in other branches
- 7 tests/protected_node.view_mode.test \ProtectedNodeViewMode
Configure protected_node to use per node password.
Hierarchy
- class \ProtectedNodeBaseTestCase extends \DrupalWebTestCase
- class \ProtectedNodeViewMode
Expanded class hierarchy of ProtectedNodeViewMode
File
- tests/
protected_node.view_mode.test, line 11 - Test protected node view mode functionality.
View source
class ProtectedNodeViewMode extends ProtectedNodeBaseTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Protected node view mode feature',
'description' => "This tests view mode feature in case of per node protection",
'group' => 'Protected Node',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Log in an Admin.
$this
->drupalLogin($this->adminUser);
// Submit the configuration form.
$protected_node_settings = array(
'protected_node_use_global_password' => PROTECTED_NODE_PER_NODE_PASSWORD,
'protected_node_checked_view_modes[]' => 'full',
);
$this
->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));
}
/**
* Test function.
*
* Test that a promoted protected node can be seen on the front page
* (unprotected view mode: teaser) by an authorized user.
*/
public function testAllowedView() {
// Log in as Admin.
$this
->drupalLogin($this->adminUser);
// Generate random password.
$password = $this
->randomName(10);
// Create a new page node.
$node = $this
->createPromotedProtectedNode($password);
// Once the node created logout the user.
$this
->drupalLogout();
// An authenticated user sees the node.
$this
->drupalLogin($this->normalAccessAllowedUser);
$this
->drupalGet('');
$text = $node->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with right permission can access a protected node without password in an unprotected view mode", $this->group);
}
/**
* Test function.
*
* Test that a promoted protected node can be seen on the front page
* (unprotected view mode: teaser) by an authenticated but not allowed user.
*/
public function testNotAllowedView() {
// Log in as Admin.
$this
->drupalLogin($this->adminUser);
// Generate random password.
$password = $this
->randomName(10);
// Create a new page node.
$node = $this
->createPromotedProtectedNode($password);
// Once the node created logout the user.
$this
->drupalLogout();
// User that can see published content sees the node.
$this
->drupalLogin($this->normalNonAccessAllowedUser);
$this
->drupalGet('');
$text = $node->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with no access permission is allowed to access a protected node in an unprotected view mode", $this->group);
}
/**
* Helper method to create a promoted protected node.
*
* Please make sure the user has the permission to create the node before
* calling the method.
*
* @param string $password
* A password.
*
* @return object
* A node object.
*/
public function createPromotedProtectedNode($password) {
// Add a new promoted page node that is protected.
$node_title = $this
->randomName(8);
$node_data = array(
'title' => $node_title,
'body[und][0][value]' => $this
->randomName(32),
'protected_node_is_protected' => TRUE,
'protected_node_passwd[pass1]' => $password,
'protected_node_passwd[pass2]' => $password,
'promote' => TRUE,
);
$this
->drupalPost('node/add/page', $node_data, t('Save'));
return $this
->drupalGetNodeByTitle($node_title);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProtectedNodeViewMode:: |
public | function | Helper method to create a promoted protected node. | |
ProtectedNodeViewMode:: |
public static | function | ||
ProtectedNodeViewMode:: |
public | function |
Prepare users for protected node's tests. Overrides ProtectedNodeBaseTestCase:: |
|
ProtectedNodeViewMode:: |
public | function | Test function. | |
ProtectedNodeViewMode:: |
public | function | Test function. |