class RecipeNodeAccessTest in Recipe 7.2
Same name and namespace in other branches
- 7 src/Tests/RecipeNodeAccessTest.php \Drupal\recipe\Tests\RecipeNodeAccessTest
Tests display of nodes in recipe lists for node access.
Hierarchy
- class \Drupal\recipe\Tests\RecipeNodeAccessTest extends \Drupal\recipe\Tests\DrupalWebTestCase
Expanded class hierarchy of RecipeNodeAccessTest
File
- src/
Tests/ RecipeNodeAccessTest.php, line 8
Namespace
Drupal\recipe\TestsView source
class RecipeNodeAccessTest extends \DrupalWebTestCase {
/**
* A user with administrative privileges.
*
* @var \stdClass
*/
protected $adminUser;
/**
* A node title.
*
* @var string
*/
protected $nodeTitle;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Recipe node access',
'description' => 'Tests display of nodes in recipe lists for node access.',
'group' => 'Recipe',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
// Enable modules required for testing.
parent::setUp(array(
'recipe',
'node_access_test',
));
// Create and log in the admin user with Recipe content permissions.
$this->adminUser = $this
->drupalCreateUser(array(
'create recipe content',
'edit own recipe content',
'administer blocks',
));
$this
->drupalLogin($this->adminUser);
// Set the variable to enable private nodes with node_access_test.
node_access_rebuild();
variable_set('node_access_test_private', TRUE);
// Create a test recipe node.
$this->nodeTitle = $this
->randomName(16);
$edit = array(
'title' => $this->nodeTitle,
'recipe_description[' . LANGUAGE_NONE . '][0][value]' => $this
->randomName(16),
'recipe_yield' => 1,
'private' => TRUE,
);
$this
->drupalPost('node/add/recipe', $edit, 'Save');
}
/**
* Tests node_access for nodes displayed in recipe lists.
*/
public function testRecentRecipeBoxNodeAccess() {
// Logout and assert that the anonymous user can't access the node.
$this
->drupalLogout();
$this
->drupalGet('node/1');
$this
->assertResponse(403);
// Assert that a link to the test recipe can't be seen at /recipe.
$this
->drupalGet('recipe');
$this
->assertNoLink($this->nodeTitle);
// Log in as the admin_user and set the recipe node as public.
$this
->drupalLogin($this->adminUser);
$edit = array(
'private' => FALSE,
);
$this
->drupalPost('node/1/edit', $edit, 'Save');
// Logout and assert that the anonymous user can access the node.
$this
->drupalLogout();
$this
->drupalGet('node/1');
$this
->assertResponse(200);
// Logout and assert that a link to the test recipe can be seen at /recipe.
$this
->drupalGet('recipe');
$this
->assertLink($this->nodeTitle);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RecipeNodeAccessTest:: |
protected | property | A user with administrative privileges. | |
RecipeNodeAccessTest:: |
protected | property | A node title. | |
RecipeNodeAccessTest:: |
public static | function | ||
RecipeNodeAccessTest:: |
public | function | ||
RecipeNodeAccessTest:: |
public | function | Tests node_access for nodes displayed in recipe lists. |