class NormalizerTestBase
Same name in this branch
- 9 core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase
Same name and namespace in other branches
- 11.x core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase
- 10 core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase
- 8.9.x core/modules/serialization/src/Tests/NormalizerTestBase.php \Drupal\serialization\Tests\NormalizerTestBase
- 8.9.x core/modules/serialization/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\serialization\Kernel\NormalizerTestBase
- 8.9.x core/modules/hal/tests/src/Kernel/NormalizerTestBase.php \Drupal\Tests\hal\Kernel\NormalizerTestBase
Test the HAL normalizer.
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\hal\Kernel\NormalizerTestBase extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of NormalizerTestBase
File
-
core/
modules/ hal/ tests/ src/ Kernel/ NormalizerTestBase.php, line 13
Namespace
Drupal\Tests\hal\KernelView source
abstract class NormalizerTestBase extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'entity_test',
'field',
'hal',
'language',
'serialization',
'system',
'text',
'user',
'filter',
];
/**
* The mock serializer.
*
* @var \Symfony\Component\Serializer\Serializer
*/
protected $serializer;
/**
* The format being tested.
*
* @var string
*/
protected $format = 'hal_json';
/**
* The class name of the test class.
*
* @var string
*/
protected $entityClass = 'Drupal\\entity_test\\Entity\\EntityTest';
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
// If the concrete test sub-class installs the Node or Comment modules,
// ensure that the node and comment entity schema are created before the
// field configurations are installed. This is because the entity tables
// need to be created before the body field storage tables. This prevents
// trying to create the body field tables twice.
$class = static::class;
while ($class) {
if (property_exists($class, 'modules')) {
// Only check the modules, if the $modules property was not inherited.
$rp = new \ReflectionProperty($class, 'modules');
if ($rp->class == $class) {
foreach (array_intersect([
'node',
'comment',
], $class::$modules) as $module) {
$this->installEntitySchema($module);
}
}
}
$class = get_parent_class($class);
}
$this->installConfig([
'field',
'language',
]);
// Add German as a language.
ConfigurableLanguage::create([
'id' => 'de',
'label' => 'Deutsch',
'weight' => -1,
])->save();
// Create the test text field.
FieldStorageConfig::create([
'field_name' => 'field_test_text',
'entity_type' => 'entity_test',
'type' => 'text',
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_text',
'bundle' => 'entity_test',
'translatable' => FALSE,
])->save();
// Create the test translatable field.
FieldStorageConfig::create([
'field_name' => 'field_test_translatable_text',
'entity_type' => 'entity_test',
'type' => 'text',
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_translatable_text',
'bundle' => 'entity_test',
'translatable' => TRUE,
])->save();
// Create the test entity reference field.
FieldStorageConfig::create([
'field_name' => 'field_test_entity_reference',
'entity_type' => 'entity_test',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'entity_test',
],
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test',
'translatable' => TRUE,
])->save();
$this->serializer = $this->container
->get('serializer');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.