dataSet example

'name' => 'Ginger',
        'job' => NULL,
      ],
    ];
    $this->assertNotIdenticalResultset($view$resultset$this->columnMap);
  }

  /** * Additional data to test the NULL issue. */
  protected function dataSet() {
    $data_set = parent::dataSet();
    $data_set[] = [
      'name' => 'Ginger',
      'age' => 25,
      'job' => NULL,
      'created' => gmmktime(0, 0, 0, 1, 2, 2000),
      'status' => 1,
    ];
    return $data_set;
  }

  /** * Allow {views_test_data}.job to be NULL. * * @internal */
/** * Add more items to the test set, to make the order tests more robust. * * In total we have then 60 entries, which makes a probability of a collision * of 1/60!, which is around 1/1E80, which is higher than the estimated amount * of protons / electrons in the observable universe, also called the * eddington number. * * @see http://wikipedia.org/wiki/Eddington_number */
  protected function dataSet() {
    $data = parent::dataSet();
    for ($i = 0; $i < 55; $i++) {
      $data[] = [
        'name' => 'name_' . $i,
        'age' => $i,
        'job' => 'job_' . $i,
        'created' => rand(0, time()),
        'status' => 1,
      ];
    }
    return $data;
  }

  
// Make sure a views rendered page is touched.     $this->drupalGet('test_page_display_200');

    $this->assertSession()->responseContains("test_subtheme_views_pre_render");
    $this->assertSession()->responseContains("test_subtheme_views_post_render");

    $this->assertSession()->responseContains("test_basetheme_views_pre_render");
    $this->assertSession()->responseContains("test_basetheme_views_post_render");

    // Verify that the views group title is added.     $this->assertSession()->responseContains('<em class="placeholder">' . count($this->dataSet()) . '</em> items found.');
  }

}

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

    
'uid' => 1,
      ],
    ];
    $this->assertIdenticalResultset($view$expected_result$this->columnMap);
    $view->destroy();

    // Set the relationship to optional should cause to return all beatles.     $view->initHandlers();
    $view->relationship['uid']->options['required'] = FALSE;
    $this->executeView($view);

    $expected_result = $this->dataSet();
    // Alter the expected result to contain the right uids.     foreach ($expected_result as &$row) {
      // Only John has an existing author.       if ($row['name'] == 'John') {
        $row['uid'] = 1;
      }
      else {
        // The LEFT join should set an empty {users}.uid field.         $row['uid'] = NULL;
      }
    }

    
'id' => 'age',
        'table' => 'views_test_data',
        'field' => 'age',
        'relationship' => 'none',
      ],
    ]);

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

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

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

    // Reverse the ordering     $view->displayHandlers->get('default')->overrideOption('sorts', [
      'age' => [
        
$views_data = parent::viewsData();

    $views_data['views_test_data']['status']['filter']['id'] = 'boolean_string';

    return $views_data;
  }

  /** * {@inheritdoc} */
  protected function dataSet() {
    $data = parent::dataSet();

    foreach ($data as &$row) {
      if ($row['status']) {
        $row['status'] = 'Enabled';
      }
      else {
        $row['status'] = '';
      }
    }

    return $data;
  }

  public function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['age']['field']['id'] = 'boolean';
    return $data;
  }

  /** * {@inheritdoc} */
  public function dataSet() {
    $data = parent::dataSet();
    $data[0]['age'] = 0;
    $data[3]['age'] = 0;
    return $data;
  }

  /** * Tests the setting and output of custom labels for boolean values. */
  public function testCustomOption() {
    // Add the boolean field handler to the test view.     $view = Views::getView('test_view');
    
$view->setDisplay();

    $view->initQuery();
    $this->assertInstanceOf(QueryTestPlugin::class$view->query);
  }

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

    $view->initQuery();
    $view->query->setAllItems($this->dataSet());

    $this->executeView($view);
    $this->assertNotEmpty($view->result, 'Make sure the view result got filled');
  }

  /** * Tests methods provided by the QueryPluginBase. * * @see \Drupal\views\Plugin\views\query\QueryPluginBase */
  protected function queryMethodsTests() {
    

class FieldFileSizeTest extends ViewsKernelTestBase {

  /** * Views used by this test. * * @var array */
  public static $testViews = ['test_view'];

  public function dataSet() {
    $data = parent::dataSet();
    $data[0]['age'] = 0;
    $data[1]['age'] = 10;
    $data[2]['age'] = 1000;
    $data[3]['age'] = 10000;

    return $data;
  }

  public function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['age']['field']['id'] = 'file_size';

    
$id_field->additional_fields['job'] = 'job';
    // Choose also a field alias key which doesn't match to the table field.     $id_field->additional_fields['created_test'] = ['table' => 'views_test_data', 'field' => 'created'];
    $view->build();

    // Make sure the field aliases have the expected value.     $this->assertEquals('views_test_data_job', $id_field->aliases['job']);
    $this->assertEquals('views_test_data_created', $id_field->aliases['created_test']);

    $this->executeView($view);
    // Tests the getValue method with and without a field aliases.     foreach ($this->dataSet() as $key => $row) {
      $id = $key + 1;
      $result = $view->result[$key];
      $this->assertEquals($id$id_field->getValue($result));
      $this->assertEquals($row['job']$id_field->getValue($result, 'job'));
      $this->assertEquals($row['created']$id_field->getValue($result, 'created_test'));
    }
  }

  /** * Asserts that a string is part of another string. * * @param string $haystack * The value to search in. * @param string $needle * The value to search for. * @param string $message * (optional) A message to display with the assertion. Do not translate * messages: use \Drupal\Component\Render\FormattableMarkup to embed * variables in the message text, not t(). If left blank, a default message * will be displayed. * * @internal */
'not null' => FALSE,
      'size' => 'big',
    ];

    return $schema;
  }

  /** * An extended test dataset. */
  protected function dataSet() {
    $dataset = parent::dataSet();
    $dataset[0]['description'] = 'John Winston Ono Lennon, MBE (9 October 1940 – 8 December 1980) was an English musician and singer-songwriter who rose to worldwide fame as one of the founding members of The Beatles, one of the most commercially successful and critically acclaimed acts in the history of popular music. Along with fellow Beatle Paul McCartney, he formed one of the most successful songwriting partnerships of the 20th century.';
    $dataset[1]['description'] = 'George Harrison,[1] MBE (25 February 1943 – 29 November 2001)[2] was an English rock guitarist, singer-songwriter, actor and film producer who achieved international fame as lead guitarist of The Beatles.';
    $dataset[2]['description'] = 'Richard Starkey, MBE (born 7 July 1940), better known by his stage name Ringo Starr, is an English musician, singer-songwriter, and actor who gained worldwide fame as the drummer for The Beatles.';
    $dataset[3]['description'] = 'Sir James Paul McCartney, MBE (born 18 June 1942) is an English musician, singer-songwriter and composer. Formerly of The Beatles (1960–1970) and Wings (1971–1981), McCartney is the most commercially successful songwriter in the history of popular music, according to Guinness World Records.[1]';
    $dataset[4]['description'] = NULL;

    return $dataset;
  }

  /** * Build and return a Page view of the views_test_data table. * * @return \Drupal\views\ViewExecutable */

  protected function mappedOutputHelper(ViewExecutable $view) {
    $output = $view->preview();
    $rendered_output = \Drupal::service('renderer')->renderRoot($output);
    $this->storeViewPreview($rendered_output);
    $rows = $this->elements->body->div->div;
    $data_set = $this->dataSet();

    $count = 0;
    foreach ($rows as $row) {
      $attributes = $row->attributes();
      $class = (string) $attributes['class'][0];
      $this->assertStringContainsString('views-row-mapping-test', $class, 'Make sure that each row has the correct CSS class.');

      foreach ($row->div as $field) {
        // Split up the field-level class, the first part is the mapping name         // and the second is the field ID.         $field_attributes = $field->attributes();
        
/** * Tests token replacement of [view:total-rows] when pager is disabled. * * It calls "Some" views pager plugin. */
  public function testTokenReplacementWithSpecificNumberOfItems(): void {
    $token_handler = \Drupal::token();
    $view = Views::getView('test_tokens');
    $view->setDisplay('page_4');
    $this->executeView($view);

    $total_rows_in_table = ViewTestData::dataSet();
    $this->assertTrue($view->get_total_rows, 'The query was set to calculate the total number of rows.');
    $this->assertGreaterThan(3, count($total_rows_in_table));

    $expected = [
      '[view:label]' => 'Test tokens',
      '[view:id]' => 'test_tokens',
      '[view:url]' => $view->getUrl(NULL, 'page_4')
        ->setAbsolute(TRUE)
        ->toString(),
      '[view:total-rows]' => '3',
    ];

    
'argument' => ['id' => 'date'],
      'filter' => ['id' => 'date'],
      'sort' => ['id' => 'date'],
    ];
    return $data;
  }

  /** * {@inheritdoc} */
  public function dataSet() {
    $datas = parent::dataSet();
    foreach ($datas as $i => $data) {
      $datas[$i]['destroyed'] = gmmktime(0, 0, 0, 1, 1, 2050);
    }
    return $datas;
  }

  /** * Sets up functional test of the views date field. */
  public function testFieldDate() {
    $view = Views::getView('test_view');
    
Home | Imprint | This part of the site doesn't use cookies.