You are here

public function SqlContentEntityStorageSchemaTest::providerSchemaCastValue in Drupal 8

Provides data for testCastValue().

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 1586

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function providerSchemaCastValue() {
  $cases = [];

  // Tests NULL values.
  $cases[] = [
    NULL,
    NULL,
    [
      'not null' => FALSE,
    ],
  ];
  $cases[] = [
    0,
    NULL,
    [
      'not null' => TRUE,
      'type' => 'int',
    ],
  ];
  $cases[] = [
    0,
    NULL,
    [
      'not null' => TRUE,
      'type' => 'serial',
    ],
  ];
  $cases[] = [
    0.0,
    NULL,
    [
      'not null' => TRUE,
      'type' => 'float',
    ],
  ];
  $cases[] = [
    '',
    NULL,
    [
      'not null' => TRUE,
      'type' => 'varchar',
    ],
  ];

  // Tests cast to int and serial.
  $cases[] = [
    1,
    '1.001',
    [
      'type' => 'int',
    ],
  ];
  $cases[] = [
    2,
    2.6,
    [
      'type' => 'int',
    ],
  ];
  $cases[] = [
    3,
    '3.6',
    [
      'type' => 'serial',
    ],
  ];

  // Tests float.
  $cases[] = [
    1.001,
    '1.001',
    [
      'type' => 'float',
    ],
  ];
  $cases[] = [
    2.6,
    2.6,
    [
      'type' => 'float',
    ],
  ];

  // Tests other column types casts to string.
  $cases[] = [
    '1',
    1,
    [
      'type' => 'varchar',
    ],
  ];
  $cases[] = [
    '2',
    '2',
    [
      'type' => 'varchar',
    ],
  ];
  return $cases;
}