You are here

class LingotekSettingsTabAccountFormTest in Lingotek Translation 3.6.x

Same name in this branch
  1. 3.6.x tests/src/Functional/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Functional\Form\LingotekSettingsTabAccountFormTest
  2. 3.6.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
  2. 3.3.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
  3. 3.4.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
  4. 3.5.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
  5. 3.7.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest
  6. 3.8.x tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabAccountFormTest

@coversDefaultClass \Drupal\lingotek\Form\LingotekSettingsTabAccountForm @group lingotek @preserveGlobalState disabled

Hierarchy

Expanded class hierarchy of LingotekSettingsTabAccountFormTest

File

tests/src/Unit/Form/LingotekSettingsTabAccountFormTest.php, line 21

Namespace

Drupal\Tests\lingotek\Unit\Form
View source
class LingotekSettingsTabAccountFormTest extends UnitTestCase {

  /**
   * The Lingotek service
   *
   * @var \Drupal\lingotek\LingotekInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $lingotek;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $configFactory;

  /**
   * The Lingotek Filter manager.
   *
   * @var \Drupal\lingotek\LingotekFilterManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $lingotekFilterManager;

  /**
   * The url generator.
   *
   * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $urlGenerator;

  /**
   * The link generator.
   *
   * @var \Drupal\Core\Utility\LinkGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $linkGenerator;

  /**
   * @var \Drupal\lingotek\Form\LingotekSettingsTabAccountForm
   */
  protected $form;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->lingotek = $this
      ->createMock(LingotekInterface::class);
    $this->configFactory = $this
      ->createMock(ConfigFactoryInterface::class);
    $this->lingotekFilterManager = $this
      ->createMock(LingotekFilterManagerInterface::class);
    $this->urlGenerator = $this
      ->createMock(UrlGeneratorInterface::class);
    $this->linkGenerator = $this
      ->createMock(LinkGeneratorInterface::class);
    $messenger = $this
      ->createMock(MessengerInterface::class);
    $this->form = new LingotekSettingsTabAccountForm($this->lingotek, $this->configFactory, $this->lingotekFilterManager, $this->urlGenerator, $this->linkGenerator);
    $this->form
      ->setStringTranslation($this
      ->getStringTranslationStub());
    $this->form
      ->setMessenger($messenger);
  }

  /**
   * @covers ::getFormId
   */
  public function testGetFormId() {
    $form_id = $this->form
      ->getFormID();
    $this
      ->assertSame('lingotek.settings_tab_account_form', $form_id);
  }

  /**
   * @covers ::buildForm
   */
  public function testBuildForm() {
    $config = $this
      ->createMock(Config::class);
    $config
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnMap([
      [
        'account.login_id',
        'test@example.com',
      ],
      [
        'account.access_token',
        'ef4b4d69-5be2-4513-b4f1-7e0f6f9511a0',
      ],
    ]);
    $this->configFactory
      ->expects($this
      ->once())
      ->method('get')
      ->with('lingotek.settings')
      ->willReturn($config);
    $this->lingotekFilterManager
      ->expects($this
      ->once())
      ->method('getLocallyAvailableFilters')
      ->willReturn([
      'filter 1' => 'filter-uuid-1',
    ]);
    $build = [];
    $form_state = $this
      ->createMock(FormStateInterface::class);
    $build = $this->form
      ->buildForm($build, $form_state);
    $this
      ->assertSame('ef4b4d69-5be2-4513-b4f1-7e0f6f9511a0', $build['account']['account_table']['token_row'][1]['#markup']);
  }

  /**
   * @covers ::disconnect
   */
  public function testDisconnect() {
    $build = [];
    $form_state = $this
      ->createMock(FormStateInterface::class);
    $form_state
      ->expects($this
      ->once())
      ->method('setRedirect')
      ->with('lingotek.account_disconnect');
    $build = $this->form
      ->disconnect($build, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekSettingsTabAccountFormTest::$configFactory protected property The config factory.
LingotekSettingsTabAccountFormTest::$form protected property
LingotekSettingsTabAccountFormTest::$lingotek protected property The Lingotek service
LingotekSettingsTabAccountFormTest::$lingotekFilterManager protected property The Lingotek Filter manager.
LingotekSettingsTabAccountFormTest::$linkGenerator protected property The link generator.
LingotekSettingsTabAccountFormTest::$urlGenerator protected property The url generator.
LingotekSettingsTabAccountFormTest::setUp protected function Overrides UnitTestCase::setUp
LingotekSettingsTabAccountFormTest::testBuildForm public function @covers ::buildForm
LingotekSettingsTabAccountFormTest::testDisconnect public function @covers ::disconnect
LingotekSettingsTabAccountFormTest::testGetFormId public function @covers ::getFormId
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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::setUpBeforeClass public static function