public function PublishContentCheckboxTests::assertNodeOperationAccess in Publish Content 7
Perform a GET operation on a node.
This will check the response to access some operation via the URL of a node. In the case of 'publish' or 'unpublish' it will first visit the view of a node so that the relevant tabs can be generated.
Parameters
int $nid: The node nid
string $op: An operation such as 'view', 'edit', 'publish', 'unpublish'
int $expected_response: The expected response code. If the user should not be able to see the 'publish' or 'unpublish' tabs, set this to 403, otherwise 200.
string $msg: (optional) An assertion log message.
Overrides PublishContentWebTestBase::assertNodeOperationAccess
File
- tests/
publishcontent.test, line 688 - Unit tests for Publish Content module.
Class
- PublishContentCheckboxTests
- Test permissions with the tab method.
Code
public function assertNodeOperationAccess($nid, $op, $expected_response, $msg = '') {
if (in_array($op, array(
'publish',
'unpublish',
))) {
// Visit the edit page first to check for the published checkbox.
$this
->drupalGet("node/{$nid}/edit");
$view_response = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
if ($view_response != 200) {
$msg .= t('Could not edit the node. Response code: @response', array(
'@response' => $view_response,
));
$this
->assert($expected_response == $view_response, $msg);
return;
}
// Check the checkbox exists.
$elements = $this
->xpath('//input[@id=:id]', array(
':id' => 'edit-status',
));
if (!isset($elements[0])) {
// No checkboxes.
$msg .= t('Published status checkbox is not accessible.');
$this
->assert($expected_response != 200, $msg);
return;
}
// At this point the response code for checkboxes is irrelevant, if
// they can access the edit page and see the checkbox, they can edit it.
$expected_response = 200;
// Tick or untick the published checkbox and submit the form.
$edit_status = $op == 'publish';
$this
->drupalPost("node/{$nid}/edit", array(
'status' => $edit_status,
), t('Save'));
}
else {
$url = $op == 'view' ? "node/{$nid}" : "node/{$nid}/{$op}";
$this
->drupalGet($url);
}
$this
->assertResponse($expected_response, $msg);
}