You are here

class DatabaseLegacyTest in Drupal 8

Deprecation tests cases for the database layer.

@group legacy

Hierarchy

Expanded class hierarchy of DatabaseLegacyTest

File

core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php, line 22

Namespace

Drupal\KernelTests\Core\Database
View source
class DatabaseLegacyTest extends DatabaseTestBase {

  /**
   * The modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'database_test',
    'system',
  ];

  /**
   * Tests deprecation of the db_and() function.
   *
   * @expectedDeprecation db_and() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an AND conjunction: new Condition('AND'), instead. See https://www.drupal.org/node/2993033
   */
  public function testDbAnd() {
    $this
      ->assertInstanceOf(Condition::class, db_and());
  }

  /**
   * Tests deprecation of the db_condition() function.
   *
   * @expectedDeprecation db_condition() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying the desired conjunction: new Condition($conjunction), instead. See https://www.drupal.org/node/2993033
   */
  public function testDbCondition() {
    $this
      ->assertInstanceOf(Condition::class, db_condition('AND'));
  }

  /**
   * Tests deprecation of the db_or() function.
   *
   * @expectedDeprecation db_or() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an OR conjunction: new Condition('OR'), instead. See https://www.drupal.org/node/2993033
   */
  public function testDbOr() {
    $this
      ->assertInstanceOf(Condition::class, db_or());
  }

  /**
   * Tests deprecation of the db_xor() function.
   *
   * @expectedDeprecation db_xor() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying a XOR conjunction: new Condition('XOR'), instead. See https://www.drupal.org/node/2993033
   */
  public function testDbXor() {
    $this
      ->assertInstanceOf(Condition::class, db_xor());
  }

  /**
   * Tests the db_table_exists() function.
   *
   * @expectedDeprecation db_table_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2993033
   */
  public function testDbTableExists() {
    $this
      ->assertTrue(db_table_exists('test'));
  }

  /**
   * Tests the db_find_tables() function.
   *
   * @expectedDeprecation db_find_tables() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use $injected_database->schema()->findTables($table_expression) instead. See https://www.drupal.org/node/2993033
   */
  public function testDbFindTables() {
    $expected = [
      'test_people' => 'test_people',
      'test_people_copy' => 'test_people_copy',
    ];
    $this
      ->assertEquals($expected, db_find_tables('test_people%'));
  }

  /**
   * Tests the db_set_active() function.
   *
   * @expectedDeprecation db_set_active() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2993033
   */
  public function testDbSetActive() {
    $get_active_db = $this->connection
      ->getKey();
    $this
      ->assert(db_set_active($get_active_db), 'Database connection is active');
  }

  /**
   * Tests the db_drop_table() function.
   *
   * @expectedDeprecation db_drop_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2993033
   */
  public function testDbDropTable() {
    $this
      ->assertFalse(db_drop_table('temp_test_table'));
  }

  /**
   * Tests deprecation of the db_next_id() function.
   *
   * @expectedDeprecation db_next_id() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call nextId() on it. For example, $injected_database->nextId($existing_id). See https://www.drupal.org/node/2993033
   */
  public function testDbNextId() {
    $this
      ->installSchema('system', 'sequences');
    $this
      ->assertEquals(1001, db_next_id(1000));
  }

  /**
   * Tests the db_change_field() function is deprecated.
   *
   * @expectedDeprecation db_change_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
   * @doesNotPerformAssertions
   */
  public function testDbChangeField() {
    $spec = [
      'description' => "A new person's name",
      'type' => 'varchar_ascii',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
      'binary' => TRUE,
    ];
    db_change_field('test', 'name', 'nosuchcolumn', $spec);
  }

  /**
   * Tests deprecation of the db_field_set_default() function.
   *
   * @expectedDeprecation db_field_set_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
   * @expectedDeprecation fieldSetDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
   * @doesNotPerformAssertions
   */
  public function testDbFieldSetDefault() {
    db_field_set_default('test', 'job', 'baz');
  }

  /**
   * Tests deprecation of the db_field_set_no_default() function.
   *
   * @expectedDeprecation db_field_set_no_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
   * @expectedDeprecation fieldSetNoDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
   * @doesNotPerformAssertions
   */
  public function testDbFieldSetNoDefault() {
    db_field_set_no_default('test_null', 'age');
  }

  /**
   * Tests Schema::fieldSetDefault and Schema::fieldSetNoDefault.
   *
   * @expectedDeprecation fieldSetDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
   * @expectedDeprecation fieldSetNoDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
   */
  public function testSchemaFieldDefaultChange() {

    // Create a table.
    $table_specification = [
      'description' => 'Schema table description.',
      'fields' => [
        'id' => [
          'type' => 'int',
          'default' => NULL,
        ],
        'test_field' => [
          'type' => 'int',
          'not null' => TRUE,
          'description' => 'Test field',
        ],
      ],
    ];
    $this->connection
      ->schema()
      ->createTable('test_table', $table_specification);

    // An insert without a value for the column 'test_field' should fail.
    try {
      $this->connection
        ->insert('test_table')
        ->fields([
        'id' => 1,
      ])
        ->execute();
      $this
        ->fail('Expected DatabaseException, none was thrown.');
    } catch (DatabaseException $e) {
      $this
        ->assertEquals(0, $this->connection
        ->select('test_table')
        ->countQuery()
        ->execute()
        ->fetchField());
    }

    // Add a default value to the column.
    $this->connection
      ->schema()
      ->fieldSetDefault('test_table', 'test_field', 0);

    // The insert should now succeed.
    $this->connection
      ->insert('test_table')
      ->fields([
      'id' => 1,
    ])
      ->execute();
    $this
      ->assertEquals(1, $this->connection
      ->select('test_table')
      ->countQuery()
      ->execute()
      ->fetchField());

    // Remove the default.
    $this->connection
      ->schema()
      ->fieldSetNoDefault('test_table', 'test_field');

    // The insert should fail again.
    try {
      $this->connection
        ->insert('test_table')
        ->fields([
        'id' => 2,
      ])
        ->execute();
      $this
        ->fail('Expected DatabaseException, none was thrown.');
    } catch (DatabaseException $e) {
      $this
        ->assertEquals(1, $this->connection
        ->select('test_table')
        ->countQuery()
        ->execute()
        ->fetchField());
    }
  }

  /**
   * Tests deprecation of the db_transaction() function.
   *
   * @expectedDeprecation db_transaction is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call startTransaction() on it. For example, $injected_database->startTransaction($name). See https://www.drupal.org/node/2993033
   */
  public function testDbTransaction() {
    $this
      ->assertInstanceOf(Transaction::class, db_transaction());
  }

  /**
   * Tests the db_close() function.
   *
   * @expectedDeprecation db_close() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::closeConnection() instead. See https://www.drupal.org/node/2993033
   */
  public function testDbClose() {
    $this
      ->assertTrue(Database::isActiveConnection(), 'Database connection is active');
    db_close();
    $this
      ->assertFalse(Database::isActiveConnection(), 'Database connection is not active');
  }

  /**
   * Tests deprecation of the db_add_field() function.
   *
   * @expectedDeprecation db_add_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033
   */
  public function testDbAddField() {
    $this
      ->assertFalse($this->connection
      ->schema()
      ->fieldExists('test', 'anint'));
    db_add_field('test', 'anint', [
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
      'description' => 'Added int column.',
    ]);
    $this
      ->assertTrue($this->connection
      ->schema()
      ->fieldExists('test', 'anint'));
  }

  /**
   * Tests deprecation of the db_drop_field() function.
   *
   * @expectedDeprecation db_drop_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropField() on it. For example, $injected_database->schema()->dropField($table, $field). See https://www.drupal.org/node/2993033
   */
  public function testDbDropField() {
    $this
      ->assertTrue($this->connection
      ->schema()
      ->fieldExists('test', 'age'));
    $this
      ->assertTrue(db_drop_field('test', 'age'));
    $this
      ->assertFalse($this->connection
      ->schema()
      ->fieldExists('test', 'age'));
  }

  /**
   * Tests deprecation of the db_field_exists() function.
   *
   * @expectedDeprecation db_field_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033
   */
  public function testDbFieldExists() {
    $this
      ->assertTrue(db_field_exists('test', 'age'));
  }

  /**
   * Tests deprecation of the db_field_names() function.
   *
   * @expectedDeprecation db_field_names() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldNames() on it. For example, $injected_database->schema()->fieldNames($fields). See https://www.drupal.org/node/2993033
   */
  public function testDbFieldNames() {
    $this
      ->assertSame([
      'test_field',
    ], db_field_names([
      'test_field',
    ]));
  }

  /**
   * Tests deprecation of the db_create_table() function.
   *
   * @expectedDeprecation db_create_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033
   */
  public function testDbCreateTable() {
    $name = 'test_create_table';
    $table = [
      'fields' => [
        'id' => [
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
      ],
      'primary key' => [
        'id',
      ],
    ];
    db_create_table($name, $table);
    $this
      ->assertTrue($this->connection
      ->schema()
      ->tableExists($name));
  }

  /**
   * Tests deprecation of the db_merge() function.
   *
   * @expectedDeprecation db_merge() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call merge() on it. For example, $injected_database->merge($table, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbMerge() {
    $this
      ->assertInstanceOf(Merge::class, db_merge('test'));
  }

  /**
   * Tests deprecation of the db_driver() function.
   *
   * @expectedDeprecation db_driver() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call driver() on it. For example, $injected_database->driver($string). See https://www.drupal.org/node/2993033
   */
  public function testDbDriver() {
    $this
      ->assertNotNull(db_driver());
  }

  /**
   * Tests deprecation of the db_escape_field() function.
   *
   * @expectedDeprecation db_escape_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeField() on it. For example, $injected_database->escapeField($field). See https://www.drupal.org/node/2993033
   */
  public function testDbEscapeField() {
    $this
      ->assertNotNull(db_escape_field('test'));
  }

  /**
   * Tests deprecation of the db_like() function.
   *
   * @expectedDeprecation db_like() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeLike() on it. For example, $injected_database->escapeLike($string). See https://www.drupal.org/node/2993033
   */
  public function testDbLike() {
    $this
      ->assertSame('test\\%', db_like('test%'));
  }

  /**
   * Tests deprecation of the db_escape_table() function.
   *
   * @expectedDeprecation db_escape_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeTable() on it. For example, $injected_database->escapeTable($table). See https://www.drupal.org/node/2993033
   */
  public function testDbEscapeTable() {
    $this
      ->assertNotNull(db_escape_table('test'));
  }

  /**
   * Tests deprecation of the db_rename_table() function.
   *
   * @expectedDeprecation db_rename_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call renameTable() on it. For example, $injected_database->schema()->renameTable($table, $new_name). See https://www.drupal.org/node/2993033
   */
  public function testDbRenameTable() {
    $this
      ->assertTrue($this->connection
      ->schema()
      ->tableExists('test'));
    db_rename_table('test', 'test_rename');
    $this
      ->assertTrue($this->connection
      ->schema()
      ->tableExists('test_rename'));
  }

  /**
   * Tests deprecation of the db_drop_index() function.
   *
   * @expectedDeprecation db_drop_index() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropIndex() on it. For example, $injected_database->schema()->dropIndex($table, $name). See https://www.drupal.org/node/2993033
   */
  public function testDbDropIndex() {
    $this
      ->assertFalse(db_drop_index('test', 'no_such_index'));
  }

  /**
   * Tests deprecation of the db_index_exists() function.
   *
   * @expectedDeprecation db_index_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call indexExists() on it. For example, $injected_database->schema()->indexExists($table, $name). See https://www.drupal.org/node/2993033
   */
  public function testDbIndexExists() {
    $this
      ->assertFalse(db_index_exists('test', 'no_such_index'));
  }

  /**
   * Tests deprecation of the db_drop_unique_key() function.
   *
   * @expectedDeprecation db_drop_unique_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropUniqueKey() on it. For example, $injected_database->schema()->dropUniqueKey($table, $name). See https://www.drupal.org/node/2993033
   */
  public function testDbDropUniqueKey() {
    $this
      ->assertTrue(db_drop_unique_key('test', 'name'));
  }

  /**
   * Tests deprecation of the db_add_unique_key() function.
   *
   * @expectedDeprecation db_add_unique_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields). See https://www.drupal.org/node/2993033
   * @doesNotPerformAssertions
   */
  public function testDbAddUniqueKey() {
    db_add_unique_key('test', 'age', [
      'age',
    ]);
  }

  /**
   * Tests deprecation of the db_drop_primary_key() function.
   *
   * @expectedDeprecation db_drop_primary_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropPrimaryKey() on it. For example, $injected_database->schema()->dropPrimaryKey($table). See https://www.drupal.org/node/2993033
   */
  public function testDbDropPrimaryKey() {
    $this
      ->assertTrue(db_drop_primary_key('test_people'));
  }

  /**
   * Tests deprecation of the db_add_primary_key() function.
   *
   * @expectedDeprecation db_add_primary_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields). See https://www.drupal.org/node/2993033
   * @doesNotPerformAssertions
   */
  public function testDbAddPrimaryKey() {
    $this->connection
      ->schema()
      ->dropPrimaryKey('test_people');
    db_add_primary_key('test_people', [
      'job',
    ]);
  }

  /**
   * Tests the db_update() function.
   *
   * @expectedDeprecation db_update() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call call update() on it. For example, $injected_database->update($table, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbUpdate() {
    $this
      ->assertInstanceOf(Update::class, db_update('test'));
  }

  /**
   * Tests the db_query() function.
   *
   * @expectedDeprecation db_query() is deprecated in drupal:8.0.0. It will be removed before drupal:9.0.0. Instead, get a database connection injected into your service from the container and call query() on it. For example, $injected_database->query($query, $args, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbQuery() {
    $this
      ->assertInstanceOf(StatementInterface::class, db_query('SELECT name FROM {test} WHERE name = :name', [
      ':name' => "John",
    ]));
  }

  /**
   * Tests deprecation of the db_delete() function.
   *
   * @expectedDeprecation db_delete is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call delete() on it. For example, $injected_database->delete($table, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbDelete() {
    $this
      ->assertInstanceOf(Delete::class, db_delete('test'));
  }

  /**
   * Tests deprecation of the db_truncate() function.
   *
   * @expectedDeprecation db_truncate() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call truncate() on it. For example, $injected_database->truncate($table, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbTruncate() {
    $this
      ->assertInstanceOf(Truncate::class, db_truncate('test'));
  }

  /**
   * Tests deprecation of the $options 'target' key in Connection::query.
   *
   * @expectedDeprecation Passing a 'target' key to \Drupal\Core\Database\Connection::query $options argument is deprecated in drupal:8.0.x and will be removed before drupal:9.0.0. Instead, use \Drupal\Core\Database\Database::getConnection($target)->query(). See https://www.drupal.org/node/2993033
   */
  public function testDbOptionsTarget() {
    $this
      ->assertNotNull($this->connection
      ->query('SELECT * FROM {test}', [], [
      'target' => 'bar',
    ]));
  }

  /**
   * Tests deprecation of the $options 'target' key in Select.
   *
   * @expectedDeprecation Passing a 'target' key to \Drupal\Core\Database\Connection::query $options argument is deprecated in drupal:8.0.x and will be removed before drupal:9.0.0. Instead, use \Drupal\Core\Database\Database::getConnection($target)->query(). See https://www.drupal.org/node/2993033
   */
  public function testDbOptionsTargetInSelect() {
    $this
      ->assertNotNull($this->connection
      ->select('test', 't', [
      'target' => 'bar',
    ])
      ->fields('t')
      ->execute());
  }

  /**
   * Tests deprecation of the db_query_temporary() function.
   *
   * @expectedDeprecation db_query_temporary() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call queryTemporary() on it. For example, $injected_database->queryTemporary($query, $args, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbQueryTemporary() {
    $expected = $this->connection
      ->select('test')
      ->countQuery()
      ->execute()
      ->fetchField();
    $name = db_query_temporary('SELECT name FROM {test}');
    $count = $this->connection
      ->select($name)
      ->countQuery()
      ->execute()
      ->fetchField();
    $this
      ->assertSame($expected, $count);
  }

  /**
   * Tests deprecation of the db_query_range() function.
   *
   * @expectedDeprecation db_query_range() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call queryRange() on it. For example, $injected_database->queryRange($query, $from, $count, $args, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbQueryRange() {
    $count = count(db_query_range('SELECT name FROM {test}', 1, 3)
      ->fetchAll());
    $this
      ->assertSame(3, $count);
  }

  /**
   * Tests deprecation of the db_add_index() function.
   *
   * @expectedDeprecation db_add_index() is deprecated in drupal:8.0.x and will be removed in drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033
   */
  public function testDbAddIndex() {
    $table_specification = [
      'fields' => [
        'age' => [
          'description' => "The person's age",
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ],
      ],
    ];
    $this
      ->assertNull(db_add_index('test', 'test', [
      'age',
    ], $table_specification));
  }

  /**
   * Tests the db_insert() function.
   *
   * @expectedDeprecation db_insert() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call insert() on it. For example, $injected_database->insert($table, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbInsert() {
    $this
      ->assertInstanceOf(Insert::class, db_insert('test'));
  }

  /**
   * Tests the db_select() function.
   *
   * @expectedDeprecation db_select() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call select() on it. For example, $injected_database->db_select($table, $alias, $options). See https://www.drupal.org/node/2993033
   */
  public function testDbSelect() {
    $this
      ->assertInstanceOf(Select::class, db_select('test'));
  }

  /**
   * Tests the db_ignore_replica() function.
   *
   * @expectedDeprecation db_ignore_replica() is deprecated in drupal:8.7.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger() instead. See https://www.drupal.org/node/2997500
   */
  public function testDbIgnoreReplica() {
    $connection = Database::getConnectionInfo('default');
    Database::addConnectionInfo('default', 'replica', $connection['default']);
    db_ignore_replica();

    /** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
    $session = \Drupal::service('session');
    $this
      ->assertTrue($session
      ->has('ignore_replica_server'));
  }

  /**
   * Tests the _db_get_target() function.
   *
   * @expectedDeprecation _db_get_target() is deprecated in drupal:8.8.0. Will be removed before drupal:9.0.0. See https://www.drupal.org/node/2993033
   */
  public function testDbGetTarget() {
    $op1 = $op2 = [
      'target' => 'replica',
    ];
    $this
      ->assertEquals('replica', _db_get_target($op1));
    $this
      ->assertEquals('default', _db_get_target($op2, FALSE));
    $this
      ->assertEmpty($op1);
    $this
      ->assertEmpty($op2);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertContentTrait::$content protected property The current raw content.
AssertContentTrait::$drupalSettings protected property The drupalSettings value from the current raw $content.
AssertContentTrait::$elements protected property The XML structure parsed from the current raw $content. 1
AssertContentTrait::$plainTextContent protected property The plain-text content of raw $content (text nodes).
AssertContentTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertContentTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertContentTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertContentTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertContentTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertContentTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertContentTrait::assertLink protected function Passes if a link with the specified label is found.
AssertContentTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertContentTrait::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
AssertContentTrait::assertNoEscaped protected function Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise.
AssertContentTrait::assertNoField protected function Asserts that a field does not exist with the given name or ID.
AssertContentTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertContentTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertContentTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertContentTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertContentTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertContentTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertContentTrait::assertNoLinkByHrefInMainRegion protected function Passes if a link containing a given href is not found in the main region.
AssertContentTrait::assertNoOption protected function Asserts that a select option in the current page does not exist.
AssertContentTrait::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
AssertContentTrait::assertNoPattern protected function Triggers a pass if the perl regex pattern is not found in raw content.
AssertContentTrait::assertNoRaw protected function Passes if the raw text is NOT found on the loaded page, fail otherwise.
AssertContentTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertNoTitle protected function Pass if the page title is not the given string.
AssertContentTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertContentTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertContentTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionSelectedWithDrupalSelector protected function Asserts that a select option in the current page is checked.
AssertContentTrait::assertOptionWithDrupalSelector protected function Asserts that a select option in the current page exists.
AssertContentTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertContentTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertContentTrait::assertText protected function Passes if the page (with HTML stripped) contains the text.
AssertContentTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertContentTrait::assertTextPattern protected function Asserts that a Perl regex pattern is found in the plain-text content.
AssertContentTrait::assertThemeOutput protected function Asserts themed output.
AssertContentTrait::assertTitle protected function Pass if the page title is the given string.
AssertContentTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertContentTrait::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
AssertContentTrait::buildXPathQuery protected function Builds an XPath query.
AssertContentTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertContentTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
AssertContentTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertContentTrait::getDrupalSettings protected function Gets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::getRawContent protected function Gets the current raw content.
AssertContentTrait::getSelectedItem protected function Get the selected value from a select field.
AssertContentTrait::getTextContent protected function Retrieves the plain-text content from the current raw content.
AssertContentTrait::getUrl protected function Get the current URL from the cURL handler. 1
AssertContentTrait::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
AssertContentTrait::removeWhiteSpace protected function Removes all white-space between HTML tags from the raw content.
AssertContentTrait::setDrupalSettings protected function Sets the value of drupalSettings for the currently-loaded page.
AssertContentTrait::setRawContent protected function Sets the raw content (e.g. HTML).
AssertContentTrait::xpath protected function Performs an xpath search on the contents of the internal browser.
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
DatabaseLegacyTest::$modules public static property The modules to enable. Overrides DatabaseTestBase::$modules
DatabaseLegacyTest::testDbAddField public function Tests deprecation of the db_add_field() function.
DatabaseLegacyTest::testDbAddIndex public function Tests deprecation of the db_add_index() function.
DatabaseLegacyTest::testDbAddPrimaryKey public function Tests deprecation of the db_add_primary_key() function.
DatabaseLegacyTest::testDbAddUniqueKey public function Tests deprecation of the db_add_unique_key() function.
DatabaseLegacyTest::testDbAnd public function Tests deprecation of the db_and() function.
DatabaseLegacyTest::testDbChangeField public function Tests the db_change_field() function is deprecated.
DatabaseLegacyTest::testDbClose public function Tests the db_close() function.
DatabaseLegacyTest::testDbCondition public function Tests deprecation of the db_condition() function.
DatabaseLegacyTest::testDbCreateTable public function Tests deprecation of the db_create_table() function.
DatabaseLegacyTest::testDbDelete public function Tests deprecation of the db_delete() function.
DatabaseLegacyTest::testDbDriver public function Tests deprecation of the db_driver() function.
DatabaseLegacyTest::testDbDropField public function Tests deprecation of the db_drop_field() function.
DatabaseLegacyTest::testDbDropIndex public function Tests deprecation of the db_drop_index() function.
DatabaseLegacyTest::testDbDropPrimaryKey public function Tests deprecation of the db_drop_primary_key() function.
DatabaseLegacyTest::testDbDropTable public function Tests the db_drop_table() function.
DatabaseLegacyTest::testDbDropUniqueKey public function Tests deprecation of the db_drop_unique_key() function.
DatabaseLegacyTest::testDbEscapeField public function Tests deprecation of the db_escape_field() function.
DatabaseLegacyTest::testDbEscapeTable public function Tests deprecation of the db_escape_table() function.
DatabaseLegacyTest::testDbFieldExists public function Tests deprecation of the db_field_exists() function.
DatabaseLegacyTest::testDbFieldNames public function Tests deprecation of the db_field_names() function.
DatabaseLegacyTest::testDbFieldSetDefault public function Tests deprecation of the db_field_set_default() function.
DatabaseLegacyTest::testDbFieldSetNoDefault public function Tests deprecation of the db_field_set_no_default() function.
DatabaseLegacyTest::testDbFindTables public function Tests the db_find_tables() function.
DatabaseLegacyTest::testDbGetTarget public function Tests the _db_get_target() function.
DatabaseLegacyTest::testDbIgnoreReplica public function Tests the db_ignore_replica() function.
DatabaseLegacyTest::testDbIndexExists public function Tests deprecation of the db_index_exists() function.
DatabaseLegacyTest::testDbInsert public function Tests the db_insert() function.
DatabaseLegacyTest::testDbLike public function Tests deprecation of the db_like() function.
DatabaseLegacyTest::testDbMerge public function Tests deprecation of the db_merge() function.
DatabaseLegacyTest::testDbNextId public function Tests deprecation of the db_next_id() function.
DatabaseLegacyTest::testDbOptionsTarget public function Tests deprecation of the $options 'target' key in Connection::query.
DatabaseLegacyTest::testDbOptionsTargetInSelect public function Tests deprecation of the $options 'target' key in Select.
DatabaseLegacyTest::testDbOr public function Tests deprecation of the db_or() function.
DatabaseLegacyTest::testDbQuery public function Tests the db_query() function.
DatabaseLegacyTest::testDbQueryRange public function Tests deprecation of the db_query_range() function.
DatabaseLegacyTest::testDbQueryTemporary public function Tests deprecation of the db_query_temporary() function.
DatabaseLegacyTest::testDbRenameTable public function Tests deprecation of the db_rename_table() function.
DatabaseLegacyTest::testDbSelect public function Tests the db_select() function.
DatabaseLegacyTest::testDbSetActive public function Tests the db_set_active() function.
DatabaseLegacyTest::testDbTableExists public function Tests the db_table_exists() function.
DatabaseLegacyTest::testDbTransaction public function Tests deprecation of the db_transaction() function.
DatabaseLegacyTest::testDbTruncate public function Tests deprecation of the db_truncate() function.
DatabaseLegacyTest::testDbUpdate public function Tests the db_update() function.
DatabaseLegacyTest::testDbXor public function Tests deprecation of the db_xor() function.
DatabaseLegacyTest::testSchemaFieldDefaultChange public function Tests Schema::fieldSetDefault and Schema::fieldSetNoDefault.
DatabaseTestBase::$connection protected property The database connection for testing.
DatabaseTestBase::addSampleData public static function Sets up our sample data.
DatabaseTestBase::ensureSampleDataNull public function Sets up tables for NULL handling.
DatabaseTestBase::setUp protected function Overrides KernelTestBase::setUp 1
KernelTestBase::$backupGlobals protected property Back up and restore any global variables that may be changed by tests.
KernelTestBase::$backupStaticAttributes protected property Back up and restore static class properties that may be changed by tests.
KernelTestBase::$backupStaticAttributesBlacklist protected property Contains a few static class properties for performance.
KernelTestBase::$classLoader protected property
KernelTestBase::$configImporter protected property @todo Move into Config test base class. 7
KernelTestBase::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
KernelTestBase::$container protected property
KernelTestBase::$databasePrefix protected property
KernelTestBase::$preserveGlobalState protected property Do not forward any global state from the parent process to the processes that run the actual tests.
KernelTestBase::$root protected property The app root.
KernelTestBase::$runTestInSeparateProcess protected property Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property.
KernelTestBase::$siteDirectory protected property
KernelTestBase::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 6
KernelTestBase::$vfsRoot protected property The virtual filesystem root directory.
KernelTestBase::assertPostConditions protected function 1
KernelTestBase::bootEnvironment protected function Bootstraps a basic test environment.
KernelTestBase::bootKernel private function Bootstraps a kernel for a test.
KernelTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
KernelTestBase::disableModules protected function Disables modules for this test.
KernelTestBase::enableModules protected function Enables modules for this test.
KernelTestBase::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
KernelTestBase::getDatabaseConnectionInfo protected function Returns the Database connection info to be used for this test. 1
KernelTestBase::getDatabasePrefix public function
KernelTestBase::getExtensionsForModules private function Returns Extension objects for $modules to enable.
KernelTestBase::getModulesToEnable private static function Returns the modules to enable for this test.
KernelTestBase::initFileCache protected function Initializes the FileCache component.
KernelTestBase::installConfig protected function Installs default configuration for a given list of modules.
KernelTestBase::installEntitySchema protected function Installs the storage schema for a specific entity type.
KernelTestBase::installSchema protected function Installs database tables from a module schema definition.
KernelTestBase::isTestInIsolation Deprecated protected function Returns whether the current test method is running in a separate process.
KernelTestBase::prepareTemplate protected function
KernelTestBase::register public function Registers test-specific services. Overrides ServiceProviderInterface::register 26
KernelTestBase::render protected function Renders a render array. 1
KernelTestBase::setInstallProfile protected function Sets the install profile and rebuilds the container to update it.
KernelTestBase::setSetting protected function Sets an in-memory Settings variable.
KernelTestBase::setUpBeforeClass public static function 1
KernelTestBase::setUpFilesystem protected function Sets up the filesystem, so things like the file directory. 2
KernelTestBase::stop protected function Stops test execution.
KernelTestBase::tearDown protected function 6
KernelTestBase::tearDownCloseDatabaseConnection public function @after
KernelTestBase::vfsDump protected function Dumps the current state of the virtual filesystem to STDOUT.
KernelTestBase::__get Deprecated public function BC: Automatically resolve former KernelTestBase class properties.
KernelTestBase::__sleep public function Prevents serializing any properties.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.