Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
|
@ -1,16 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Tests\DateTimeFieldTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Tests;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
|
|
@ -77,18 +75,18 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = entity_create('field_storage_config', array(
|
||||
$this->fieldStorage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'datetime',
|
||||
'settings' => array('datetime_type' => 'date'),
|
||||
));
|
||||
$this->fieldStorage->save();
|
||||
$this->field = entity_create('field_config', array(
|
||||
$this->field = FieldConfig::create([
|
||||
'field_storage' => $this->fieldStorage,
|
||||
'bundle' => 'entity_test',
|
||||
'required' => TRUE,
|
||||
));
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')
|
||||
|
|
@ -624,7 +622,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
|
||||
// Create a field storage with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_storage = entity_create('field_storage_config', array(
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'datetime',
|
||||
|
|
@ -632,10 +630,10 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
));
|
||||
$field_storage->save();
|
||||
|
||||
$field = entity_create('field_config', array(
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'date_content',
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Set now as default_value.
|
||||
|
|
@ -657,7 +655,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
// Create a new node to check that datetime field default value is today.
|
||||
$new_node = entity_create('node', array('type' => 'date_content'));
|
||||
$new_node = Node::create(['type' => 'date_content']);
|
||||
$expected_date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE);
|
||||
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
|
||||
|
||||
|
|
@ -690,7 +688,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
// Create a new node to check that datetime field default value is +90 days.
|
||||
$new_node = entity_create('node', array('type' => 'date_content'));
|
||||
$new_node = Node::create(['type' => 'date_content']);
|
||||
$expected_date = new DrupalDateTime('+90 days', DATETIME_STORAGE_TIMEZONE);
|
||||
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
|
||||
|
||||
|
|
@ -713,7 +711,7 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
// Create a new node to check that datetime field default value is not set.
|
||||
$new_node = entity_create('node', array('type' => 'date_content'));
|
||||
$new_node = Node::create(['type' => 'date_content']);
|
||||
$this->assertNull($new_node->get($field_name)->value, 'Default value is not set');
|
||||
}
|
||||
|
||||
|
|
@ -801,6 +799,48 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
$this->assertText('date is invalid', format_string('Invalid second value %time has been caught.', array('%time' => $time_value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that 'Date' field storage setting form is disabled if field has data.
|
||||
*/
|
||||
public function testDateStorageSettings() {
|
||||
// Create a test content type.
|
||||
$this->drupalCreateContentType(['type' => 'date_content']);
|
||||
|
||||
// Create a field storage with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'datetime',
|
||||
'settings' => [
|
||||
'datetime_type' => 'date',
|
||||
],
|
||||
]);
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'field_name' => $field_name,
|
||||
'bundle' => 'date_content',
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
entity_get_form_display('node', 'date_content', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'datetime_default',
|
||||
])
|
||||
->save();
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomString(),
|
||||
'body[0][value]' => $this->randomString(),
|
||||
$field_name . '[0][value][date]' => '2016-04-01',
|
||||
];
|
||||
$this->drupalPostForm('node/add/date_content', $edit, t('Save'));
|
||||
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
|
||||
$result = $this->xpath("//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]");
|
||||
$this->assertEqual(count($result), 1, "Changing datetime setting is disabled.");
|
||||
$this->assertText('There is data for this field in the database. The field settings can no longer be changed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a entity_test and sets the output in the internal browser.
|
||||
*
|
||||
|
|
|
|||
Reference in a new issue