You are here

class HelpMessageHelperTest in Acquia Lift Connector 8

HelpMessageHelper Test.

@coversDefaultClass Drupal\acquia_lift\Service\Helper\HelpMessageHelper @group acquia_lift

Hierarchy

Expanded class hierarchy of HelpMessageHelperTest

File

tests/src/Unit/Service/Helper/HelpMessageHelperTest.php, line 23
Contains \Drupal\Tests\acquia_lift\Service\Helper\HelpMessageHelperTest.

Namespace

Drupal\Tests\acquia_lift\Service\Helper
View source
class HelpMessageHelperTest extends UnitTestCase {
  use SettingsDataTrait;

  /**
   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  private $configFactory;

  /**
   * @var \Drupal\Core\Utility\LinkGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  private $linkGenerator;

  /**
   * @var \Drupal\Core\Config\ImmutableConfig|\PHPUnit_Framework_MockObject_MockObject
   */
  private $settings;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->configFactory = $this
      ->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $this->linkGenerator = $this
      ->getMock('Drupal\\Core\\Utility\\LinkGeneratorInterface');
    $this->settings = $this
      ->getMockBuilder('Drupal\\Core\\Config\\ImmutableConfig')
      ->disableOriginalConstructor()
      ->getMock();
    $this->configFactory
      ->expects($this
      ->once())
      ->method('get')
      ->with('acquia_lift.settings')
      ->willReturn($this->settings);
    $this->linkGenerator
      ->expects($this
      ->at(0))
      ->method('generate')
      ->with('Documentation')
      ->willReturn('a_documentation_link');
  }

  /**
   * Tests the getMessage() method - AdminSettingsForm, full settings.
   *
   * @covers ::getMessage
   *
   * @param string $route_name
   *
   * @dataProvider providerRouteNames
   */
  public function testGetMessageAdminSettingsFormFullSettings($route_name) {
    $full_settings = $this
      ->getValidCredentialSettings();
    $this->settings
      ->expects($this
      ->once())
      ->method('get')
      ->with('credential')
      ->willReturn($full_settings);
    $this->linkGenerator
      ->expects($this
      ->at(1))
      ->method('generate')
      ->with('Acquia Lift Web Admin')
      ->willReturn('a_web_admin_link');
    $help_message_helper = new HelpMessageHelper($this->configFactory, $this->linkGenerator);
    $message = $help_message_helper
      ->getMessage($route_name);
    $this
      ->assertEquals('You can find more info in a_documentation_link, and control your web services settings at a_web_admin_link.', $message);
  }

  /**
   * Tests the getMessage() method - AdminSettingsForm, no API URL setting.
   *
   * @covers ::getMessage
   *
   * @param string $route_name
   *
   * @dataProvider providerRouteNames
   */
  public function testGetMessageAdminSettingsFormNoApiUrl($route_name) {
    $missing_api_url_settings = $this
      ->getValidCredentialSettings();
    unset($missing_api_url_settings['api_url']);
    $this->settings
      ->expects($this
      ->once())
      ->method('get')
      ->with('credential')
      ->willReturn($missing_api_url_settings);
    $help_message_helper = new HelpMessageHelper($this->configFactory, $this->linkGenerator);
    $message = $help_message_helper
      ->getMessage($route_name);
    $this
      ->assertEquals('You can find more info in a_documentation_link.', $message);
  }

  /**
   * Data provider to produce route names.
   */
  public function providerRouteNames() {
    $data = [];
    $data['help page'] = [
      'help.page.acquia_lift',
    ];
    $data['admin settings form'] = [
      'acquia_lift.admin_settings_form',
    ];
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HelpMessageHelperTest::$configFactory private property
HelpMessageHelperTest::$linkGenerator private property
HelpMessageHelperTest::$settings private property
HelpMessageHelperTest::providerRouteNames public function Data provider to produce route names.
HelpMessageHelperTest::setUp public function Overrides UnitTestCase::setUp
HelpMessageHelperTest::testGetMessageAdminSettingsFormFullSettings public function Tests the getMessage() method - AdminSettingsForm, full settings.
HelpMessageHelperTest::testGetMessageAdminSettingsFormNoApiUrl public function Tests the getMessage() method - AdminSettingsForm, no API URL setting.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
SettingsDataTrait::getValidCredentialSettings private function Get a valid credential settings array.
SettingsDataTrait::getValidFieldMappingsSettings private function Get a valid field mappings settings array.
SettingsDataTrait::getValidFrontEndCredentialSettings private function Get a valid front end credential settings.
SettingsDataTrait::getValidIdentitySettings private function Get a valid identity settings array.
SettingsDataTrait::getValidThumbnailSettings private function Get a valid thumbnail settings array.
SettingsDataTrait::getValidVisibilitySettings private function Get a valid visibility settings array.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.