public function TestBase::setUp in Image Lazyloader 8
Overrides BrowserTestBase::setUp
File
- src/
tests/ TestBase.php, line 37
Class
- TestBase
- Test case for typical lazyloader tests.
Namespace
Drupal\lazyloader\TestsCode
public function setUp() {
parent::setUp();
$this
->createContentType([
'type' => 'page',
]);
$user = $this
->drupalCreateUser([
'create page content',
'edit own page content',
'administer lazyloader',
'administer url aliases',
'create url aliases',
]);
$this
->drupalLogin($user);
// Add unlimited image field.
$field_storage = FieldStorageConfig::create([
'type' => 'image',
'field_name' => 'field_images',
'cardinality' => -1,
'entity_type' => 'node',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_name' => 'field_images',
'entity_type' => 'node',
'bundle' => 'page',
]);
$field
->save();
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('node', 'page', 'full');
$display
->setComponent('field_images', [
'type' => 'image',
'settings' => [
'image_style' => 'medium',
],
]);
$display
->save();
$images = $this
->drupalGetTestFiles('image');
foreach ($images as $key => $image) {
$file = File::create((array) $image);
$file
->save();
$images[$key] = $file
->id();
}
$settings = [
'type' => 'page',
'field_images' => $images,
'path' => [
'alias' => '/' . $this
->randomMachineName(),
],
];
$this->node = $this
->drupalCreateNode($settings);
}