You are here

public function ParagraphsTypesTest::testParagraphTypeDefaultIcon in Paragraphs 8

Tests the paragraph type default icon settings.

File

tests/src/Functional/WidgetLegacy/ParagraphsTypesTest.php, line 104

Class

ParagraphsTypesTest
Tests Paragraphs types.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

public function testParagraphTypeDefaultIcon() {

  /** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
  $entity_repository = \Drupal::service('entity.repository');
  $admin_user = $this
    ->drupalCreateUser([
    'administer paragraphs types',
    'access files overview',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Add the paragraph type with icon.
  $this
    ->drupalGet('admin/structure/paragraphs_type/add');
  $this
    ->assertSession()
    ->pageTextContains('Paragraph type icon');
  $test_files = $this
    ->getTestFiles('image');
  $fileSystem = \Drupal::service('file_system');
  $edit = [
    'label' => 'Test paragraph type',
    'id' => 'test_paragraph_type_icon',
    'files[icon_file]' => $fileSystem
      ->realpath($test_files[0]->uri),
  ];
  $this
    ->submitForm($edit, 'Save and manage fields');
  $this
    ->assertSession()
    ->pageTextContains('Saved the Test paragraph type Paragraphs type.');

  // Check if the icon is created from defaults if not exists.
  $paragraph_type = ParagraphsType::load('test_paragraph_type_icon');
  $file = $entity_repository
    ->loadEntityByUuid('file', $paragraph_type
    ->get('icon_uuid'));
  $file
    ->delete();
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/paragraphs_type');

  // New default icon name.
  $default_icon_name = 'test_paragraph_type_icon-default-icon.png';
  $this
    ->assertSession()
    ->responseContains($default_icon_name);
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->pageTextContains($default_icon_name);
  $file = $entity_repository
    ->loadEntityByUuid('file', $paragraph_type
    ->get('icon_uuid'));
  $this
    ->assertNotEmpty($file);
}