createTestViews example


    $term->save();
    // This will get a term ID of 4.     $this->terms[$term->id()] = $term;
    $term = Term::create([
      'vid' => 'tags',
      'name' => 'muh',
    ]);
    $term->save();
    $this->terms[$term->id()] = $term;

    ViewTestData::createTestViews(static::class['taxonomy_test_views']);
  }

  /** * Tests dependencies are not added for terms that do not exist. */
  public function testConfigDependency() {
    /** @var \Drupal\views\Entity\View $view */
    $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');

    // Dependencies are sorted.     $content_dependencies = [
      
    // - term 2.2     for ($i = 0; $i < 3; $i++) {
      for ($j = 0; $j <= $i$j++) {
        $this->terms[$i][$j] = $term = Term::create([
          'vid' => 'tags',
          'name' => "Term $i.$j",
          'parent' => isset($this->terms[$i][0]) ? $this->terms[$i][0]->id() : 0,
        ]);
        $term->save();
      }
    }
    ViewTestData::createTestViews(static::class['taxonomy_test_views']);

    Vocabulary::create([
      'vid' => 'empty_vocabulary',
      'name' => 'Empty Vocabulary',
    ])->save();
  }

  /** * Tests the filter UI. */
  public function testFilterUI() {
    

  public static $testViews = ['test_user_uid_argument'];

  /** * Tests the generated title of a user: uid argument. */
  public function testArgumentTitle() {
    $this->installSchema('system', ['sequences']);
    $this->installEntitySchema('user');
    $this->installConfig(['user']);
    User::create(['uid' => 0, 'name' => ''])->save();
    ViewTestData::createTestViews(static::class['user_test_views']);

    $view = Views::getView('test_user_uid_argument');

    // Tests an invalid user uid.     $view->preview(NULL, [rand(1000, 10000)]);
    $this->assertEmpty($view->getTitle());
    $view->destroy();

    // Tests a valid user.     $account = $this->createUser();
    $view->preview(NULL, [$account->id()]);
    
/** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    // First setup the needed entity types before installing the views.     parent::setUp(FALSE);

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

    ViewTestData::createTestViews(static::class['views_test_config']);

    // Bypass any field access.     $this->adminUser = User::create(['name' => $this->randomString()]);
    $this->adminUser->save();
    $this->container->get('current_user')->setAccount($this->adminUser);

    $this->testUsers = [];
    for ($i = 0; $i < 5; $i++) {
      $this->testUsers[$i] = User::create([
        'name' => 'test ' . $i,
        'timezone' => User::getAllowedTimezones()[$i],
        

  protected $normalUser;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    $this->enableViewsTestModule();

    ViewTestData::createTestViews(static::class['views_test_data']);

    $this->webUser = $this->drupalCreateUser();

    $normal_role = $this->drupalCreateRole([]);
    $this->normalUser = $this->drupalCreateUser([
      'views_test_data test permission',
    ]);
    $this->normalUser->addRole($normal_role);
    // @todo when all the plugin information is cached make a reset function and     // call it here.   }

  

  public static $testViews = ['test_content_ajax'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    ViewTestData::createTestViews(self::class['views_test_config']);

    $admin_user = $this->drupalCreateUser([
      'administer site configuration',
      'administer views',
      'access content overview',
    ]);

    // Disable automatic live preview to make the sequence of calls clearer.     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
    $this->drupalLogin($admin_user);
  }

  

  protected $defaultTheme = 'stark';

  public static $testViews = ['test_content_ajax', 'test_display'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    ViewTestData::createTestViews(self::class['views_test_config']);

    $admin_user = $this->drupalCreateUser([
      'administer site configuration',
      'administer views',
      'administer nodes',
      'access content overview',
      'access contextual links',
    ]);

    // Disable automatic live preview to make the sequence of calls clearer.     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
    

  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();

    
// Create an additional node type.     $type_name2 = strtolower($this->randomMachineName(8)) . '_test';
    $type2 = $this->drupalCreateContentType(['name' => $type_name2, 'type' => $type_name2]);
    $type_name2 = $type2->id();

    // Add a field to the second node type.     $bundle_path2 = 'admin/structure/types/manage/' . $type_name2;
    $this->fieldUIAddExistingField($bundle_path2$field_name$field_label);

    \Drupal::service('module_installer')->install(['views']);
    ViewTestData::createTestViews(static::class['field_test_views']);

    $view = View::load('test_view_field_delete');
    $this->assertNotNull($view);
    $this->assertTrue($view->status());
    // Test that the View depends on the field.     $dependencies = $view->getDependencies() + ['config' => []];
    $this->assertContains("field.storage.node.$field_name", $dependencies['config']);

    // Check the config dependencies of the first field, the field storage must     // not be shown as being deleted yet.     $this->drupalGet("$bundle_path1/fields/node.$type_name1.$field_name/delete");
    

  protected $nodes;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = []): void {
    parent::setUp($import_test_views$modules);

    ViewTestData::createTestViews(static::class['block_test_views']);
    $this->enableViewsTestModule();

    $this->nodeType = $this->container->get('entity_type.manager')
      ->getStorage('node_type')
      ->create([
        'name' => 'Test node type',
        'type' => 'test',
      ]);
    $this->nodeType->save();

    $this->nodes[0] = $this->container->get('entity_type.manager')
      

  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp();
    if ($import_test_views) {
      ViewTestData::createTestViews(static::class$modules);
    }
  }

  /** * Sets up the views_test_data.module. * * Because the schema of views_test_data.module is dependent on the test * using it, it cannot be enabled normally. */
  protected function enableViewsTestModule() {
    // Define the schema and views data variable before enabling the test module.
/** * Tests the user uid filter and argument. */
  public function testUserUid() {
    $this->installSchema('system', ['sequences']);
    $this->installConfig(['filter']);
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installSchema('tracker', ['tracker_node', 'tracker_user']);

    ViewTestData::createTestViews(static::class['tracker_test_views']);
    $node = $this->createNode();

    $map = [
      'nid' => 'nid',
      'title' => 'title',
    ];

    $expected = [
      [
        'nid' => $node->id(),
        'title' => $node->label(),
      ],

  public static $testViews = [
    'test_block_content_revision_id',
    'test_block_content_revision_revision_id',
  ];

  /** * Create a block_content with revision and rest result count for both views. */
  public function testBlockContentRevisionRelationship() {
    $this->installEntitySchema('block_content');
    ViewTestData::createTestViews(static::class['block_content_test_views']);

    BlockContentType::create([
      'id' => 'basic',
      'label' => 'basic',
      'revision' => TRUE,
    ]);
    $block_content = BlockContent::create([
      'info' => $this->randomMachineName(),
      'type' => 'basic',
      'langcode' => 'en',
    ]);
    

  public static $testViews = ['test_field_body'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    ViewTestData::createTestViews(static::class['views_test_config']);

    // Always show advanced column.     \Drupal::configFactory()->getEditable('views.settings')->set('ui.show.advanced_column', TRUE)->save();

    // Disable automatic live preview to make the sequence of calls clearer. And     // prevent errors on saving the view with the preview ajax load that are     // cancelled.     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();

    $account = $this->drupalCreateUser(['administer views']);
    $this->drupalLogin($account);
  }

  public static $testViews = ['test_view_block'];

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp();

    ViewTestData::createTestViews(static::class['block_test_views']);
  }

  /** * Tests that ViewsBlock::getMachineNameSuggestion() produces the right value. * * @see \Drupal\views\Plugin\Block::getMachineNameSuggestion() */
  public function testMachineNameSuggestion() {
    $plugin_definition = [
      'provider' => 'views',
    ];
    
Home | Imprint | This part of the site doesn't use cookies.