8.3.x CaseSensitivityTest.php public CaseSensitivityTest::testCaseSensitiveInsert()
8.0.x CaseSensitivityTest.php CaseSensitivityTest::testCaseSensitiveInsert()
8.1.x CaseSensitivityTest.php CaseSensitivityTest::testCaseSensitiveInsert()
8.2.x CaseSensitivityTest.php CaseSensitivityTest::testCaseSensitiveInsert()
8.4.x CaseSensitivityTest.php public CaseSensitivityTest::testCaseSensitiveInsert()

Tests BINARY collation in MySQL.

File

core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php, line 14

Class

CaseSensitivityTest
Tests handling case sensitive collation.

Namespace

Drupal\KernelTests\Core\Database

Code

function testCaseSensitiveInsert() {
  $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField();

  db_insert('test')
    ->fields(array(
      'name' => 'john', // <- A record already exists with name 'John'.
      'age' => 2,
      'job' => 'Baby',
    ))
    ->execute();

  $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField();
  $this->assertIdentical($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
  $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'john'))->fetchField();
  $this->assertIdentical($saved_age, '2', 'Can retrieve after inserting.');
}