improvements-2.x-dev/modules/improvements_admin/tests/src/Functional/ImprovementsAdminTest.php

modules/improvements_admin/tests/src/Functional/ImprovementsAdminTest.php
<?php

namespace Drupal\Tests\improvements_admin\Functional;

use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\improvements\Traits\ImprovementsTestTrait;

class ImprovementsAdminTest extends BrowserTestBase {

  use BlockCreationTrait;
  use ImprovementsTestTrait;

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

  /**
   * {@inheritDoc}
   */
  protected static $modules = ['improvements_admin'];

  /**
   * {@inheritDoc}
   */
  protected function setUp(): void {
    parent::setUp();
  }

  /**
   * Test modules list filter autofocus.
   *
   * @covers ::improvements_admin_form_system_modules_alter()
   */
  public function testModulesListAutofocus(): void {
    $this->drupalLoginAsRoot();
    $this->drupalGet('/admin/modules');
    $this->dontSeeErrorMessage();
    $this->assertSession()->elementExists('css', '#edit-text[autofocus]');
  }

  /**
   * Test link for edit block content.
   *
   * @covers ::improvements_admin_form_block_admin_display_form_alter()
   */
  public function testContentBlockEditLink(): void {
    $this->installModule('block', 'block_content');
    $this->createBlockContentType();
    $block_content_entity = $this->createBlockContent();
    $block_config_entity = $this->placeBlockContent($block_content_entity, ['id' => 'test_edit_content_link']);
    $this->drupalLoginAsRoot();
    $this->drupalGet('/admin/structure/block');
    $this->dontSeeErrorMessage();
    $this->assertSession()->elementExists('css', 'tr[data-drupal-selector="edit-blocks-test-edit-content-link"] .dropbutton a[href="/admin/content/block/' . $block_content_entity->id() . '"]');
  }

  /**
   * Test content block form autofocus.
   *
   * @covers ::improvements_admin_form_block_content_form_alter()
   */
  public function testBlockContentAutofocus(): void {
    $this->installModule('block', 'block_content');
    $this->createBlockContentType();
    $this->drupalLoginAsRoot();
    $this->drupalGet('/block/add/basic');
    $this->dontSeeErrorMessage();
    $this->assertSession()->elementAttributeExists('css', '#edit-info-0-value', 'autofocus');
  }

  /**
   * Test textarea widget improvements.
   */
  public function testFieldWidgetTextareaImprovements(): void {
    $this->installModule('node', 'text', 'filter', 'field', 'field_ui');
    $this->createFilterFormat(['format' => 'full_html', 'name' => 'Full HTML']);
    $this->createFilterFormat(['format' => 'raw_html', 'name' => 'Raw HTML']);
    $this->createContentType(['type' => 'page', 'name' => 'Page']);
    $web_assert = $this->assertSession();

    $this->createField(
      entity_type: 'node',
      entity_bundle: 'page',
      field_name: 'field_text',
      field_type: 'text_long',
      field_label: 'Test text field',
      widget_type: 'text_textarea',
    );

    $this->drupalLoginAsRoot();
    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementExists('css', 'select[name="field_text[0][format]"]');

    $this->drupalGet('/admin/structure/types/manage/page/form-display');
    $this->dontSeeErrorMessage();
    $this->openEntityDisplayComponentSettings('field_text');
    $web_assert->fieldExists('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][max_length]');
    $web_assert->fieldExists('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][dynamic_height]');
    $web_assert->fieldExists('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][disable_editor]');
    $web_assert->fieldExists('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][hide_format_select]');

    $this->submitForm([
      'fields[field_text][settings_edit_form][third_party_settings][improvements_admin][max_length]' => 10,
      'fields[field_text][settings_edit_form][third_party_settings][improvements_admin][dynamic_height]' => 1,
      'fields[field_text][settings_edit_form][third_party_settings][improvements_admin][disable_editor]' => 1,
      'fields[field_text][settings_edit_form][third_party_settings][improvements_admin][hide_format_select]' => 1,
    ], 'Save');
    $this->dontSeeErrorMessage();

    $this->openEntityDisplayComponentSettings('field_text');
    $web_assert->fieldValueEquals('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][max_length]', 10);
    $web_assert->checkboxChecked('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][dynamic_height]');
    $web_assert->checkboxChecked('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][disable_editor]');
    $web_assert->checkboxChecked('fields[field_text][settings_edit_form][third_party_settings][improvements_admin][hide_format_select]');

    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert = $this->assertSession();
    $web_assert->elementAttributeContains('css', '#edit-field-text-0-value', 'maxlength', '10');
    $web_assert->elementExists('css', '#edit-field-text-0-format.visually-hidden');

    // @TODO Add test disabled CKEditor
  }

  /**
   * Test textfield widget improvements.
   */
  public function testFieldWidgetTextfieldImprovements(): void {
    $this->installModule('node', 'field', 'field_ui');
    $this->createContentType(['type' => 'page', 'name' => 'Page']);
    $this->createField(
      entity_type: 'node',
      entity_bundle: 'page',
      field_name: 'field_string',
      field_type: 'string',
      field_label: 'String',
      widget_type: 'string_textfield',
    );
    $this->drupalLoginAsRoot();
    $web_assert = $this->assertSession();

    $this->drupalGet('/admin/structure/types/manage/page/form-display');
    $this->dontSeeErrorMessage();
    $this->openEntityDisplayComponentSettings('field_string');
    $web_assert->fieldExists('fields[field_string][settings_edit_form][third_party_settings][improvements_admin][max_length]');

    $this->submitForm([
      'fields[field_string][settings_edit_form][third_party_settings][improvements_admin][max_length]' => 10,
    ], 'Save');
    $this->dontSeeErrorMessage();

    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementAttributeContains('css', '#edit-field-string-0-value', 'maxlength', '10');
  }

  /**
   * Test "file" widget improvements.
   */
  public function testFieldWidgetFileImprovements(): void {
    $this->installModule('node', 'field', 'field_ui', 'file', 'improvements_form');
    $this->createContentType(['type' => 'page', 'name' => 'Page']);
    $this->createField(
      entity_type: 'node',
      entity_bundle: 'page',
      field_name: 'field_file',
      field_type: 'file',
      field_label: 'File',
      widget_type: 'file_generic',
    );
    $this->drupalLoginAsRoot();
    $web_assert = $this->assertSession();

    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementExists('css', '#edit-field-file-0-upload');

    $this->drupalGet('/admin/structure/types/manage/page/form-display');
    $this->dontSeeErrorMessage();
    $this->openEntityDisplayComponentSettings('field_file');
    $web_assert->fieldExists('fields[field_file][settings_edit_form][third_party_settings][improvements_admin][autoupload]');
    $web_assert->fieldExists('fields[field_file][settings_edit_form][third_party_settings][improvements_admin][upload_button_state]');

    $this->submitForm([
      'fields[field_file][settings_edit_form][third_party_settings][improvements_admin][autoupload]' => FALSE,
    ], 'Save');
    $this->dontSeeErrorMessage();

    $this->openEntityDisplayComponentSettings('field_file');
    $web_assert->checkboxNotChecked('fields[field_file][settings_edit_form][third_party_settings][improvements_admin][autoupload]');

    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementExists('css', '#edit-field-file-0-upload.js-form-file--no-autoupload');
    $web_assert->elementExists('css', '#edit-field-file-0-upload-button.js-hide');

    $field_file_widget_settings['third_party_settings']['improvements_admin']['upload_button_state'] = 1;
    $this->setFieldWidgetSettings('node', 'page', 'field_file', $field_file_widget_settings);
    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementExists('css', '#edit-field-file-0-upload-button');
    $web_assert->elementNotExists('css', '#edit-field-file-0-upload-button.js-hide');

    $field_file_widget_settings['third_party_settings']['improvements_admin']['upload_button_state'] = 0;
    $this->setFieldWidgetSettings('node', 'page', 'field_file', $field_file_widget_settings);
    $this->drupalGet('/node/add/page');
    $this->dontSeeErrorMessage();
    $web_assert->elementNotExists('css', '#edit-field-file-0-upload-button');
  }

}

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

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