Commit 1e5f2f7d authored by webchick's avatar webchick

Issue #2032553 by pwolanin, Xano: Fixed The _account attribute on the Request...

Issue #2032553 by pwolanin, Xano: Fixed The _account attribute on the Request is not available during web tests.
parent 1f219646
......@@ -118,7 +118,8 @@ public function testNodeHandler() {
// Test as a non-admin.
$normal_user = $this->drupalCreateUser(array('access content'));
$GLOBALS['user'] = $normal_user;
$request = $this->container->get('request');
$request->attributes->set('_account', $normal_user);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -170,7 +171,7 @@ public function testNodeHandler() {
// Test as an admin.
$admin_user = $this->drupalCreateUser(array('access content', 'bypass node access'));
$GLOBALS['user'] = $admin_user;
$request->attributes->set('_account', $admin_user);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -264,7 +265,8 @@ public function testUserHandler() {
}
// Test as a non-admin.
$GLOBALS['user'] = $users['non_admin'];
$request = $this->container->get('request');
$request->attributes->set('_account', $users['non_admin']);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -303,7 +305,7 @@ public function testUserHandler() {
);
$this->assertReferenceable($instance, $referenceable_tests, 'User handler');
$GLOBALS['user'] = $users['admin'];
$request->attributes->set('_account', $users['admin']);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -435,7 +437,8 @@ public function testCommentHandler() {
// Test as a non-admin.
$normal_user = $this->drupalCreateUser(array('access content', 'access comments'));
$GLOBALS['user'] = $normal_user;
$request = $this->container->get('request');
$request->attributes->set('_account', $normal_user);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -474,7 +477,7 @@ public function testCommentHandler() {
// Test as a comment admin.
$admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments'));
$GLOBALS['user'] = $admin_user;
$request->attributes->set('_account', $admin_user);
$referenceable_tests = array(
array(
'arguments' => array(
......@@ -492,7 +495,7 @@ public function testCommentHandler() {
// Test as a node and comment admin.
$admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments', 'bypass node access'));
$GLOBALS['user'] = $admin_user;
$request->attributes->set('_account', $admin_user);
$referenceable_tests = array(
array(
'arguments' => array(
......
......@@ -14,6 +14,7 @@
use Drupal\user\TempStoreFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a node deletion confirmation form.
......@@ -95,7 +96,7 @@ public function getConfirmText() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$this->nodes = $this->tempStoreFactory->get('node_multiple_delete_confirm')->get($GLOBALS['user']->id());
if (empty($this->nodes)) {
return new RedirectResponse(url($this->getCancelPath(), array('absolute' => TRUE)));
......@@ -107,7 +108,7 @@ public function buildForm(array $form, array &$form_state) {
return String::checkPlain($node->label());
}, $this->nodes),
);
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**
......
......@@ -40,16 +40,85 @@ public function testBulkForm() {
$elements = $this->xpath('//select[@id="edit-action"]//option');
$this->assertIdentical(count($elements), 8, 'All node operations are found.');
// Block a node using the bulk form.
$this->assertTrue($node->status);
// Unpublish a node using the bulk form.
$this->assertTrue($node->isPublished(), 'Node is initially published');
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_unpublish_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check their status.
$node = entity_load('node', $node->id());
$this->assertFalse($node->status);
// Re-load the node and check the status.
$node = entity_load('node', $node->id(), TRUE);
$this->assertFalse($node->isPublished(), 'Node has been unpublished');
// Publish action.
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_publish_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check the status.
$node = entity_load('node', $node->id(), TRUE);
$this->assertTrue($node->isPublished(), 'Node has been published');
// Make sticky action.
$node->setPublished(FALSE);
$node->save();
$this->assertFalse($node->isSticky(), 'Node is not sticky');
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_make_sticky_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check the status and sticky flag.
$node = entity_load('node', $node->id(), TRUE);
$this->assertTrue($node->isPublished(), 'Node has been published');
$this->assertTrue($node->isSticky(), 'Node has been made sticky');
// Make unsticky action.
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_make_unsticky_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check the sticky flag.
$node = entity_load('node', $node->id(), TRUE);
$this->assertFalse($node->isSticky(), 'Node is not sticky anymore');
// Promote to front page.
$node->setPublished(FALSE);
$node->save();
$this->assertFalse($node->isPromoted(), 'Node is not promoted to the front page');
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_promote_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check the status and promoted flag.
$node = entity_load('node', $node->id(), TRUE);
$this->assertTrue($node->isPublished(), 'Node has been published');
$this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page');
// Demote from front page.
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_unpromote_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
// Re-load the node and check the promoted flag.
$node = entity_load('node', $node->id(), TRUE);
$this->assertFalse($node->isPromoted(), 'Node has been demoted');
// Delete node.
$edit = array(
'node_bulk_form[0]' => TRUE,
'action' => 'node_delete_action',
);
$this->drupalPost(NULL, $edit, t('Apply'));
$this->drupalPost(NULL, array(), t('Delete'));
// Re-load the node and check if it has been deleted.
$node = entity_load('node', $node->id(), TRUE);
$this->assertNull($node, 'Node has been deleted');
}
}
......@@ -981,7 +981,7 @@ protected function prepareConfigDirectories() {
}
/**
* Rebuild drupal_container().
* Rebuild Drupal::getContainer().
*
* Use this to build a new kernel and service container. For example, when the
* list of enabled modules is changed via the internal browser, in which case
......@@ -992,16 +992,18 @@ protected function prepareConfigDirectories() {
* @see TestBase::tearDown()
*
* @todo Fix http://drupal.org/node/1708692 so that module enable/disable
* changes are immediately reflected in drupal_container(). Until then,
* changes are immediately reflected in Drupal::getContainer(). Until then,
* tests can invoke this workaround when requiring services from newly
* enabled modules to be immediately available in the same request.
*/
protected function rebuildContainer() {
$this->kernel = new DrupalKernel('testing', drupal_classloader(), FALSE);
$this->kernel->boot();
// DrupalKernel replaces the container in drupal_container() with a
// DrupalKernel replaces the container in Drupal::getContainer() with a
// different object, so we need to replace the instance on this test class.
$this->container = drupal_container();
$this->container = \Drupal::getContainer();
// The global $user is set in TestBase::prepareEnvironment().
$this->container->get('request')->attributes->set('_account', $GLOBALS['user']);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment