Commit 537cc876 authored by alexpott's avatar alexpott

Issue #2333731 by Berdir: Fixed WebTestBase::drupalCreateNode() should not hardcode default values.

parent a1f0ff2d
......@@ -88,7 +88,7 @@ public function testUsersWithoutPermission() {
$this->assertRaw('<p>Do you also love Drupal?</p><figure class="caption caption-img"><img src="druplicon.png" /><figcaption>Druplicon</figcaption></figure>');
// Retrieving the untransformed text should result in an empty 403 response.
$response = $this->drupalPost('editor/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', array());
$response = $this->drupalPost('editor/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', array());
$this->assertResponse(403);
// @todo Uncomment the below once https://drupal.org/node/2063303 is fixed.
// $this->assertIdentical('[]', $response);
......@@ -106,7 +106,7 @@ public function testUserWithPermission() {
// Ensure the text is transformed.
$this->assertRaw('<p>Do you also love Drupal?</p><figure class="caption caption-img"><img src="druplicon.png" /><figcaption>Druplicon</figcaption></figure>');
$response = $this->drupalPost('editor/' . 'node/1/body/und/full', 'application/vnd.drupal-ajax', array());
$response = $this->drupalPost('editor/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', array());
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The untransformed text POST request results in one AJAX command.');
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Tests;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
/**
* Tests node access functionality with multiple languages and two node access
......@@ -171,18 +172,22 @@ protected function setUp() {
$this->nodes['public_no_language_private'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 1)),
'private' => FALSE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->nodes['public_no_language_public'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 0)),
'private' => FALSE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->nodes['private_no_language_private'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 1)),
'private' => TRUE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->nodes['private_no_language_public'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 1)),
'private' => TRUE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\node\Tests;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
/**
* Tests node_access and db_select() with node_access tag functionality with
......@@ -134,9 +135,11 @@ protected function setUp() {
$this->nodes['no_language_public'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 0)),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->nodes['no_language_private'] = $this->drupalCreateNode(array(
'field_private' => array(array('value' => 1)),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
}
......
......@@ -79,7 +79,10 @@ function testNodeAccess() {
// Creating a public node with no special langcode, like when no language
// module enabled.
$node_public_no_language = $this->drupalCreateNode(array('private' => FALSE));
$node_public_no_language = $this->drupalCreateNode(array(
'private' => FALSE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->assertTrue($node_public_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.');
// Tests that access is granted if requested with no language.
......@@ -169,7 +172,10 @@ function testNodeAccessPrivate() {
// Creating a private node with no special langcode, like when no language
// module enabled.
$node_private_no_language = $this->drupalCreateNode(array('private' => TRUE));
$node_private_no_language = $this->drupalCreateNode(array(
'private' => TRUE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->assertTrue($node_private_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.');
// Tests that access is not granted if requested with no language.
......@@ -242,7 +248,10 @@ function testNodeAccessQueryTag() {
// Creating a public node with no special langcode, like when no language
// module enabled.
$node_no_language = $this->drupalCreateNode(array('private' => FALSE));
$node_no_language = $this->drupalCreateNode(array(
'private' => FALSE,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$this->assertTrue($node_no_language->language()->id == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.');
// Query the nodes table as the web user with the node access tag and no
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\Tests\ContentTranslationUITest;
use Drupal\Core\Language\LanguageInterface;
/**
* Tests the Node Translation UI.
......@@ -208,7 +209,10 @@ public function testDisabledBundle() {
$this->drupalCreateContentType(array('type' => $disabledBundle, 'name' => $disabledBundle));
// Create a node for each bundle.
$node = $this->drupalCreateNode(array('type' => $this->bundle));
$node = $this->drupalCreateNode(array(
'type' => $this->bundle,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
// Make sure that nothing was inserted into the {content_translation} table.
$rows = db_query('SELECT * FROM {content_translation}')->fetchAll();
......
......@@ -27,7 +27,9 @@ class BulkFormTest extends NodeTestBase {
*/
public function testBulkForm() {
$this->drupalLogin($this->drupalCreateUser(array('administer nodes')));
$node = $this->drupalCreateNode();
$node = $this->drupalCreateNode(array(
'promote' => FALSE,
));
$this->drupalGet('test-node-bulk-form');
$elements = $this->xpath('//select[@id="edit-action"]//option');
......
......@@ -134,7 +134,7 @@ protected function setUp() {
public function testAutocompleteQuickEdit() {
$this->drupalLogin($this->editor_user);
$quickedit_uri = 'quickedit/form/node/'. $this->node->id() . '/' . $this->field_name . '/und/full';
$quickedit_uri = 'quickedit/form/node/'. $this->node->id() . '/' . $this->field_name . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = Json::decode($response);
......@@ -164,7 +164,7 @@ public function testAutocompleteQuickEdit() {
$this->assertNoLink('new term');
// Load the form again, which should now get it back from TempStore.
$quickedit_uri = 'quickedit/form/node/'. $this->node->id() . '/' . $this->field_name . '/und/full';
$quickedit_uri = 'quickedit/form/node/'. $this->node->id() . '/' . $this->field_name . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$ajax_commands = Json::decode($response);
......
......@@ -56,6 +56,8 @@ public function testRankings() {
)),
'title' => 'Drupal rocks',
'body' => array(array('value' => "Drupal's search rocks")),
'sticky' => 0,
'promote' => 0,
);
foreach (array(0, 1) as $num) {
if ($num == 1) {
......
......@@ -225,16 +225,8 @@ function drupalGetNodeByTitle($title, $reset = FALSE) {
* );
* @endcode
* - title: Random string.
* - comment: CommentItemInterface::OPEN.
* - promote: NODE_NOT_PROMOTED.
* - log: Empty string.
* - status: NODE_PUBLISHED.
* - sticky: NODE_NOT_STICKY.
* - type: 'page'.
* - langcode: LanguageInterface::LANGCODE_NOT_SPECIFIED.
* - uid: The currently logged in user, or the user running test.
* - revision: 1. (Backwards-compatible binary flag indicating whether a
* new revision should be created; use 1 to specify a new revision.)
* - uid: The currently logged in user, or anonymous.
*
* @return \Drupal\node\NodeInterface
* The created node entity.
......@@ -242,44 +234,15 @@ function drupalGetNodeByTitle($title, $reset = FALSE) {
protected function drupalCreateNode(array $settings = array()) {
// Populate defaults array.
$settings += array(
'body' => array(array()),
'body' => array(array(
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
)),
'title' => $this->randomMachineName(8),
'promote' => NODE_NOT_PROMOTED,
'revision' => 1,
'log' => '',
'status' => NODE_PUBLISHED,
'sticky' => NODE_NOT_STICKY,
'type' => 'page',
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'uid' => \Drupal::currentUser()->id(),
);
// Use the original node's created time for existing nodes.
if (isset($settings['created']) && !isset($settings['date'])) {
$settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O');
}
// If the node's user uid is not specified manually, use the currently
// logged in user if available, or else the user running the test.
if (!isset($settings['uid'])) {
if ($this->loggedInUser) {
$settings['uid'] = $this->loggedInUser->id();
}
else {
$user = \Drupal::currentUser() ?: new AnonymousUserSession();
$settings['uid'] = $user->id();
}
}
// Merge body field value and format separately.
$settings['body'][0] += array(
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
);
$node = entity_create('node', $settings);
if (!empty($settings['revision'])) {
$node->setNewRevision();
}
$node->save();
return $node;
......
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