updated core to 8.6.2
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\node\Tests\Views;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on nodes.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeContextualLinksTest extends NodeTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['contextual'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_contextual_links'];
|
||||
|
||||
/**
|
||||
* Tests contextual links.
|
||||
*/
|
||||
public function testNodeContextualLinks() {
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode(['promote' => 1]);
|
||||
$this->drupalGet('node');
|
||||
|
||||
$user = $this->drupalCreateUser(['administer nodes', 'access contextual links']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$response = $this->renderContextualLinks(['node:node=1:'], 'node');
|
||||
$this->assertResponse(200);
|
||||
$json = Json::decode($response);
|
||||
$this->setRawContent($json['node:node=1:']);
|
||||
|
||||
// @todo Add these back when the functionality for making Views displays
|
||||
// appear in contextual links is working again.
|
||||
// $this->assertLinkByHref('node/1/contextual-links', 0, 'The contextual link to the view was found.');
|
||||
// $this->assertLink('Test contextual link', 0, 'The contextual link to the view was found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server-rendered contextual links for the given contextual link ids.
|
||||
*
|
||||
* Copied from \Drupal\contextual\Tests\ContextualDynamicContextTest::renderContextualLinks().
|
||||
*
|
||||
* @param array $ids
|
||||
* An array of contextual link ids.
|
||||
* @param string $current_path
|
||||
* The Drupal path for the page for which the contextual links are rendered.
|
||||
*
|
||||
* @return string
|
||||
* The response body.
|
||||
*/
|
||||
protected function renderContextualLinks($ids, $current_path) {
|
||||
// Build POST values.
|
||||
$post = [];
|
||||
for ($i = 0; $i < count($ids); $i++) {
|
||||
$post['ids[' . $i . ']'] = $ids[$i];
|
||||
}
|
||||
|
||||
// Serialize POST values.
|
||||
foreach ($post as $key => $value) {
|
||||
// Encode according to application/x-www-form-urlencoded
|
||||
// Both names and values needs to be urlencoded, according to
|
||||
// http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
|
||||
$post[$key] = urlencode($key) . '=' . urlencode($value);
|
||||
}
|
||||
$post = implode('&', $post);
|
||||
|
||||
// Perform HTTP request.
|
||||
return $this->curlExec([
|
||||
CURLOPT_URL => \Drupal::url('contextual.render', [], ['absolute' => TRUE, 'query' => ['destination' => $current_path]]),
|
||||
CURLOPT_POST => TRUE,
|
||||
CURLOPT_POSTFIELDS => $post,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Accept: application/json',
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the node page works if Contextual Links is disabled.
|
||||
*
|
||||
* All views have Contextual links enabled by default, even with the
|
||||
* Contextual links module disabled. This tests if no calls are done to the
|
||||
* Contextual links module by views when it is disabled.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2379811
|
||||
*/
|
||||
public function testPageWithDisabledContextualModule() {
|
||||
\Drupal::service('module_installer')->uninstall(['contextual']);
|
||||
\Drupal::service('module_installer')->install(['views_ui']);
|
||||
|
||||
// Ensure that contextual links don't get called for admin users.
|
||||
$admin_user = User::load(1);
|
||||
$admin_user->setPassword('new_password');
|
||||
$admin_user->pass_raw = 'new_password';
|
||||
$admin_user->save();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode(['promote' => 1]);
|
||||
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('node');
|
||||
}
|
||||
|
||||
}
|
||||
+1
-21
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
namespace Drupal\Tests\node\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
@@ -158,17 +158,6 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||
// Confirm that this is the default revision.
|
||||
$this->assertTrue($node->isDefaultRevision(), 'Third node revision is the default one.');
|
||||
|
||||
// Confirm that the "Edit" and "Delete" contextual links appear for the
|
||||
// default revision.
|
||||
$ids = ['node:node=' . $node->id() . ':changed=' . $node->getChangedTime()];
|
||||
$json = $this->renderContextualLinks($ids, 'node/' . $node->id());
|
||||
$this->verbose($json[$ids[0]]);
|
||||
|
||||
$expected = '<li class="entitynodeedit-form"><a href="' . base_path() . 'node/' . $node->id() . '/edit">Edit</a></li>';
|
||||
$this->assertTrue(strstr($json[$ids[0]], $expected), 'The "Edit" contextual link is shown for the default revision.');
|
||||
$expected = '<li class="entitynodedelete-form"><a href="' . base_path() . 'node/' . $node->id() . '/delete">Delete</a></li>';
|
||||
$this->assertTrue(strstr($json[$ids[0]], $expected), 'The "Delete" contextual link is shown for the default revision.');
|
||||
|
||||
// Confirm that revisions revert properly.
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", [], t('Revert'));
|
||||
$this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [
|
||||
@@ -188,15 +177,6 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||
$node = node_revision_load($node->getRevisionId());
|
||||
$this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.');
|
||||
|
||||
// Confirm that "Edit" and "Delete" contextual links don't appear for
|
||||
// non-default revision.
|
||||
$ids = ['node_revision::node=' . $node->id() . '&node_revision=' . $node->getRevisionId() . ':'];
|
||||
$json = $this->renderContextualLinks($ids, 'node/' . $node->id() . '/revisions/' . $node->getRevisionId() . '/view');
|
||||
$this->verbose($json[$ids[0]]);
|
||||
|
||||
$this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodeedit-form">'), 'The "Edit" contextual link is not shown for a non-default revision.');
|
||||
$this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodedelete-form">'), 'The "Delete" contextual link is not shown for a non-default revision.');
|
||||
|
||||
// Confirm revisions delete properly.
|
||||
$this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete'));
|
||||
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', [
|
||||
+14
-11
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
namespace Drupal\Tests\node\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
|
||||
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Ensures that node type functions work correctly.
|
||||
@@ -15,6 +16,7 @@ use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;
|
||||
class NodeTypeTest extends NodeTestBase {
|
||||
|
||||
use AssertBreadcrumbTrait;
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -87,6 +89,7 @@ class NodeTypeTest extends NodeTestBase {
|
||||
* Tests editing a node type using the UI.
|
||||
*/
|
||||
public function testNodeTypeEditing() {
|
||||
$assert = $this->assertSession();
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
$web_user = $this->drupalCreateUser(['bypass node access', 'administer content types', 'administer node fields']);
|
||||
$this->drupalLogin($web_user);
|
||||
@@ -96,8 +99,8 @@ class NodeTypeTest extends NodeTestBase {
|
||||
|
||||
// Verify that title and body fields are displayed.
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertRaw('Title', 'Title field was found.');
|
||||
$this->assertRaw('Body', 'Body field was found.');
|
||||
$assert->pageTextContains('Title');
|
||||
$assert->pageTextContains('Body');
|
||||
|
||||
// Rename the title field.
|
||||
$edit = [
|
||||
@@ -106,8 +109,8 @@ class NodeTypeTest extends NodeTestBase {
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertRaw('Foo', 'New title label was displayed.');
|
||||
$this->assertNoRaw('Title', 'Old title label was not displayed.');
|
||||
$assert->pageTextContains('Foo');
|
||||
$assert->pageTextNotContains('Title');
|
||||
|
||||
// Change the name and the description.
|
||||
$edit = [
|
||||
@@ -117,11 +120,11 @@ class NodeTypeTest extends NodeTestBase {
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
|
||||
$this->drupalGet('node/add');
|
||||
$this->assertRaw('Bar', 'New name was displayed.');
|
||||
$this->assertRaw('Lorem ipsum', 'New description was displayed.');
|
||||
$assert->pageTextContains('Bar');
|
||||
$assert->pageTextContains('Lorem ipsum');
|
||||
$this->clickLink('Bar');
|
||||
$this->assertRaw('Foo', 'Title field was found.');
|
||||
$this->assertRaw('Body', 'Body field was found.');
|
||||
$assert->pageTextContains('Foo');
|
||||
$assert->pageTextContains('Body');
|
||||
|
||||
// Change the name through the API
|
||||
/** @var \Drupal\node\NodeTypeInterface $node_type */
|
||||
@@ -146,7 +149,7 @@ class NodeTypeTest extends NodeTestBase {
|
||||
]);
|
||||
// Check that the body field doesn't exist.
|
||||
$this->drupalGet('node/add/page');
|
||||
$this->assertNoRaw('Body', 'Body field was not found.');
|
||||
$assert->pageTextNotContains('Body');
|
||||
}
|
||||
|
||||
/**
|
||||
+11
-6
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\node\Tests;
|
||||
namespace Drupal\Tests\node\Functional;
|
||||
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
@@ -12,6 +12,7 @@ use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests the node entity preview functionality.
|
||||
@@ -22,6 +23,9 @@ class PagePreviewTest extends NodeTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
use CommentTestTrait;
|
||||
use TestFileCreationTrait {
|
||||
getTestFiles as drupalGetTestFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the comment, node and taxonomy modules to test on the preview.
|
||||
@@ -177,7 +181,8 @@ class PagePreviewTest extends NodeTestBase {
|
||||
$this->drupalPostForm(NULL, ['field_image[0][alt]' => 'Picture of llamas'], t('Preview'));
|
||||
|
||||
// Check that the preview is displaying the title, body and term.
|
||||
$this->assertTitle(t('@title | Drupal', ['@title' => $edit[$title_key]]), 'Basic page title is preview.');
|
||||
$expected_title = $edit[$title_key] . ' | Drupal';
|
||||
$this->assertSession()->titleEquals($expected_title);
|
||||
$this->assertEscaped($edit[$title_key], 'Title displayed and escaped.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
@@ -210,13 +215,13 @@ class PagePreviewTest extends NodeTestBase {
|
||||
$this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
|
||||
$this->assertFieldByName($term_key, $edit[$term_key], 'Term field displayed.');
|
||||
$this->assertFieldByName('field_image[0][alt]', 'Picture of llamas');
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')], NULL, [], [], 'node-page-form');
|
||||
$this->getSession()->getPage()->pressButton('Add another item');
|
||||
$this->assertFieldByName('field_test_multi[0][value]');
|
||||
$this->assertFieldByName('field_test_multi[1][value]');
|
||||
|
||||
// Return to page preview to check everything is as expected.
|
||||
$this->drupalPostForm(NULL, [], t('Preview'));
|
||||
$this->assertTitle(t('@title | Drupal', ['@title' => $edit[$title_key]]), 'Basic page title is preview.');
|
||||
$this->assertSession()->titleEquals($expected_title);
|
||||
$this->assertEscaped($edit[$title_key], 'Title displayed and escaped.');
|
||||
$this->assertText($edit[$body_key], 'Body displayed.');
|
||||
$this->assertText($edit[$term_key], 'Term displayed.');
|
||||
@@ -353,8 +358,8 @@ class PagePreviewTest extends NodeTestBase {
|
||||
$this->assertText('Basic page ' . $title . ' has been created.');
|
||||
$node = $this->drupalGetNodeByTitle($title);
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')]);
|
||||
$this->drupalPostAjaxForm(NULL, [], ['field_test_multi_add_more' => t('Add another item')]);
|
||||
$this->getSession()->getPage()->pressButton('Add another item');
|
||||
$this->getSession()->getPage()->pressButton('Add another item');
|
||||
$edit = [
|
||||
'field_test_multi[1][value]' => $example_text_2,
|
||||
'field_test_multi[2][value]' => $example_text_3,
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\node\Functional\Views;
|
||||
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on nodes.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class NodeContextualLinksTest extends NodeTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['contextual'];
|
||||
|
||||
/**
|
||||
* Tests if the node page works if Contextual Links is disabled.
|
||||
*
|
||||
* All views have Contextual links enabled by default, even with the
|
||||
* Contextual links module disabled. This tests if no calls are done to the
|
||||
* Contextual links module by views when it is disabled.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2379811
|
||||
*/
|
||||
public function testPageWithDisabledContextualModule() {
|
||||
\Drupal::service('module_installer')->uninstall(['contextual']);
|
||||
\Drupal::service('module_installer')->install(['views_ui']);
|
||||
|
||||
// Ensure that contextual links don't get called for admin users.
|
||||
$admin_user = User::load(1);
|
||||
$admin_user->setPassword('new_password');
|
||||
$admin_user->passRaw = 'new_password';
|
||||
$admin_user->save();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode(['promote' => 1]);
|
||||
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('node');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\node\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
|
||||
|
||||
/**
|
||||
* Create a node with revisions and test contextual links.
|
||||
*
|
||||
* @group node
|
||||
*/
|
||||
class ContextualLinksTest extends WebDriverTestBase {
|
||||
|
||||
use ContextualLinkClickTrait;
|
||||
|
||||
/**
|
||||
* An array of node revisions.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface[]
|
||||
*/
|
||||
protected $nodes;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'contextual'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType([
|
||||
'type' => 'page',
|
||||
'name' => 'Basic page',
|
||||
'display_submitted' => FALSE,
|
||||
]);
|
||||
|
||||
// Create initial node.
|
||||
$node = $this->drupalCreateNode();
|
||||
|
||||
$nodes = [];
|
||||
|
||||
// Get original node.
|
||||
$nodes[] = clone $node;
|
||||
|
||||
// Create two revisions.
|
||||
$revision_count = 2;
|
||||
for ($i = 0; $i < $revision_count; $i++) {
|
||||
|
||||
// Create revision with a random title and body and update variables.
|
||||
$node->title = $this->randomMachineName();
|
||||
$node->body = [
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
];
|
||||
$node->setNewRevision();
|
||||
|
||||
$node->save();
|
||||
|
||||
// Make sure we get revision information.
|
||||
$node = Node::load($node->id());
|
||||
$nodes[] = clone $node;
|
||||
}
|
||||
|
||||
$this->nodes = $nodes;
|
||||
|
||||
$this->drupalLogin($this->createUser(
|
||||
[
|
||||
'view page revisions',
|
||||
'revert page revisions',
|
||||
'delete page revisions',
|
||||
'edit any page content',
|
||||
'delete any page content',
|
||||
'access contextual links',
|
||||
'administer content types',
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the contextual links on revisions.
|
||||
*/
|
||||
public function testRevisionContextualLinks() {
|
||||
// Confirm that the "Edit" and "Delete" contextual links appear for the
|
||||
// default revision.
|
||||
$this->drupalGet('node/' . $this->nodes[0]->id());
|
||||
$page = $this->getSession()->getPage();
|
||||
$page->waitFor(10, function () use ($page) {
|
||||
return $page->find('css', "main .contextual");
|
||||
});
|
||||
|
||||
$this->toggleContextualTriggerVisibility('main');
|
||||
$page->find('css', 'main .contextual button')->press();
|
||||
$links = $page->findAll('css', "main .contextual-links li a");
|
||||
|
||||
$this->assertEquals('Edit', $links[0]->getText());
|
||||
$this->assertEquals('Delete', $links[1]->getText());
|
||||
|
||||
// Confirm that "Edit" and "Delete" contextual links don't appear for
|
||||
// non-default revision.
|
||||
$this->drupalGet("node/" . $this->nodes[0]->id() . "/revisions/" . $this->nodes[1]->getRevisionId() . "/view");
|
||||
$this->assertSession()->pageTextContains($this->nodes[1]->getTitle());
|
||||
$page->waitFor(10, function () use ($page) {
|
||||
return $page->find('css', "main .contextual");
|
||||
});
|
||||
|
||||
$this->toggleContextualTriggerVisibility('main');
|
||||
$contextual_button = $page->find('css', 'main .contextual button');
|
||||
$this->assertEmpty(0, $contextual_button);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user