View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\entity_share_client\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\node\NodeInterface;
use Drupal\user\UserInterface;
class BasicFieldsTest extends EntityShareClientFunctionalTestBase {
public static $modules = [
'entity_share_entity_test',
'jsonapi_extras',
];
protected static $entityTypeId = 'node';
protected static $entityBundleId = 'es_test';
protected static $entityLangcode = 'en';
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager
->getStorage('jsonapi_resource_config')
->create([
'id' => 'node--es_test',
'disabled' => FALSE,
'path' => 'node/es_test',
'resourceType' => 'node--es_test',
'resourceFields' => [
'title' => [
'fieldName' => 'title',
'publicName' => $this
->randomMachineName(),
'enhancer' => [
'id' => '',
],
'disabled' => FALSE,
],
'langcode' => [
'fieldName' => 'langcode',
'publicName' => $this
->randomMachineName(),
'enhancer' => [
'id' => '',
],
'disabled' => FALSE,
],
],
])
->save();
$this
->postSetupFixture();
}
protected function getChannelUserPermissions() {
$permissions = parent::getChannelUserPermissions();
$permissions[] = 'view test entity';
return $permissions;
}
protected function getEntitiesDataArray() {
$date_formatter = $this->container
->get('date.formatter');
return [
'node' => [
'en' => [
'es_test' => $this
->getCompleteNodeInfos([
'status' => [
'value' => NodeInterface::PUBLISHED,
'checker_callback' => 'getValue',
],
]),
'es_test_boolean_off' => $this
->getCompleteNodeInfos([
'field_es_test_boolean' => [
'value' => 0,
'checker_callback' => 'getValue',
],
]),
'es_test_boolean_on' => $this
->getCompleteNodeInfos([
'field_es_test_boolean' => [
'value' => 1,
'checker_callback' => 'getValue',
],
]),
'es_test_date_only' => $this
->getCompleteNodeInfos([
'field_es_test_date_only' => [
'value' => $date_formatter
->format($this->faker
->dateTimeBetween()
->getTimestamp(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT),
'checker_callback' => 'getValue',
],
]),
'es_test_date_and_time' => $this
->getCompleteNodeInfos([
'field_es_test_date' => [
'value' => $date_formatter
->format($this->faker
->dateTimeBetween()
->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'checker_callback' => 'getValue',
],
]),
'es_test_date_range_date_only' => $this
->getCompleteNodeInfos([
'field_es_test_date_only_range' => [
'value' => [
[
'value' => $date_formatter
->format($this->faker
->dateTimeBetween()
->getTimestamp(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT),
'end_value' => $date_formatter
->format($this->faker
->dateTimeBetween('now', '+30 years')
->getTimestamp(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT),
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_date_range_all_day' => $this
->getCompleteNodeInfos([
'field_es_test_date_all_day_range' => [
'value' => [
[
'value' => $date_formatter
->format($this->faker
->dateTimeBetween()
->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => $date_formatter
->format($this->faker
->dateTimeBetween('now', '+30 years')
->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_date_range_date_and_time' => $this
->getCompleteNodeInfos([
'field_es_test_date_range' => [
'value' => [
[
'value' => $date_formatter
->format($this->faker
->dateTimeBetween()
->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end_value' => $date_formatter
->format($this->faker
->dateTimeBetween('now', '+30 years')
->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_email' => $this
->getCompleteNodeInfos([
'field_es_test_email' => [
'value' => $this->faker->email,
'checker_callback' => 'getValue',
],
]),
'es_test_list_float' => $this
->getCompleteNodeInfos([
'field_es_test_list_float' => [
'value' => $this->faker
->randomElement([
1,
1.5,
2,
2.5,
3,
]),
'checker_callback' => 'getValue',
],
]),
'es_test_list_integer' => $this
->getCompleteNodeInfos([
'field_es_test_list_integer' => [
'value' => $this->faker
->randomElement([
1,
2,
3,
]),
'checker_callback' => 'getValue',
],
]),
'es_test_list_text' => $this
->getCompleteNodeInfos([
'field_es_test_list_text' => [
'value' => $this->faker
->randomElement([
'choice_1',
'choice_2',
'choice_3',
]),
'checker_callback' => 'getValue',
],
]),
'es_test_number_decimal' => $this
->getCompleteNodeInfos([
'field_es_test_number_decimal' => [
'value' => $this->faker
->randomFloat(2, 0, 99999999),
'checker_callback' => 'getValue',
],
]),
'es_test_number_float' => $this
->getCompleteNodeInfos([
'field_es_test_number_float' => [
'value' => $this->faker
->randomNumber(5),
'checker_callback' => 'getValue',
],
]),
'es_test_number_integer' => $this
->getCompleteNodeInfos([
'field_es_test_number_integer' => [
'value' => $this->faker
->randomNumber(),
'checker_callback' => 'getValue',
],
]),
'es_test_telephone_phone_number' => $this
->getCompleteNodeInfos([
'field_es_test_telephone' => [
'value' => $this->faker->phoneNumber,
'checker_callback' => 'getValue',
],
]),
'es_test_telephone_mobile_number' => $this
->getCompleteNodeInfos([
'field_es_test_telephone' => [
'value' => $this->faker->mobileNumber,
'checker_callback' => 'getValue',
],
]),
'es_test_telephone_service_number' => $this
->getCompleteNodeInfos([
'field_es_test_telephone' => [
'value' => $this->faker->serviceNumber,
'checker_callback' => 'getValue',
],
]),
'es_test_text_plain' => $this
->getCompleteNodeInfos([
'field_es_test_text_plain' => [
'value' => $this->faker
->text(255),
'checker_callback' => 'getValue',
],
]),
'es_test_text_plain_long' => $this
->getCompleteNodeInfos([
'field_es_test_text_plain_long' => [
'value' => $this->faker
->text(1000),
'checker_callback' => 'getValue',
],
]),
'es_test_text_formatted' => $this
->getCompleteNodeInfos([
'field_es_test_text_formatted' => [
'value' => [
[
'value' => $this->faker
->text(255),
'format' => 'restricted_html',
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_text_formatted_long' => $this
->getCompleteNodeInfos([
'field_es_test_text_formatted_lon' => [
'value' => [
[
'value' => $this->faker
->text(1000),
'format' => 'basic_html',
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_text_formatted_long_summary' => $this
->getCompleteNodeInfos([
'field_es_test_body' => [
'value' => [
[
'value' => $this->faker
->text(1000),
'summary' => $this->faker
->text(1000),
'format' => 'full_html',
],
],
'checker_callback' => 'getValues',
],
]),
'es_test_timestamp' => $this
->getCompleteNodeInfos([
'field_es_test_timestamp' => [
'value' => $this->faker
->unixTime(),
'checker_callback' => 'getValue',
],
]),
],
],
'entity_test_not_translatable' => [
LanguageInterface::LANGCODE_NOT_SPECIFIED => [
'entity_test_not_translatable' => [
'name' => [
'value' => $this
->randomString(),
'checker_callback' => 'getValue',
],
],
],
],
'entity_test_not_translatable_el' => [
LanguageInterface::LANGCODE_NOT_SPECIFIED => [
'entity_test_not_translatable_el' => [
'name' => [
'value' => $this
->randomString(),
'checker_callback' => 'getValue',
],
],
],
],
];
}
protected function createChannel(UserInterface $user) {
parent::createChannel($user);
$channel_storage = $this->entityTypeManager
->getStorage('channel');
$channel = $channel_storage
->create([
'id' => 'entity_test_not_translatable_entity_test_not_translatable_' . LanguageInterface::LANGCODE_NOT_SPECIFIED,
'label' => $this
->randomString(),
'channel_entity_type' => 'entity_test_not_translatable',
'channel_bundle' => 'entity_test_not_translatable',
'channel_langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'authorized_users' => [
$user
->uuid(),
],
]);
$channel
->save();
$this->channels[$channel
->id()] = $channel;
$channel = $channel_storage
->create([
'id' => 'entity_test_not_translatable_el_entity_test_not_translatable_el_' . LanguageInterface::LANGCODE_NOT_SPECIFIED,
'label' => $this
->randomString(),
'channel_entity_type' => 'entity_test_not_translatable_el',
'channel_bundle' => 'entity_test_not_translatable_el',
'channel_langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'authorized_users' => [
$user
->uuid(),
],
]);
$channel
->save();
$this->channels[$channel
->id()] = $channel;
}
public function testBasicPull() {
$this
->pullEveryChannels();
$this
->checkCreatedEntities();
}
}