FieldTestBase.php in Drupal 10
File
core/modules/field/tests/src/Functional/Views/FieldTestBase.php
View source
<?php
namespace Drupal\Tests\field\Functional\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\field\Entity\FieldStorageConfig;
abstract class FieldTestBase extends ViewTestBase {
protected static $modules = [
'node',
'field_test_views',
];
public $fieldStorages;
public $fields;
protected function setUp($import_test_views = TRUE, $modules = [
'field_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
}
public function setUpFieldStorages($amount = 3, $type = 'string') {
$field_names = [];
for ($i = 0; $i < $amount; $i++) {
$field_names[$i] = 'field_name_' . $i;
$this->fieldStorages[$i] = FieldStorageConfig::create([
'field_name' => $field_names[$i],
'entity_type' => 'node',
'type' => $type,
]);
$this->fieldStorages[$i]
->save();
}
return $field_names;
}
public function setUpFields($bundle = 'page') {
foreach ($this->fieldStorages as $key => $field_storage) {
$this->fields[$key] = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
]);
$this->fields[$key]
->save();
}
}
}
Classes
Name |
Description |
FieldTestBase |
Provides some helper methods for testing fieldapi integration into views. |