function FieldStorageIndexesValidationTest::testInvalidIndexes

Same name and namespace in other branches
  1. 11.x core/modules/field/tests/src/Kernel/Config/FieldStorageIndexesValidationTest.php \Drupal\Tests\field\Kernel\Config\FieldStorageIndexesValidationTest::testInvalidIndexes()

Test invalid indexes.

Attributes

#[Test]

File

core/modules/field/tests/src/Kernel/Config/FieldStorageIndexesValidationTest.php, line 77

Class

FieldStorageIndexesValidationTest
Tests validation for field storage indexes config.

Namespace

Drupal\Tests\field\Kernel\Config

Code

public function testInvalidIndexes() : void {
  $config = \Drupal::configFactory()->getEditable('field.storage.entity_test.field_test_import');
  $typed_config_manager = \Drupal::service('config.typed');
  $invalid_indexes = [
    [
      '' => [
        'value',
      ],
    ],
    [
      'foo2' => [
        '',
      ],
    ],
    [
      'foo3' => [
        'value' => 1,
      ],
    ],
    [
      'foo4' => [
        'value' => 'value',
      ],
    ],
    [
      'foo5' => 'value',
    ],
    [
      'foo6' => [
        [
          'value',
          0,
        ],
      ],
    ],
    [
      'foo7' => [
        [
          'value',
          -50,
        ],
      ],
    ],
    [
      'foo8' => [
        [
          'value',
          '1',
        ],
      ],
    ],
    [
      'foo9' => [
        [
          'value',
          127,
          2,
        ],
      ],
    ],
    [
      'foo10' => [
        [],
      ],
    ],
    [
      'foo11' => [
        [
          '',
        ],
      ],
    ],
    [
      'foo12' => [
        'value',
        127,
      ],
      'bar12' => [
        'value',
        127,
      ],
    ],
    [
      'foo13' => [
        [
          'value',
        ],
        [
          'format',
        ],
      ],
    ],
    [
      'foo14' => [
        'value',
        'format',
      ],
      'bar3' => [
        'value',
        [
          'format',
        ],
      ],
    ],
    [
      0 => [
        'value',
      ],
    ],
  ];
  foreach ($invalid_indexes as $indexes) {
    $config->set('indexes', $indexes);
    $typed_config = $typed_config_manager->createFromNameAndData($config->getName(), $config->get());
    $this->assertNotCount(0, $typed_config->validate());
  }
}

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