schemaDefinition example


  }

  /** * 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.     \Drupal::state()->set('views_test_data_schema', $this->schemaDefinition());
    \Drupal::state()->set('views_test_data_views_data', $this->viewsData());

    \Drupal::service('module_installer')->install(['views_test_data']);
    $this->resetAll();
    $this->rebuildContainer();
    $this->container->get('module_handler')->reload();

    // Load the test dataset.     $data_set = $this->dataSet();
    $query = Database::getConnection()->insert('views_test_data')
      ->fields(array_keys($data_set[0]));
    
parent::setUp();
    $this->installConfig(['language']);

    // Create another language beside English.     ConfigurableLanguage::create(['id' => 'xx-lolspeak', 'label' => 'Lolspeak'])->save();
  }

  /** * {@inheritdoc} */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();
    $schema['views_test_data']['fields']['langcode'] = [
      'description' => 'The {language}.langcode of this beatle.',
      'type' => 'varchar',
      'length' => 12,
      'default' => '',
    ];

    return $schema;
  }

  /** * {@inheritdoc} */
foreach ($view->result as $delta => $row) {
      [$value$formatted_value$granularity] = $this->ages[$delta];
      $view->field['age']->options['granularity'] = $granularity;
      $this->assertEquals($formatted_value$view->field['age']->advancedRender($row));
    }
  }

  /** * Overrides \Drupal\views\Tests\ViewUnitTestBase::schemaDefinition(). */
  protected function schemaDefinition() {
    $schema_definition = parent::schemaDefinition();
    $schema_definition['views_test_data']['fields']['age']['not null'] = FALSE;
    return $schema_definition;
  }

  /** * Overrides \Drupal\views\Tests\ViewUnitTestBase::viewsData(). */
  protected function viewsData() {
    $data = parent::viewsData();
    $data['views_test_data']['age']['field']['id'] = 'time_interval';
    return $data;
  }

  protected $columnMap = [
    'views_test_data_id' => 'id',
  ];

  /** * {@inheritdoc} */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();

    $schema['views_test_data']['fields']['status'] = [
      'description' => 'The status of this record',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
    ];

    return $schema;
  }

  
$this->drupalLogin($admin_user);
  }

  /** * 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.     \Drupal::state()->set('views_test_data_schema', $this->schemaDefinition());
    \Drupal::state()->set('views_test_data_views_data', $this->viewsData());

    \Drupal::service('module_installer')->install(['views_test_data']);
    $this->resetAll();
    $this->rebuildContainer();
    $this->container->get('module_handler')->reload();

    // Load the test dataset.     $data_set = $this->dataSet();
    $query = Database::getConnection()->insert('views_test_data')
      ->fields(array_keys($data_set[0]));
    


  /** * Check if the table exists and create it if not. * * @return bool * TRUE if the table exists, FALSE if it does not exists. */
  protected function ensureTableExists() {
    try {
      $database_schema = $this->connection->schema();
      $database_schema->createTable($this->table, $this->schemaDefinition());
    }
    // If the table already exists, then attempting to recreate it will throw an     // exception. In this case just catch the exception and do nothing.     catch (DatabaseException $e) {
    }
    catch (\Exception $e) {
      return FALSE;
    }
    return TRUE;
  }

  
'batch' => serialize($batch),
      ])
      ->execute();
  }

  /** * Check if the table exists and create it if not. */
  protected function ensureTableExists() {
    try {
      $database_schema = $this->connection->schema();
      $schema_definition = $this->schemaDefinition();
      $database_schema->createTable(static::TABLE_NAME, $schema_definition);
    }
    // If another process has already created the batch table, attempting to     // recreate it will throw an exception. In this case just catch the     // exception and do nothing.     catch (DatabaseException $e) {
    }
    catch (\Exception $e) {
      return FALSE;
    }
    return TRUE;
  }

  protected function setUpFixtures() {
    // First install the system module. Many Views have Page displays have menu     // links, and for those to work, the system menus must already be present.     $this->installConfig(['system']);

    /** @var \Drupal\Core\State\StateInterface $state */
    $state = $this->container->get('state');
    // Define the schema and views data variable before enabling the test module.     $state->set('views_test_data_schema', $this->schemaDefinition());
    $state->set('views_test_data_views_data', $this->viewsData());
    $this->container->get('views.views_data')->clear();

    $this->installConfig(['views', 'views_test_config', 'views_test_data']);
    foreach ($this->schemaDefinition() as $table => $schema) {
      $this->installSchema('views_test_data', $table);
    }

    $this->container->get('router.builder')->rebuild();

    // Load the test dataset.

    }
    return [];
  }

  /** * Check if the cache tags table exists and create it if not. */
  protected function ensureTableExists() {
    try {
      $database_schema = $this->connection->schema();
      $schema_definition = $this->schemaDefinition();
      $database_schema->createTable('cachetags', $schema_definition);
    }
    // If another process has already created the cachetags table, attempting to     // recreate it will throw an exception. In this case just catch the     // exception and do nothing.     catch (DatabaseException $e) {
    }
    catch (\Exception $e) {
      return FALSE;
    }
    return TRUE;
  }
ViewTestData::createTestViews(static::class['node_test_views']);
  }

  /** * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition(). * * Adds a uid column to test the relationships. * * @internal */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();

    $schema['views_test_data']['fields']['uid'] = [
      'description' => "The {users}.uid of the author of the beatle entry.",
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ];

    return $schema;
  }

  
$data['views_test_data']['name']['filter']['allow empty'] = TRUE;
    $data['views_test_data']['job']['filter']['allow empty'] = FALSE;
    $data['views_test_data']['description'] = $data['views_test_data']['name'];

    return $data;
  }

  /** * {@inheritdoc} */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();
    $schema['views_test_data']['fields']['description'] = [
      'description' => "A person's description",
      'type' => 'text',
      'not null' => FALSE,
      'size' => 'big',
    ];

    return $schema;
  }

  /** * An extended test dataset. */
->condition('value', $lock_id)
        ->execute();
    }
  }

  /** * Check if the semaphore table exists and create it if not. */
  protected function ensureTableExists() {
    try {
      $database_schema = $this->database->schema();
      $schema_definition = $this->schemaDefinition();
      $database_schema->createTable(static::TABLE_NAME, $schema_definition);
    }
    // If another process has already created the semaphore table, attempting to     // recreate it will throw an exception. In this case just catch the     // exception and do nothing.     catch (DatabaseException $e) {
    }
    catch (\Exception $e) {
      return FALSE;
    }
    return TRUE;
  }
/** * Views used by this test. * * @var array */
  public static $testViews = ['test_view'];

  /** * {@inheritdoc} */
  public function schemaDefinition() {
    $schema = parent::schemaDefinition();
    $schema['views_test_data']['fields']['destroyed'] = [
      'description' => "The destruction date of this record",
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => FALSE,
      'default' => 0,
      'size' => 'big',
    ];
    return $schema;
  }

  

  protected function preSave(array &$link, array $original) {
    static $schema_fields$schema_defaults;
    if (empty($schema_fields)) {
      $schema = static::schemaDefinition();
      $schema_fields = $schema['fields'];
      foreach ($schema_fields as $name => $spec) {
        if (isset($spec['default'])) {
          $schema_defaults[$name] = $spec['default'];
        }
      }
    }

    // Try to find a parent link. If found, assign it and derive its menu.     $parent = $this->findParent($link$original);
    if ($parent) {
      
$this->catchException($e);
    }
  }

  /** * Check if the cache bin exists and create it if not. */
  protected function ensureBinExists() {
    try {
      $database_schema = $this->connection->schema();
      if (!$database_schema->tableExists($this->bin)) {
        $schema_definition = $this->schemaDefinition();
        $database_schema->createTable($this->bin, $schema_definition);
        return TRUE;
      }
    }
    // If another process has already created the cache table, attempting to     // recreate it will throw an exception. In this case just catch the     // exception and do nothing.     catch (DatabaseException $e) {
      return TRUE;
    }
    return FALSE;
  }
Home | Imprint | This part of the site doesn't use cookies.