assertIdenticalResultset example

$revision->save();

    // Create one node on which the author has neither authorship of revisions     // or the main node.     $this->createNode(['uid' => $no_author->id()]);

    $view = Views::getView('test_filter_node_uid_revision');
    $view->initHandlers();
    $view->filter['uid_revision']->value = [$author->id()];

    $view->preview();
    $this->assertIdenticalResultset($view$expected_result['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.');
  }

}
/** * Tests the result of a view with base fields and configurable fields. */
  public function testSimpleExecute() {
    $executable = Views::getView('test_field_field_test');
    $executable->execute();

    $this->assertInstanceOf(EntityField::class$executable->field['id']);
    $this->assertInstanceOf(EntityField::class$executable->field['field_test']);

    $this->assertIdenticalResultset($executable,
      [
        ['id' => 1, 'field_test' => 3, 'user_id' => 2],
        ['id' => 2, 'field_test' => 0, 'user_id' => 3],
        ['id' => 3, 'field_test' => 8, 'user_id' => 4],
        ['id' => 4, 'field_test' => 5, 'user_id' => 5],
        ['id' => 5, 'field_test' => 6, 'user_id' => 6],
      ],
      ['id' => 'id', 'field_test' => 'field_test', 'user_id' => 'user_id']
    );
  }

  
'value' => 0,
      ],
    ]);
    $this->executeView($view);

    $expected_result = [
      ['id' => 2],
      ['id' => 4],
    ];

    $this->assertCount(2, $view->result);
    $this->assertIdenticalResultset($view$expected_result$this->columnMap);

    $view->destroy();
    $view->setDisplay();

    // Add the status boolean filter.     $view->displayHandlers->get('default')->overrideOption('filters', [
      'status' => [
        'id' => 'status',
        'field' => 'status',
        'table' => 'views_test_data',
        'value' => 1,
      ],

  protected function assertSortResults(string $view_id, string $column, string $order, array $expected): void {
    // Test with exposed input.     $view = Views::getView($view_id);
    $view->setExposedInput([
      'sort_by' => 'moderation_state',
      'sort_order' => $order,
    ]);
    $view->execute();
    $this->assertIdenticalResultset($view$expected[$column => $column]);

    // Test click sorting.     $view = Views::getView($view_id);
    $view->removeHandler('default', 'sort', 'moderation_state');
    $request = new Request([
      'order' => 'moderation_state',
      'sort' => strtolower($order),
    ]);
    $view->setRequest($request);
    $view->execute();
    $this->assertIdenticalResultset($view$expected[$column => $column]);
  }
$test_entity = EntityTestNoBundle::create([
      'moderation_state' => 'draft',
    ]);
    $test_entity->save();

    $view = Views::getView('test_content_moderation_state_filter_entity_test');
    $view->setExposedInput([
      'moderation_state' => 'editorial-draft',
    ]);
    $view->execute();
    $this->assertIdenticalResultset($view[['id' => $test_entity->id()]]['id' => 'id']);
  }

  /** * Tests the moderation state filter on an entity added via a relationship. */
  public function testModerationStateFilterOnJoinedEntity() {
    $workflow = Workflow::load('editorial');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->save();

    // Create some sample content that will satisfy a view of users with a
$node->save();

    $view = Views::getView('test_content_moderation_field_state_test');
    $view->execute();

    $expected_result = [
      [
        'title' => 'Test title',
        'moderation_state' => 'published',
      ],
    ];
    $this->assertIdenticalResultset($view$expected_result['title' => 'title', 'moderation_state' => 'moderation_state']);
  }

}
$view->filter[$field_start]->value['type'] = 'offset';
    $view->filter[$field_start]->value['value'] = '-1 day';
    $view->filter[$field_end]->operator = '<=';
    $view->filter[$field_end]->value['type'] = 'offset';
    $view->filter[$field_end]->value['value'] = 'now';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
      ['nid' => $this->nodes[0]->id()],
      ['nid' => $this->nodes[1]->id()],
    ];
    $this->assertIdenticalResultset($view$expected_result$this->map);
    $view->destroy();

    // Search nodes with:     // - start date greater than or equal to 'yesterday'.     // - end date greater than 'today'.     // Expected results: node 2.     $view->initHandlers();
    $view->filter[$field_start]->operator = '>=';
    $view->filter[$field_start]->value['type'] = 'offset';
    $view->filter[$field_start]->value['value'] = '-1 day';
    $view->filter[$field_end]->operator = '>';
    
$media = Media::create([
      'name' => 'Test media',
      'bundle' => $this->testMediaType->id(),
      'uid' => $primary_author->id(),
    ]);
    $media->setRevisionUserId($primary_author->id());
    $media->save();

    $view = Views::getView('test_media_revision_uid');
    $this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'mid' => 1,
        'vid' => 1,
        'uid' => $primary_author->id(),
        'revision_user' => $primary_author->id(),
      ],
    ]static::$columnMap);

    // Test results shows the original author as well as the revision author.     $media->setRevisionUser($secondary_author);
    $media->setNewRevision();
    
'langcode' => [
          'id' => 'langcode',
          'table' => 'views_test_data',
          'field' => 'langcode',
        ],
      ]);
      $this->executeView($view[$langcode]);

      $expected = [
        ['name' => $name],
      ];
      $this->assertIdenticalResultset($view$expected['views_test_data_name' => 'name']);
      $view->destroy();
    }
  }

}

  public function testSimpleResultSet() {
    $view = Views::getView('test_view');
    $view->setDisplay();

    // Execute the view.     $this->executeView($view);

    // Verify the result.     $this->assertCount(5, $view->result, 'The number of returned rows match.');
    $this->assertIdenticalResultset($view$this->dataSet()[
      'views_test_data_name' => 'name',
      'views_test_data_age' => 'age',
    ]);
  }

  /** * Tests filtering of the result set. */
  public function testSimpleFiltering() {
    $view = Views::getView('test_view');
    $view->setDisplay();

    
$this->assertSame($expected$view->getDependencies());
    $this->executeView($view[$this->term1->id()$this->term2->id()]);
    $expected_result = [
      [
        'nid' => $this->nodes[1]->id(),
      ],
      [
        'nid' => $this->nodes[0]->id(),
      ],
    ];
    $column_map = ['nid' => 'nid'];
    $this->assertIdenticalResultset($view$expected_result$column_map);

    // Change the view to test relation limited by vocabulary.     $this->config('views.view.test_taxonomy_node_term_data')
      ->set('display.default.display_options.relationships.term_node_tid.vids', ['views_testing_tags'])
      ->save();

    $view = Views::getView('test_taxonomy_node_term_data');
    // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().     $expected['config'][] = 'taxonomy.vocabulary.views_testing_tags';
    $this->assertSame($expected$view->getDependencies());
    $this->executeView($view[$this->term1->id()$this->term2->id()]);
    
'type' => 'default',
      'title' => $this->randomMachineName(),
    ]);
    $node3->setOwner($no_author);
    $node3->save();

    $view = Views::getView('test_argument_node_uid_revision');
    $view->initHandlers();
    $view->setArguments(['uid_revision' => $author->id()]);

    $this->executeView($view);
    $this->assertIdenticalResultset($view$expected_result['nid' => 'nid']);
  }

}

  public function testDatetimeArgumentYear() {
    $view = Views::getView('test_argument_datetime');

    // The 'default' display has the 'year' argument.     $view->setDisplay('default');
    $this->executeView($view['2000']);
    $expected = [];
    $expected[] = ['nid' => $this->nodes[0]->id()];
    $this->assertIdenticalResultset($view$expected$this->map);
    $view->destroy();

    $view->setDisplay('default');
    $this->executeView($view['2002']);
    $expected = [];
    $expected[] = ['nid' => $this->nodes[2]->id()];
    $this->assertIdenticalResultset($view$expected$this->map);
    $view->destroy();

    $view->setDisplay('default');
    $this->executeView($view['2003']);
    
NodeType::create(['type' => 'page', 'name' => 'page'])->save();
    $node = Node::create(['type' => 'page', 'title' => 'test1', 'uid' => 1]);
    $node->save();
    $first_revision_id = $node->getRevisionId();
    $node->setNewRevision();
    $node->setTitle('test2');
    $node->save();
    $second_revision_id = $node->getRevisionId();

    $view_nid = Views::getView('test_node_revision_id_argument');
    $this->executeView($view_nid[$second_revision_id]);
    $this->assertIdenticalResultset($view_nid[['title' => 'test2']]);
    $this->assertSame('test2', $view_nid->getTitle());
  }

}
'operator' => '=',
        'value' => 'Ringo',
      ],
    ]);

    $this->executeView($view);
    $resultset = [
      [
        'name' => 'Ringo',
      ],
    ];
    $this->assertIdenticalResultset($view$resultset$this->columnMap);
  }

  public function testFilterStringGroupedExposedEqual() {
    $filters = $this->getGroupedExposedFilters();
    $view = $this->getBasicPageView();

    // Filter: Name, Operator: =, Value: Ringo     $filters['name']['group_info']['default_group'] = 1;
    $view->setDisplay('page_1');
    $view->displayHandlers->get('page_1')->overrideOption('filters', $filters);
    $view->save();

    
Home | Imprint | This part of the site doesn't use cookies.