You are here

public function InstallTest::testAliasCreation in Lightning Core 8.5

Tests that the sitewide contact form is aliased correctly during install.

File

modules/lightning_contact_form/tests/src/Kernel/InstallTest.php, line 30

Class

InstallTest
Tests install-time logic of Lightning Contact Form.

Namespace

Drupal\Tests\lightning_contact_form\Kernel

Code

public function testAliasCreation() {
  $this
    ->installEntitySchema('path_alias');

  // The sitewide contact form does not exist, so the install hook should not
  // try to create an alias for it.
  module_load_include('install', 'lightning_contact_form');

  // The hook will try to modify the contact form if config is not syncing.
  $this->container
    ->get('config.installer')
    ->setSyncing(TRUE);
  lightning_contact_form_install();

  /** @var \Drupal\path_alias\AliasManagerInterface $alias_manager */
  $alias_manager = $this->container
    ->get('path_alias.manager');
  $this
    ->assertSame('/contact', $alias_manager
    ->getPathByAlias('/contact'));

  // If the contact form is created while installing from config (i.e.,
  // InstallerKernel::installationAttempted() returns TRUE and config is
  // syncing), the alias should be created too.
  $GLOBALS['install_state'] = [];
  ContactForm::create([
    'id' => 'sitewide',
  ])
    ->save();
  $this
    ->assertSame('/contact/sitewide', $alias_manager
    ->getPathByAlias('/contact'));
}