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:
Pantheon Automation 2016-04-20 09:56:34 -07:00 committed by Greg Anderson
parent b11a755ba8
commit c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions

View file

@ -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.
*

View file

@ -1,125 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\DateTimeItemTest.
*/
namespace Drupal\datetime\Tests;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\field\Tests\FieldUnitTestBase;
/**
* Tests the new entity API for the date field type.
*
* @group datetime
*/
class DateTimeItemTest extends FieldUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('datetime');
protected function setUp() {
parent::setUp();
// Create a field with settings to validate.
$field_storage = entity_create('field_storage_config', array(
'field_name' => 'field_datetime',
'type' => 'datetime',
'entity_type' => 'entity_test',
'settings' => array('datetime_type' => 'date'),
));
$field_storage->save();
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'settings' => array(
'default_value' => 'blank',
),
));
$field->save();
}
/**
* Tests using entity fields of the date field type.
*/
public function testDateTimeItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->field_datetime = $value;
$entity->name->value = $this->randomMachineName();
$entity->save();
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertTrue($entity->field_datetime instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_datetime[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_datetime->value, $value);
$this->assertEqual($entity->field_datetime[0]->value, $value);
// Verify changing the date value.
$new_value = $this->randomMachineName();
$entity->field_datetime->value = $new_value;
$this->assertEqual($entity->field_datetime->value, $new_value);
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_datetime->value, $new_value);
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity->field_datetime->generateSampleItems();
$this->entityValidateAndSave($entity);
}
/**
* Tests DateTimeItem::setValue().
*/
public function testSetValue() {
// Test DateTimeItem::setValue() using string.
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->get('field_datetime')->set(0, $value);
$entity->save();
// Load the entity and ensure the field was saved correctly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.');
// Test DateTimeItem::setValue() using property array.
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
$entity->save();
// Load the entity and ensure the field was saved correctly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with array value.');
}
/**
* Tests setting the value of the DateTimeItem directly.
*/
public function testSetValueProperty() {
// Test Date::setValue().
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
$entity->save();
// Load the entity and ensure the field was saved correctly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.');
}
}

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\Views\ArgumentDateTimeTest.
*/
namespace Drupal\datetime\Tests\Views;
use Drupal\views\Views;
@ -138,4 +133,71 @@ class ArgumentDateTimeTest extends DateTimeHandlerTestBase {
$view->destroy();
}
/**
* Test week WW argument.
*/
public function testDatetimeArgumentWeek() {
$view = Views::getView('test_argument_datetime');
// The 'embed_4' display has WW argument.
$view->setDisplay('embed_4');
$this->executeView($view, ['41']);
$expected = [];
$expected[] = ['nid' => $this->nodes[0]->id()];
$expected[] = ['nid' => $this->nodes[1]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
$view->setDisplay('embed_4');
$this->executeView($view, ['01']);
$expected = [];
$expected[] = ['nid' => $this->nodes[2]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
}
/**
* Test full_date CCYYMMDD argument.
*/
public function testDatetimeArgumentFullDate() {
$view = Views::getView('test_argument_datetime');
// The 'embed_5' display has CCYYMMDD argument.
$view->setDisplay('embed_5');
$this->executeView($view, ['20001010']);
$expected = [];
$expected[] = ['nid' => $this->nodes[0]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
$view->setDisplay('embed_5');
$this->executeView($view, ['20020101']);
$expected = [];
$expected[] = ['nid' => $this->nodes[2]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
}
/**
* Test year_month CCYYMM argument.
*/
public function testDatetimeArgumentYearMonth() {
$view = Views::getView('test_argument_datetime');
// The 'embed_6' display has CCYYMM argument.
$view->setDisplay('embed_6');
$this->executeView($view, ['200010']);
$expected = [];
$expected[] = ['nid' => $this->nodes[0]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
$view->setDisplay('embed_6');
$this->executeView($view, ['200201']);
$expected = [];
$expected[] = ['nid' => $this->nodes[2]->id()];
$this->assertIdenticalResultset($view, $expected, $this->map);
$view->destroy();
}
}

View file

@ -1,15 +1,13 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\Views\DateTimeHandlerTestBase.
*/
namespace Drupal\datetime\Tests\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\Handler\HandlerTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Base class for testing datetime handlers.
@ -44,19 +42,19 @@ abstract class DateTimeHandlerTestBase extends HandlerTestBase {
parent::setUp();
// Add a date field to page nodes.
$node_type = entity_create('node_type', [
$node_type = NodeType::create([
'type' => 'page',
'name' => 'page'
]);
$node_type->save();
$fieldStorage = entity_create('field_storage_config', [
$fieldStorage = FieldStorageConfig::create([
'field_name' => static::$field_name,
'entity_type' => 'node',
'type' => 'datetime',
'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
]);
$fieldStorage->save();
$field = entity_create('field_config', [
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => 'page',
'required' => TRUE,

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\Views\FilterDateTest.
*/
namespace Drupal\datetime\Tests\Views;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\field\Entity\FieldStorageConfig;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\Views\FilterDateTimeTest.
*/
namespace Drupal\datetime\Tests\Views;
use Drupal\views\Views;

View file

@ -1,10 +1,5 @@
<?php
/**
* @file
* Contains \Drupal\datetime\Tests\Views\SortDateTimeTest.
*/
namespace Drupal\datetime\Tests\Views;
use Drupal\views\Views;