function SqlContentEntityStorageTest::testCleanIds

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCleanIds()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCleanIds()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageTest::testCleanIds()

Tests entity ID sanitization.

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php, line 1382

Class

SqlContentEntityStorageTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorage @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function testCleanIds() {
    $valid_ids = [
        -1,
        0,
        1,
        '-1',
        '0',
        '1',
        0123,
        -0x1a,
        0x1afc,
        -0b111,
        0b101,
        '0123',
        '00123',
        '000123',
        '-0123',
        '-00123',
        '-000123',
        -10.0,
        -1.0,
        0.0,
        1.0,
        10.0,
        -10.0,
        -1.0,
        0.0,
        1.0,
        10.0,
    ];
    $this->fieldDefinitions = $this->mockFieldDefinitions([
        'id',
    ]);
    $this->fieldDefinitions['id']
        ->expects($this->any())
        ->method('getType')
        ->willReturn('integer');
    $this->setUpEntityStorage();
    $this->entityType
        ->expects($this->any())
        ->method('getKey')
        ->willReturnMap([
        [
            'id',
            'id',
        ],
    ]);
    $method = new \ReflectionMethod($this->entityStorage, 'cleanIds');
    $method->setAccessible(TRUE);
    $this->assertEquals($valid_ids, $method->invoke($this->entityStorage, $valid_ids));
    $invalid_ids = [
        '--1',
        '-0x1A',
        '0x1AFC',
        '-0b111',
        '0b101',
        'a',
        FALSE,
        TRUE,
        NULL,
        '32acb',
        123.123,
        123.678,
    ];
    $this->assertEquals([], $method->invoke($this->entityStorage, $invalid_ids));
}

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