You are here

protected function ThemeTest::setUp in Image Lazyloader 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/ThemeTest.php, line 59

Class

ThemeTest
Tests Lazyloaders theme integration.

Namespace

Drupal\Tests\lazyloader\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('file');
  $this
    ->installSchema('system', 'sequences');
  $this
    ->installSchema('file', 'file_usage');
  $this
    ->installSchema('node', 'node_access');
  $this
    ->installConfig('system');
  $this
    ->installConfig('lazyloader');
  NodeType::create([
    'type' => 'page',
  ])
    ->save();

  // 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();
  ImageStyle::create([
    'name' => 'medium',
  ])
    ->save();

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
  $display = \Drupal::service('entity_display.repository')
    ->getViewDisplay('node', 'page');
  $display
    ->setComponent('field_images', [
    'type' => 'image',
    'settings' => [
      'image_style' => 'medium',
    ],
  ]);
  $display
    ->save();
  $images = $this
    ->getTestFiles('image');
  foreach ($images as $key => $image) {
    $file = File::create((array) $image);
    $file
      ->save();
    $images[$key] = $file
      ->id();
  }
  $user = User::create([
    'name' => 'muh',
  ]);
  $user
    ->save();
  $settings = [
    'type' => 'page',
    'field_images' => $images,
    'path_alias' => [
      '/' . $this
        ->randomMachineName(),
    ],
    'title' => 'test title',
    'uid' => $user
      ->id(),
  ];
  $this->node = Node::create($settings);
  $this->node
    ->save();
}