FieldTest.php

Same filename in this branch
  1. 9 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldTest.php
  2. 9 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldTest.php
  3. 9 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php
  4. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php
  5. 9 core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php
Same filename and directory in other branches
  1. 8.9.x core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldTest.php
  2. 8.9.x core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldTest.php
  3. 8.9.x core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php
  4. 8.9.x core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
  5. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php
  6. 8.9.x core/modules/quickedit/tests/src/FunctionalJavascript/FieldTest.php
  7. 10 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldTest.php
  8. 10 core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldTest.php
  9. 10 core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php
  10. 10 core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
  11. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php
  12. 11.x core/modules/field/tests/src/Kernel/Plugin/migrate/source/d6/FieldTest.php
  13. 11.x core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldTest.php
  14. 11.x core/modules/views/tests/src/Unit/Plugin/field/FieldTest.php
  15. 11.x core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
  16. 11.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldTest.php

Namespace

Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler

File

core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php

View source
<?php

namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;

use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestData;

/**
 * Tests the field handler UI.
 *
 * @group views
 */
class FieldTest extends WebDriverTestBase {
  use SchemaCheckTestTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
    'views',
    'views_ui',
    'views_test_config',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_field_body',
  ];
  
  /**
   * The account.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $account;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    ViewTestData::createTestViews(static::class, [
      'views_test_config',
    ]);
    // Disable automatic live preview to make the sequence of calls clearer.
    \Drupal::configFactory()->getEditable('views.settings')
      ->set('ui.always_live_preview', FALSE)
      ->save();
    $this->account = $this->drupalCreateUser([
      'administer views',
    ]);
    $this->drupalLogin($this->account);
    NodeType::create([
      'type' => 'page',
    ])->save();
    FieldConfig::create([
      'entity_type' => 'node',
      'field_name' => 'body',
      'bundle' => 'page',
    ])->save();
  }
  public function testFormatterChanging() {
    $web_assert = $this->assertSession();
    $url = '/admin/structure/views/view/test_field_body';
    $this->drupalGet($url);
    $page = $this->getSession()
      ->getPage();
    $page->clickLink('Body field');
    $web_assert->assertWaitOnAjaxRequest();
    $page->fillField('options[type]', 'text_trimmed');
    // Add a value to the trim_length setting.
    $web_assert->assertWaitOnAjaxRequest();
    $page->fillField('options[settings][trim_length]', '700');
    $apply_button = $page->find('css', '.views-ui-dialog button.button--primary');
    $this->assertNotEmpty($apply_button);
    $apply_button->press();
    $web_assert->assertWaitOnAjaxRequest();
    // Save the page.
    $save_button = $page->find('css', '#edit-actions-submit');
    $save_button->press();
    // Set the body field back to 'default' and test that the trim_length
    // settings are not in the config.
    $this->drupalGet($url);
    $page->clickLink('Body field');
    $web_assert->assertWaitOnAjaxRequest();
    $page->fillField('options[type]', 'text_default');
    $web_assert->assertWaitOnAjaxRequest();
    $apply_button = $page->find('css', '.views-ui-dialog button.button--primary');
    $apply_button->press();
    $web_assert->assertWaitOnAjaxRequest();
    // Save the page.
    $save_button = $page->find('css', '#edit-actions-submit');
    $save_button->press();
    $this->assertConfigSchemaByName('views.view.test_field_body');
  }

}

Classes

Title Deprecated Summary
FieldTest Tests the field handler UI.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.