class EntityArgumentTest

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Functional/Plugin/EntityArgumentTest.php \Drupal\Tests\views\Functional\Plugin\EntityArgumentTest

Tests the handler of the view: entity target argument.

@group views

Hierarchy

Expanded class hierarchy of EntityArgumentTest

See also

\Drupal\views\Plugin\views\argument\EntityArgument

File

core/modules/views/tests/src/Functional/Plugin/EntityArgumentTest.php, line 18

Namespace

Drupal\Tests\views\Functional\Plugin
View source
class EntityArgumentTest extends TaxonomyTestBase {
  
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static array $testViews = [
    'test_entity_id_argument',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
    'taxonomy',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * A user with permission to administer taxonomy.
   *
   * @var \Drupal\user\UserInterface
   */
  protected UserInterface $adminUser;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE, $modules = []) : void {
    parent::setUp($import_test_views, $modules);
    ViewTestData::createTestViews(static::class, [
      'views_test_config',
    ]);
    // Create an administrative user.
    $this->adminUser = $this->drupalCreateUser([
      'administer taxonomy',
      'bypass node access',
    ]);
    $this->drupalLogin($this->adminUser);
  }
  
  /**
   * Tests the generated title of a view with an entity target argument.
   */
  public function testArgumentTitle() : void {
    $view = Views::getView('test_entity_id_argument');
    $assert_session = $this->assertSession();
    // Test with single entity ID examples.
    $this->drupalGet('/entity-id-argument-test');
    $assert_session->titleEquals($view->getTitle() . ' | Drupal');
    $this->drupalGet('/entity-id-argument-test/1');
    $assert_session->titleEquals('test: title ' . $this->term1
      ->label() . ', input ' . $this->term1
      ->id() . ' | Drupal');
    $this->drupalGet('/entity-id-argument-test/2');
    $assert_session->titleEquals('test: title ' . $this->term2
      ->label() . ', input ' . $this->term2
      ->id() . ' | Drupal');
    // Test with multiple entity IDs examples.
    $this->drupalGet('/entity-id-argument-test/1,2');
    $assert_session->titleEquals('test: title ' . $this->term1
      ->label() . ', ' . $this->term2
      ->label() . ', input ' . $this->term1
      ->id() . ',' . $this->term2
      ->id() . ' | Drupal');
    $this->drupalGet('/entity-id-argument-test/2,1');
    $assert_session->titleEquals('test: title ' . $this->term2
      ->label() . ', ' . $this->term1
      ->label() . ', input ' . $this->term2
      ->id() . ',' . $this->term1
      ->id() . ' | Drupal');
    $this->drupalGet('/entity-id-argument-test/1+2');
    $assert_session->titleEquals('test: title ' . $this->term1
      ->label() . ' + ' . $this->term2
      ->label() . ', input ' . $this->term1
      ->id() . '+' . $this->term2
      ->id() . ' | Drupal');
    $this->drupalGet('/entity-id-argument-test/2+1');
    $assert_session->titleEquals('test: title ' . $this->term2
      ->label() . ' + ' . $this->term1
      ->label() . ', input ' . $this->term2
      ->id() . '+' . $this->term1
      ->id() . ' | Drupal');
  }

}

Members

Title Sort descending Modifiers Object type Summary
EntityArgumentTest::$adminUser protected property A user with permission to administer taxonomy.
EntityArgumentTest::$defaultTheme protected property The theme to install as the default for testing.
EntityArgumentTest::$modules protected static property Modules to install.
EntityArgumentTest::$testViews public static property Views used by this test.
EntityArgumentTest::setUp protected function Sets up the test.
EntityArgumentTest::testArgumentTitle public function Tests the generated title of a view with an entity target argument.
EntityReferenceFieldCreationTrait::createEntityReferenceField protected function Creates a field of an entity reference field storage on the specified bundle.

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