Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\datetime\Kernel;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Drupal\Core\Form\FormInterface;
|
||||
use Drupal\Core\Form\FormState;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests serializing a form with an injected datetime instance.
|
||||
*
|
||||
* @group datetime
|
||||
*/
|
||||
class DateTimeFormInjectionTest extends KernelTestBase implements FormInterface {
|
||||
|
||||
use DependencySerializationTrait;
|
||||
|
||||
/**
|
||||
* A Dblog logger instance.
|
||||
*
|
||||
* @var \Psr\Log\LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system', 'datetime'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['key_value_expire', 'sequences']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'datetime_test_injection_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback.
|
||||
*
|
||||
* @param array $element
|
||||
* Form element.
|
||||
*
|
||||
* @return array
|
||||
* Processed element.
|
||||
*/
|
||||
public function process($element) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['datelist_element'] = [
|
||||
'#title' => 'datelist test',
|
||||
'#type' => 'datelist',
|
||||
'#default_value' => new DrupalDateTime('2000-01-01 00:00:00'),
|
||||
'#date_part_order' => [
|
||||
'month',
|
||||
'day',
|
||||
'year',
|
||||
'hour',
|
||||
'minute', 'ampm',
|
||||
],
|
||||
'#date_text_parts' => ['year'],
|
||||
'#date_year_range' => '2010:2020',
|
||||
'#date_increment' => 15,
|
||||
];
|
||||
$form['#process'][] = [$this, 'process'];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validateForm(array &$form, FormStateInterface $form_state) {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->assertTrue(TRUE);
|
||||
$form_state->setRebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests custom string injection serialization.
|
||||
*/
|
||||
public function testDatetimeSerialization() {
|
||||
$form_state = new FormState();
|
||||
$form_state->setRequestMethod('POST');
|
||||
$form_state->setCached();
|
||||
$form_builder = $this->container->get('form_builder');
|
||||
$form_id = $form_builder->getFormId($this, $form_state);
|
||||
$form = $form_builder->retrieveForm($form_id, $form_state);
|
||||
$form_builder->prepareForm($form_id, $form, $form_state);
|
||||
$form_builder->processForm($form_id, $form, $form_state);
|
||||
}
|
||||
|
||||
}
|
123
web/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
Normal file
123
web/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\datetime\Kernel;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
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 FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('datetime');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'field_datetime',
|
||||
'type' => 'datetime',
|
||||
'entity_type' => 'entity_test',
|
||||
'settings' => array('datetime_type' => 'date'),
|
||||
));
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'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 = EntityTest::create();
|
||||
$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 = EntityTest::load($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 = EntityTest::load($id);
|
||||
$this->assertEqual($entity->field_datetime->value, $new_value);
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$entity = EntityTest::create();
|
||||
$entity->field_datetime->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests DateTimeItem::setValue().
|
||||
*/
|
||||
public function testSetValue() {
|
||||
// Test DateTimeItem::setValue() using string.
|
||||
$entity = EntityTest::create();
|
||||
$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 = EntityTest::load($id);
|
||||
$this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.');
|
||||
|
||||
// Test DateTimeItem::setValue() using property array.
|
||||
$entity = EntityTest::create();
|
||||
$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 = EntityTest::load($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 = EntityTest::create();
|
||||
$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 = EntityTest::load($id);
|
||||
$this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.');
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue