inline_image_saver-1.0.x-dev/tests/src/Functional/InlineImageSaverUiTest.php

tests/src/Functional/InlineImageSaverUiTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\inline_image_saver\Functional;

use Drupal\Component\Utility\Html;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\inline_image_saver\Traits\InlineImageTestTrait;

/**
 * Tests the UI of the inline_image_saver module.
 */
class InlineImageSaverUiTest extends BrowserTestBase {

  use InlineImageTestTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['inline_image_saver_ui_test'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  public function setUp(): void {
    parent::setUp();
    $this->processableFormatId = 'full_html';
  }

  /**
   * Tests the validation UI.
   */
  public function testValidationUi(): void {
    $node_type_id = $this->drupalCreateContentType()->id();
    $permissions = [
      'administer site configuration',
      "create $node_type_id content",
      "edit own $node_type_id content",
      "use text format $this->processableFormatId",
      'use text format filtered_html',
    ];
    $user = $this->drupalCreateUser($permissions);
    $this->drupalLogin($user);

    $edit = [
      "processable_formats[$this->processableFormatId]" => TRUE,
      'enable_validation' => TRUE,
      'allow_if_downloadable' => TRUE,
      'enable_replace' => TRUE,
      'enable_download' => TRUE,
      'prefer_reuse_files' => TRUE,
      'allow_data_uri' => TRUE,
      'check_file_exists' => TRUE,
      'validate_url' => TRUE,
      'validate_url_query' => TRUE,
      'check_file_mime' => TRUE,
      'fallback_markup' => '<s>' . Html::escape('<img src="@src" alt="@alt" title="@title" data-entity-type="@data-entity-type" data-entity-uuid="@data-entity-uuid">') . '</s>',
      'create_revision' => TRUE,
      'revision_log' => $this->randomMachineName(),
      'skip_on_sync' => TRUE,
    ];
    $this->drupalGet('admin/config/content/inline-image-saver/settings');
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->statusMessageContains('The configuration options have been saved.', 'status');

    $img_markup = $this->createImageMarkup(['alt' => 'body_image&']);
    $this->drupalGet("node/add/$node_type_id");
    $edit = [
      'title[0][value]' => $this->randomMachineName(),
      'body[0][value]' => $img_markup,
      'body[0][format]' => $this->processableFormatId,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusMessageContains('The image body_image& is invalid: empty data-entity-type attribute. The image must contain valid data-entity-type and data-entity-uuid attributes referencing an existing file entity.', 'error');

    $img_markup = $this->createImageMarkup([
      'src' => '/foo/bar.jpg',
      'data-entity-type' => 'file',
      'data-entity-uuid' => $this->randomMachineName(),
      'alt' => 'base_text_long&',
    ]);
    $this->drupalGet("node/add/$node_type_id");
    $edit = [
      'title[0][value]' => $this->randomMachineName(),
      'base_text_long[0][value]' => $img_markup,
      'base_text_long[0][format]' => $this->processableFormatId,
    ];
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusMessageContains('The image base_text_long& is invalid: referenced entity not found. The image must contain valid data-entity-type and data-entity-uuid attributes referencing an existing file entity.', 'error');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc