You are here

private function UiTest::assertThatAdminCanAddFrontEndEnvironment in Build Hooks 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/UiTest.php \Drupal\Tests\build_hooks\Functional\UiTest::assertThatAdminCanAddFrontEndEnvironment()

Asserts admin can create new environment.

Return value

\Drupal\build_hooks\Entity\FrontendEnvironmentInterface Created entity.

1 call to UiTest::assertThatAdminCanAddFrontEndEnvironment()
UiTest::testBuildHooksUi in tests/src/Functional/UiTest.php
Test build hooks UI.

File

tests/src/Functional/UiTest.php, line 166

Class

UiTest
Defines a class for testing build hooks UI.

Namespace

Drupal\Tests\build_hooks\Functional

Code

private function assertThatAdminCanAddFrontEndEnvironment() : FrontendEnvironmentInterface {
  $random = mb_strtolower($this
    ->randomMachineName());
  $whiz = $this
    ->randomMachineName(2);

  // Try to submit the form with whiz length 2 characters and a long ID.
  $this
    ->submitForm([
    'id' => mb_strtolower($this
      ->randomMachineName(34)),
    'label' => $random,
    'url' => 'http://example.com/' . $random,
    'deployment_strategy' => TriggerInterface::DEPLOYMENT_STRATEGY_MANUAL,
    'settings[whiz]' => $whiz,
  ], 'Save');
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains('Whiz must contains minimum 3 characters.');
  $assert
    ->pageTextContains('Machine-readable name cannot be longer than 32 characters but is currently 34 characters long.');
  $this
    ->submitForm([
    'id' => $random,
    'label' => $random,
    'url' => 'http://example.com/' . $random,
    'deployment_strategy' => TriggerInterface::DEPLOYMENT_STRATEGY_MANUAL,
    'settings[whiz]' => $random,
  ], 'Save');
  $assert
    ->pageTextContains('The frontend environment configuration has been saved.');
  $environment = \Drupal::entityTypeManager()
    ->getStorage('frontend_environment')
    ->load($random);
  $this
    ->assertNotEmpty($environment);
  $this
    ->assertEquals($random, $environment
    ->label());

  /** @var \Drupal\build_hooks\Plugin\FrontendEnvironmentInterface $plugin */
  $plugin = $environment
    ->getPlugin();
  $this
    ->assertEquals($random, $plugin
    ->getConfiguration()['whiz']);
  $this
    ->assertEquals('build_hooks_test', $plugin
    ->getPluginId());
  return $environment;
}