public function PathautoEntityWithStringIdTest::testEntityWithStringId in Pathauto 8
Test aliasing entities with long string ID.
@dataProvider entityWithStringIdProvider
Parameters
string|int $id: The entity ID
string $expected_key: The expected key for 'pathauto_state.*' collections.
File
- tests/src/ Kernel/ PathautoEntityWithStringIdTest.php, line 86 
Class
- PathautoEntityWithStringIdTest
- Tests auto-aliasing of entities that use string IDs.
Namespace
Drupal\Tests\pathauto\KernelCode
public function testEntityWithStringId($id, $expected_key) {
  $entity = PathautoStringIdTest::create([
    'id' => $id,
    'name' => $name = $this
      ->randomMachineName(),
  ]);
  $entity
    ->save();
  // Check that the path was generated.
  $this
    ->assertEntityAlias($entity, mb_strtolower("/{$name}"));
  // Check that the path auto state was saved with the expected key.
  $value = \Drupal::keyValue('pathauto_state.pathauto_string_id_test')
    ->get($expected_key);
  $this
    ->assertEquals(PathautoState::CREATE, $value);
  $context = [];
  // Batch delete uses the key-value store collection 'pathauto_state.*. We
  // test that after a bulk delete all aliases are removed. Running only once
  // the batch delete process is enough as the batch size is 100.
  $this->aliasType
    ->batchDelete($context);
  // Check that the paths were removed on batch delete.
  $this
    ->assertNoEntityAliasExists($entity, "/{$name}");
}