function DisplayTest::testInvalidDisplayPlugins

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testInvalidDisplayPlugins()
  2. 10 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testInvalidDisplayPlugins()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/DisplayTest.php \Drupal\Tests\views\Functional\Plugin\DisplayTest::testInvalidDisplayPlugins()

Tests invalid display plugins.

File

core/modules/views/tests/src/Functional/Plugin/DisplayTest.php, line 299

Class

DisplayTest
Tests the basic display plugin.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testInvalidDisplayPlugins() {
    $this->drupalGet('test_display_invalid');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Change the page plugin id to an invalid one. Bypass the entity system
    // so no menu rebuild was executed (so the path is still available).
    $config = $this->config('views.view.test_display_invalid');
    $config->set('display.page_1.display_plugin', 'invalid');
    $config->save();
    $this->drupalGet('test_display_invalid');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertText('The "invalid" plugin does not exist.');
    // Rebuild the router, and ensure that the path is not accessible anymore.
    views_invalidate_cache();
    \Drupal::service('router.builder')->rebuildIfNeeded();
    $this->drupalGet('test_display_invalid');
    $this->assertSession()
        ->statusCodeEquals(404);
    // Change the display plugin ID back to the correct ID.
    $config = $this->config('views.view.test_display_invalid');
    $config->set('display.page_1.display_plugin', 'page');
    $config->save();
    // Place the block display.
    $block = $this->drupalPlaceBlock('views_block:test_display_invalid-block_1', [
        'label' => 'Invalid display',
    ]);
    $this->drupalGet('<front>');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertCount(1, $this->xpath('//div[@id = :id]', [
        ':id' => 'block-' . $block->id(),
    ]));
    // Change the block plugin ID to an invalid one.
    $config = $this->config('views.view.test_display_invalid');
    $config->set('display.block_1.display_plugin', 'invalid');
    $config->save();
    // Test the page is still displayed, the block not present, and has the
    // plugin warning message.
    $this->drupalGet('<front>');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertText('The &quot;invalid&quot; plugin does not exist.');
    $this->assertCount(0, $this->xpath('//div[@id = :id]', [
        ':id' => 'block-' . $block->id(),
    ]));
}

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