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
|
@ -26,8 +26,11 @@ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
|
|||
$arguments = [
|
||||
// Argument type => help text.
|
||||
'year' => t('Date in the form of YYYY.'),
|
||||
'month' => t('Date in the form of MM.'),
|
||||
'day' => t('Date in the form of DD.'),
|
||||
'month' => t('Date in the form of MM (01 - 12).'),
|
||||
'day' => t('Date in the form of DD (01 - 31).'),
|
||||
'week' => t('Date in the form of WW (01 - 53).'),
|
||||
'year_month' => t('Date in the form of YYYYMM.'),
|
||||
'full_date' => t('Date in the form of CCYYMMDD.'),
|
||||
];
|
||||
foreach ($arguments as $argument_type => $help_text) {
|
||||
$data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\DateTimeComputed.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeCustomFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
@ -84,7 +79,7 @@ class DateTimeCustomFormatter extends DateTimeFormatterBase {
|
|||
$form['date_format'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Date/time format'),
|
||||
'#description' => $this->t('See <a href=":url" target="_blank">the documentation for PHP date formats</a>.', [':url' => 'http://php.net/manual/function.date.php']),
|
||||
'#description' => $this->t('See <a href="http://php.net/manual/function.date.php" target="_blank">the documentation for PHP date formats</a>.'),
|
||||
'#default_value' => $this->getSetting('date_format'),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
|
@ -112,7 +108,7 @@ class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactory
|
|||
|
||||
foreach ($items as $delta => $item) {
|
||||
$date = $item->date;
|
||||
$output = '';
|
||||
$output = [];
|
||||
if (!empty($item->date)) {
|
||||
if ($this->getFieldSetting('datetime_type') == 'date') {
|
||||
// A date without time will pick up the current time, use the default.
|
||||
|
@ -120,7 +116,7 @@ class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactory
|
|||
}
|
||||
$output = $this->formatDate($date);
|
||||
}
|
||||
$elements[$delta] = array('#markup' => $output);
|
||||
$elements[$delta] = $output;
|
||||
}
|
||||
|
||||
return $elements;
|
||||
|
@ -176,20 +172,31 @@ class DateTimeTimeAgoFormatter extends FormatterBase implements ContainerFactory
|
|||
* @param \Drupal\Core\Datetime\DrupalDateTime|object $date
|
||||
* A date/time object.
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
* The formatted date/time string using the past or future format setting.
|
||||
*/
|
||||
protected function formatDate(DrupalDateTime $date) {
|
||||
$granularity = $this->getSetting('granularity');
|
||||
$timestamp = $date->getTimestamp();
|
||||
$options = ['granularity' => $granularity];
|
||||
$options = [
|
||||
'granularity' => $granularity,
|
||||
'return_as_object' => TRUE,
|
||||
];
|
||||
|
||||
if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
|
||||
return SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, $options)]);
|
||||
$result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
|
||||
$build = [
|
||||
'#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()]),
|
||||
];
|
||||
}
|
||||
else {
|
||||
return SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, $options)]);
|
||||
$result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
|
||||
$build = [
|
||||
'#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()]),
|
||||
];
|
||||
}
|
||||
CacheableMetadata::createFromObject($result)->applyTo($build);
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
@ -51,7 +46,7 @@ class DateTimeFieldItemList extends FieldItemList {
|
|||
'default_date' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Relative default value'),
|
||||
'#description' => t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See <a href=\"@url\">@strtotime</a> for more details.", array('@strtotime' => 'strtotime', '@url' => 'http://www.php.net/manual/en/function.strtotime.php')),
|
||||
'#description' => t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See <a href=\"http://php.net/manual/function.strtotime.php\">strtotime</a> for more details."),
|
||||
'#default_value' => (isset($default_value[0]['default_date_type']) && $default_value[0]['default_date_type'] == static::DEFAULT_VALUE_CUSTOM) ? $default_value[0]['default_date'] : '',
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldType\DateTimeItem.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
|
@ -97,6 +92,7 @@ class DateTimeItem extends FieldItemBase {
|
|||
static::DATETIME_TYPE_DATETIME => t('Date and time'),
|
||||
static::DATETIME_TYPE_DATE => t('Date only'),
|
||||
),
|
||||
'#disabled' => $has_data,
|
||||
);
|
||||
|
||||
return $element;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldWidget;
|
||||
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDefaultWidget.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldWidget;
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeWidgetBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\Field\FieldWidget;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\Argument\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\Argument;
|
||||
|
||||
use Drupal\views\Plugin\views\argument\Date as NumericDate;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\DayDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
|
|
17
core/modules/datetime/src/Plugin/views/argument/FullDate.php
Normal file
17
core/modules/datetime/src/Plugin/views/argument/FullDate.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a full date (CCYYMMDD).
|
||||
*
|
||||
* @ViewsArgument("datetime_full_date")
|
||||
*/
|
||||
class FullDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'Ymd';
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\MonthDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
|
|
17
core/modules/datetime/src/Plugin/views/argument/WeekDate.php
Normal file
17
core/modules/datetime/src/Plugin/views/argument/WeekDate.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a week.
|
||||
*
|
||||
* @ViewsArgument("datetime_week")
|
||||
*/
|
||||
class WeekDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'W';
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\argument\YearDate.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\argument;
|
||||
|
||||
/**
|
||||
* Argument handler for a year plus month (CCYYMM).
|
||||
*
|
||||
* @ViewsArgument("datetime_year_month")
|
||||
*/
|
||||
class YearMonthDate extends Date {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $argFormat = 'Ym';
|
||||
|
||||
}
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\filter\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\filter;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Plugin\views\sort\Date.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Plugin\views\sort;
|
||||
|
||||
use Drupal\views\Plugin\views\sort\Date as NumericDate;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Tests\Views\FilterDateTimeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Tests\Views\SortDateTimeTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
|
|
@ -97,3 +97,45 @@ display:
|
|||
id: embed_2
|
||||
display_title: ''
|
||||
position: null
|
||||
embed_4:
|
||||
display_options:
|
||||
defaults:
|
||||
arguments: false
|
||||
arguments:
|
||||
field_date_value_day:
|
||||
field: field_date_value_week
|
||||
id: field_date_value
|
||||
table: node__field_date
|
||||
plugin_id: datetime_week
|
||||
display_plugin: embed
|
||||
id: embed_4
|
||||
display_title: ''
|
||||
position: null
|
||||
embed_5:
|
||||
display_options:
|
||||
defaults:
|
||||
arguments: false
|
||||
arguments:
|
||||
field_date_value_day:
|
||||
field: field_date_value_full_date
|
||||
id: field_date_value
|
||||
table: node__field_date
|
||||
plugin_id: datetime_full_date
|
||||
display_plugin: embed
|
||||
id: embed_5
|
||||
display_title: ''
|
||||
position: null
|
||||
embed_6:
|
||||
display_options:
|
||||
defaults:
|
||||
arguments: false
|
||||
arguments:
|
||||
field_date_value_day:
|
||||
field: field_date_value_year_month
|
||||
id: field_date_value
|
||||
table: node__field_date
|
||||
plugin_id: datetime_year_month
|
||||
display_plugin: embed
|
||||
id: embed_6
|
||||
display_title: ''
|
||||
position: null
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\datetime\Tests\DateTimeItemTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\datetime\Tests;
|
||||
namespace Drupal\Tests\datetime\Kernel;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\field\Tests\FieldUnitTestBase;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the new entity API for the date field type.
|
||||
*
|
||||
* @group datetime
|
||||
*/
|
||||
class DateTimeItemTest extends FieldUnitTestBase {
|
||||
class DateTimeItemTest extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
|
@ -29,20 +27,20 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_storage = entity_create('field_storage_config', array(
|
||||
$field_storage = FieldStorageConfig::create(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 = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'entity_test',
|
||||
'settings' => array(
|
||||
'default_value' => 'blank',
|
||||
),
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
}
|
||||
|
||||
|
@ -51,7 +49,7 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
*/
|
||||
public function testDateTimeItem() {
|
||||
// Verify entity creation.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$value = '2014-01-01T20:00:00Z';
|
||||
$entity->field_datetime = $value;
|
||||
$entity->name->value = $this->randomMachineName();
|
||||
|
@ -76,7 +74,7 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
$this->assertEqual($entity->field_datetime->value, $new_value);
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$entity->field_datetime->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
@ -86,7 +84,7 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
*/
|
||||
public function testSetValue() {
|
||||
// Test DateTimeItem::setValue() using string.
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$value = '2014-01-01T20:00:00Z';
|
||||
$entity->get('field_datetime')->set(0, $value);
|
||||
$entity->save();
|
||||
|
@ -96,7 +94,7 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
$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');
|
||||
$entity = EntityTest::create();
|
||||
$value = '2014-01-01T20:00:00Z';
|
||||
$entity->set('field_datetime', $value);
|
||||
$entity->save();
|
||||
|
@ -111,7 +109,7 @@ class DateTimeItemTest extends FieldUnitTestBase {
|
|||
*/
|
||||
public function testSetValueProperty() {
|
||||
// Test Date::setValue().
|
||||
$entity = entity_create('entity_test');
|
||||
$entity = EntityTest::create();
|
||||
$value = '2014-01-01T20:00:00Z';
|
||||
|
||||
$entity->set('field_datetime', $value);
|
Reference in a new issue