FieldDropButtonTest.php

Same filename in this branch
  1. 10 core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php
Same filename and directory in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php
  2. 9 core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php
  3. 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php
  4. 8.9.x core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php
  5. 11.x core/modules/views/tests/src/Kernel/Handler/FieldDropbuttonTest.php
  6. 11.x core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php

Namespace

Drupal\Tests\views\Functional\Handler

File

core/modules/views/tests/src/Functional/Handler/FieldDropButtonTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\views\Functional\Handler;

use Drupal\Tests\views\Functional\ViewTestBase;

/**
 * Tests the dropbutton field handler.
 *
 * @group views
 * @see \Drupal\system\Plugin\views\field\Dropbutton
 */
class FieldDropButtonTest extends ViewTestBase {
  
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_dropbutton',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE, $modules = [
    'views_test_config',
  ]) : void {
    parent::setUp($import_test_views, $modules);
    $admin_user = $this->drupalCreateUser([
      'access content overview',
      'administer nodes',
      'bypass node access',
    ]);
    $this->drupalLogin($admin_user);
  }
  
  /**
   * Tests dropbutton field.
   */
  public function testDropbutton() : void {
    // Create some test nodes.
    $nodes = [];
    for ($i = 0; $i < 5; $i++) {
      $nodes[] = $this->drupalCreateNode();
    }
    $this->drupalGet('test-dropbutton');
    foreach ($nodes as $node) {
      // Test that only one node title link was found.
      $this->assertSession()
        ->elementsCount('xpath', "//ul[contains(@class, dropbutton)]/li/a[contains(@href, '/node/{$node->id()}') and text()='{$node->label()}']", 1);
      // Test that only one custom link was found.
      $this->assertSession()
        ->elementsCount('xpath', "//ul[contains(@class, dropbutton)]/li/a[contains(@href, '/node/{$node->id()}') and text()='Custom Text']", 1);
    }
    // Check if the dropbutton.js library is available.
    $this->drupalGet('admin/content');
    $this->assertSession()
      ->responseContains('dropbutton.js');
    // Check if the dropbutton.js library is available on a cached page to
    // ensure that bubbleable metadata is not lost in the views render workflow.
    $this->drupalGet('admin/content');
    $this->assertSession()
      ->responseContains('dropbutton.js');
  }

}

Classes

Title Deprecated Summary
FieldDropButtonTest Tests the dropbutton field handler.

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