getview example

protected function setUp($import_test_views = TRUE): void {
    parent::setUp();

    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('user');
  }

  /** * Tests a field-based view's cache tags when using the "none" cache plugin. */
  public function testFieldBasedViewCacheTagsWithCachePluginNone() {
    $view = Views::getview('entity_test_fields');
    $view->getDisplay()->overrideOption('cache', [
      'type' => 'none',
    ]);
    $view->save();

    $this->assertCacheTagsForFieldBasedView(FALSE);
  }

  /** * Tests a field-based view's cache tags when using the "tag" cache plugin. */
  

  public function testCssClassCleaning() {
    \Drupal::service('theme_installer')->install(['test_theme']);
    $this->config('system.theme')->set('default', 'test_theme')->save();

    $entity = EntityTest::create();
    $entity->save();
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $view = Views::getview('test_preprocess');
    $build = $view->buildRenderable();
    $renderer->renderRoot($build);
    $this->assertStringContainsString('class="entity-test--default entity-test__default', (string) $build['#markup']);
    $view->destroy();

    $view->setDisplay('display_2');
    $build = $view->buildRenderable();
    $renderer->renderRoot($build);
    $markup = (string) $build['#markup'];
    $this->assertStringContainsString('css_class: entity-test--default and-another-class entity-test__default', $markup);
    $this->assertStringContainsString('attributes: class="entity-test--default and-another-class entity-test__default', $markup);
  }
Home | Imprint | This part of the site doesn't use cookies.