getBaseTables example

// Test setting and getting the offset.     $rand = rand();
    $view->setOffset($rand);
    $this->assertEquals($rand$view->getOffset());

    // Test the getBaseTable() method.     $expected = [
      'views_test_data' => TRUE,
      '#global' => TRUE,
    ];
    $this->assertSame($expected$view->getBaseTables());

    // Test response methods.     $this->assertInstanceOf(Response::class$view->getResponse());
    $new_response = new Response();
    $view->setResponse($new_response);
    $this->assertSame(spl_object_hash($view->getResponse())spl_object_hash($new_response), 'New response object correctly set.');

    // Test the getPath() method.     $path = $this->randomMachineName();
    $view->displayHandlers->get('page_1')->overrideOption('path', $path);
    $view->setDisplay('page_1');
    
$this->assertEquals($entry['message']$view->style_plugin->getField($index, 'message'));
    }
  }

  /** * Tests the relationship with the users_field_data table. */
  public function testRelationship() {
    $view = Views::getView('dblog_integration_test');
    $view->setDisplay('page_1');
    // The uid relationship should now join to the {users_field_data} table.     $base_tables = $view->getBaseTables();
    $this->assertArrayHasKey('users_field_data', $base_tables);
    $this->assertArrayNotHasKey('users', $base_tables);
    $this->assertArrayHasKey('watchdog', $base_tables);
  }

  /** * Tests views can be filtered by severity and log type. */
  public function testFiltering() {
    // Remove the watchdog entries added by the potential batch process.     $this->container->get('database')->truncate('watchdog')->execute();
    
$view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['description'] = $this->randomMachineName(16);
    $view['page[create]'] = FALSE;
    $view['show[type]'] = 'article';
    $view['show[sort]'] = 'changed:DESC';
    $this->submitForm($view, 'Save and edit');

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

    $this->assertEquals(['node_field_revision' => TRUE, '#global' => TRUE, 'node_field_data' => TRUE]$view->getBaseTables());

    // Check for the default filters.     $this->assertEquals('node_field_revision', $view->filter['status']->table);
    $this->assertEquals('status', $view->filter['status']->field);
    $this->assertEquals('1', $view->filter['status']->value);
    $this->assertEquals('node_field_data', $view->filter['type']->table);

    $this->executeView($view);

    $this->assertIdenticalResultset($view[['vid' => 1]['vid' => 3]['vid' => 2]['vid' => 4]],
      ['vid' => 'vid']);

    
if (!empty($types[$type]['type'])) {
      $type = $types[$type]['type'];
    }

    $form['#title'] = $this->t('Add @type', ['@type' => $ltitle]);
    $form['#section'] = $display_id . 'add-handler';

    // Add the display override dropdown.     views_ui_standard_display_dropdown($form$form_state$section);

    // Figure out all the base tables allowed based upon what the relationships provide.     $base_tables = $executable->getBaseTables();
    $options = Views::viewsDataHelper()->fetchFields(array_keys($base_tables)$type$display->useGroupBy()$form_state->get('type'));

    if (!empty($options)) {
      $form['override']['controls'] = [
        '#theme_wrappers' => ['container'],
        '#id' => 'views-filterable-options-controls',
        '#attributes' => ['class' => ['form--inline', 'views-filterable-options-controls']],
      ];
      $form['override']['controls']['options_search'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Search'),
      ];
Home | Imprint | This part of the site doesn't use cookies.