caore d8 files

This commit is contained in:
Bachir Soussi Chiadmi
2016-09-06 12:44:15 +02:00
commit 58f46e4e8f
12831 changed files with 1451591 additions and 0 deletions
@@ -0,0 +1,14 @@
name: 'Datetime test'
type: module
description: 'Provides default views for tests.'
package: Testing
# version: VERSION
# core: 8.x
dependencies:
- views
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
core: '8.x'
project: 'drupal'
datestamp: 1470233790
@@ -0,0 +1,141 @@
langcode: und
status: true
dependencies: { }
id: test_argument_datetime
label: ''
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
defaults:
fields: false
pager: false
sorts: false
arguments:
field_date_value_year:
field: field_date_value_year
id: field_date_value
table: node__field_date
plugin_id: datetime_year
fields:
id:
field: nid
id: nid
relationship: none
table: node_field_data
plugin_id: numeric
pager:
options:
offset: 0
type: none
sorts:
id:
field: nid
id: nid
order: ASC
relationship: none
table: node_field_data
plugin_id: numeric
display_plugin: default
display_title: Master
id: default
position: 0
embed_1:
display_options:
defaults:
arguments: false
arguments:
field_date_value_month:
field: field_date_value_month
id: field_date_value
table: node__field_date
plugin_id: datetime_month
display_plugin: embed
id: embed_1
display_title: ''
position: null
embed_2:
display_options:
defaults:
arguments: false
arguments:
field_date_value_day:
field: field_date_value_day
id: field_date_value
table: node__field_date
plugin_id: datetime_day
display_plugin: embed
id: embed_2
display_title: ''
position: null
embed_3:
display_options:
defaults:
arguments: false
arguments:
field_date_value_year:
field: field_date_value_year
id: field_date_value
table: node__field_date
plugin_id: datetime_year
field_date_value_month:
field: field_date_value_month
id: field_date_value
table: node__field_date
plugin_id: datetime_month
field_date_value_day:
field: field_date_value_day
id: field_date_value
table: node__field_date
plugin_id: datetime_day
display_plugin: embed
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
@@ -0,0 +1,56 @@
langcode: und
status: true
dependencies:
module:
- node
id: test_filter_datetime
label: ''
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: none
cache:
type: none
exposed_form:
type: basic
fields:
nid:
field: nid
id: nid
table: node_field_data
plugin_id: node
filters:
field_date_value:
id: field_date_value
table: node__field_date
field: field_date_value
plugin_id: datetime
sorts:
id:
field: nid
id: nid
order: ASC
relationship: none
table: node_field_data
plugin_id: numeric
pager:
type: full
query:
options:
query_comment: ''
type: views_query
style:
type: default
row:
type: fields
display_plugin: default
display_title: Master
id: default
position: 0
@@ -0,0 +1,57 @@
langcode: und
status: true
dependencies:
module:
- node
id: test_sort_datetime
label: ''
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: '8'
display:
default:
display_options:
access:
type: none
cache:
type: none
exposed_form:
type: basic
fields:
nid:
field: nid
id: nid
table: node_field_data
plugin_id: node
sorts:
field_date_value:
field: field_date_value
id: field_date_value
relationship: none
table: node__field_date
order: DESC
plugin_id: datetime
id:
field: nid
id: nid
order: ASC
relationship: none
table: node_field_data
plugin_id: numeric
pager:
type: full
query:
options:
query_comment: ''
type: views_query
style:
type: default
row:
type: fields
display_plugin: default
display_title: Master
id: default
position: 0
@@ -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 = 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 = 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 = 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 = 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 = 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 = 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 = entity_load('entity_test', $id);
$this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.');
}
}