CaseSensitivityTest.php

Same filename in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php
  3. 11.x core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php

Namespace

Drupal\KernelTests\Core\Database

File

core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\KernelTests\Core\Database;


/**
 * Tests handling case sensitive collation.
 *
 * @group Database
 */
class CaseSensitivityTest extends DatabaseTestBase {
    
    /**
     * Tests BINARY collation in MySQL.
     */
    public function testCaseSensitiveInsert() : void {
        $num_records_before = $this->connection
            ->query('SELECT COUNT(*) FROM {test}')
            ->fetchField();
        $this->connection
            ->insert('test')
            ->fields([
            // A record already exists with name 'John'.
'name' => 'john',
            'age' => 2,
            'job' => 'Baby',
        ])
            ->execute();
        $num_records_after = $this->connection
            ->query('SELECT COUNT(*) FROM {test}')
            ->fetchField();
        $this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
        $saved_age = $this->connection
            ->query('SELECT [age] FROM {test} WHERE [name] = :name', [
            ':name' => 'john',
        ])
            ->fetchField();
        $this->assertSame('2', $saved_age, 'Can retrieve after inserting.');
    }

}

Classes

Title Deprecated Summary
CaseSensitivityTest Tests handling case sensitive collation.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.