You are here

class SettingsHelperTest in Acquia Lift Connector 8

SettingsHelper Test.

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

Hierarchy

Expanded class hierarchy of SettingsHelperTest

File

tests/src/Unit/Service/Helper/SettingsHelperTest.php, line 22
Contains \Drupal\Tests\acquia_lift\Service\Helper\SettingsHelperTest.

Namespace

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

  /**
   * Tests the getFrontEndCredentialSettings() method.
   *
   * @covers ::getFrontEndCredentialSettings
   *
   * @param array $full_settings
   * @param array $expected_front_end_settings
   *
   * @dataProvider providerTestGetFrontEndCredentialSettings
   */
  public function testGetFrontEndCredentialSettings($full_settings, $expected_front_end_settings) {
    $result_front_end_settings = SettingsHelper::getFrontEndCredentialSettings($full_settings);
    $this
      ->assertEquals($expected_front_end_settings, $result_front_end_settings);
  }

  /**
   * Data provider for testGetFrontEndCredentialSettings().
   */
  public function providerTestGetFrontEndCredentialSettings() {
    $data = [];
    $valid_settings = $this
      ->getValidCredentialSettings();
    $valid_front_end_settings = $this
      ->getValidFrontEndCredentialSettings();
    $data['valid data 1'] = [
      $valid_settings,
      $valid_front_end_settings,
    ];
    $data['valid data 2'] = [
      $valid_settings,
      $valid_front_end_settings,
    ];
    $data['valid data 2'][0]['account_name'] = 'account_name_2';
    $data['valid data 2'][1]['account_name'] = 'account_name_2';
    $data['valid data 2'][0]['customer_site'] = '';
    $data['valid data 2'][1]['customer_site'] = '';
    $data['valid data 2'][0]['js_path'] = 'js_path_2';
    $data['valid data 2'][1]['js_path'] = 'js_path_2';
    return $data;
  }

  /**
   * Tests the getFrontEndCredentialSettings() method's Exception.
   *
   * @covers ::getFrontEndCredentialSettings
   *
   * @param array $incomplete_settings
   *
   * @dataProvider providerTestGetFrontEndCredentialSettingsException
   * @expectedException \Drupal\acquia_lift\Exception\MissingSettingsException
   * @expectedExceptionMessage Cannot generate front-end credential settings because some settings are missing.
   */
  public function testGetFrontEndCredentialSettingsException($incomplete_settings) {
    SettingsHelper::getFrontEndCredentialSettings($incomplete_settings);
  }

  /**
   * Data provider for testGetFrontEndCredentialSettingsException().
   */
  public function providerTestGetFrontEndCredentialSettingsException() {
    $data = [];
    $valid_settings = $this
      ->getValidCredentialSettings();
    $data['missing account_name'] = [
      $valid_settings,
    ];
    $data['missing api_url'] = [
      $valid_settings,
    ];
    $data['not set customer_site'] = [
      $valid_settings,
    ];
    $data['missing account_name'][0]['account_name'] = '';
    $data['missing api_url'][0]['js_path'] = '';
    unset($data['not set customer_site'][0]['customer_site']);
    return $data;
  }

  /**
   * Tests the isInvalidCredential() method.
   *
   * @covers ::isInvalidCredential
   *
   * @param array $full_settings
   * @param boolean $expected
   *
   * @dataProvider providerTestIsInvalidCredential
   */
  public function testIsInvalidCredential($full_settings, $expected) {
    $result = SettingsHelper::isInvalidCredential($full_settings);
    $this
      ->assertEquals($expected, $result);
  }

  /**
   * Data provider for testIsInvalidCredential().
   */
  public function providerTestIsInvalidCredential() {
    $data = [];
    $valid_settings = $this
      ->getValidCredentialSettings();
    $data['valid data 1'] = [
      $valid_settings,
      FALSE,
    ];
    $data['valid data 2'] = [
      $valid_settings,
      FALSE,
    ];
    $data['missing access_key'] = [
      $valid_settings,
      TRUE,
    ];
    $data['missing account_name'] = [
      $valid_settings,
      TRUE,
    ];
    $data['invalid api_url URL'] = [
      $valid_settings,
      TRUE,
    ];
    $data['invalid js_path URL'] = [
      $valid_settings,
      TRUE,
    ];
    $data['valid data 2'][0]['account_name'] = 'account_name_2';
    $data['valid data 2'][0]['customer_site'] = '';
    $data['valid data 2'][0]['js_path'] = 'js_path_2';
    $data['missing account_name'][0]['account_name'] = '';
    $data['missing access_key'][0]['access_key'] = NULL;
    $data['invalid api_url URL'][0]['api_url'] = '\\\\////\\\\////';
    $data['invalid js_path URL'][0]['js_path'] = 'invalid js path';
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
SettingsHelperTest::providerTestGetFrontEndCredentialSettings public function Data provider for testGetFrontEndCredentialSettings().
SettingsHelperTest::providerTestGetFrontEndCredentialSettingsException public function Data provider for testGetFrontEndCredentialSettingsException().
SettingsHelperTest::providerTestIsInvalidCredential public function Data provider for testIsInvalidCredential().
SettingsHelperTest::testGetFrontEndCredentialSettings public function Tests the getFrontEndCredentialSettings() method.
SettingsHelperTest::testGetFrontEndCredentialSettingsException public function Tests the getFrontEndCredentialSettings() method's Exception.
SettingsHelperTest::testIsInvalidCredential public function Tests the isInvalidCredential() method.
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.
UnitTestCase::setUp protected function 340