You are here

class LingotekSettingsTabUtilitiesFormTest in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  2. 4.0.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  3. 3.0.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  4. 3.1.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  5. 3.2.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  6. 3.3.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  7. 3.4.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  8. 3.5.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  9. 3.6.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  10. 3.7.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest
  11. 3.8.x tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekSettingsTabUtilitiesFormTest

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

Hierarchy

Expanded class hierarchy of LingotekSettingsTabUtilitiesFormTest

File

tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php, line 14

Namespace

Drupal\Tests\lingotek\Unit\Form
View source
class LingotekSettingsTabUtilitiesFormTest 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;

  /**
   * @var \Drupal\Core\State\StateInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $state;

  /**
   * @var \Drupal\Core\Routing\RouteBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $routeBuilder;

  /**
   * @var LingotekSettingsTabUtilitiesForm
   */
  protected $form;
  protected function setUp() {
    parent::setUp();
    $this->lingotek = $this
      ->getMock('Drupal\\lingotek\\LingotekInterface');
    $this->configFactory = $this
      ->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $this->state = $this
      ->getMock('Drupal\\Core\\State\\StateInterface');
    $this->routeBuilder = $this
      ->getMock('Drupal\\Core\\Routing\\RouteBuilderInterface');
    $this->form = new LingotekSettingsTabUtilitiesForm($this->lingotek, $this->configFactory, $this->state, $this->routeBuilder);
    $this->form
      ->setStringTranslation($this
      ->getStringTranslationStub());
  }

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

  /**
   * @covers ::buildForm
   */
  public function testFormDebugUtilityWithDebugDisabled() {
    $this->state
      ->expects($this
      ->any())
      ->method('get')
      ->with('lingotek.enable_debug_utilities')
      ->will($this
      ->returnValue(FALSE));
    $build = [];
    $form_state = $this
      ->getMock('Drupal\\Core\\Form\\FormStateInterface');
    $build = $this->form
      ->buildForm($build, $form_state);
    $this
      ->assertSame($build['utilities']['lingotek_table']['enable_debug_utilities']['actions']['submit']['#value']
      ->getUntranslatedString(), 'Enable debug operations');
  }

  /**
   * @covers ::buildForm
   */
  public function testFormDebugUtilityWithDebugEnabled() {
    $this->state
      ->expects($this
      ->any())
      ->method('get')
      ->with('lingotek.enable_debug_utilities')
      ->will($this
      ->returnValue(TRUE));
    $build = [];
    $form_state = $this
      ->getMock('Drupal\\Core\\Form\\FormStateInterface');
    $build = $this->form
      ->buildForm($build, $form_state);
    $this
      ->assertSame($build['utilities']['lingotek_table']['enable_debug_utilities']['actions']['submit']['#value']
      ->getUntranslatedString(), 'Disable debug operations');
  }

  /**
   * @covers ::switchDebugUtilities
   */
  public function testSwitchDebugWithDebugEnabled() {
    $this->state
      ->expects($this
      ->any())
      ->method('get')
      ->with('lingotek.enable_debug_utilities')
      ->will($this
      ->returnValue(TRUE));
    $this->state
      ->expects($this
      ->once())
      ->method('set')
      ->with('lingotek.enable_debug_utilities', FALSE);
    $this->routeBuilder
      ->expects($this
      ->once())
      ->method('rebuild');
    $this->form
      ->switchDebugUtilities();
  }

  /**
   * @covers ::switchDebugUtilities
   */
  public function testSwitchDebugWithDebugDisabled() {
    $this->state
      ->expects($this
      ->any())
      ->method('get')
      ->with('lingotek.enable_debug_utilities')
      ->will($this
      ->returnValue(FALSE));
    $this->state
      ->expects($this
      ->once())
      ->method('set')
      ->with('lingotek.enable_debug_utilities', TRUE);
    $this->routeBuilder
      ->expects($this
      ->once())
      ->method('rebuild');
    $this->form
      ->switchDebugUtilities();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekSettingsTabUtilitiesFormTest::$configFactory protected property The config factory.
LingotekSettingsTabUtilitiesFormTest::$form protected property
LingotekSettingsTabUtilitiesFormTest::$lingotek protected property The Lingotek service
LingotekSettingsTabUtilitiesFormTest::$routeBuilder protected property
LingotekSettingsTabUtilitiesFormTest::$state protected property
LingotekSettingsTabUtilitiesFormTest::setUp protected function Overrides UnitTestCase::setUp
LingotekSettingsTabUtilitiesFormTest::testFormDebugUtilityWithDebugDisabled public function @covers ::buildForm
LingotekSettingsTabUtilitiesFormTest::testFormDebugUtilityWithDebugEnabled public function @covers ::buildForm
LingotekSettingsTabUtilitiesFormTest::testGetFormId public function @covers ::getFormId
LingotekSettingsTabUtilitiesFormTest::testSwitchDebugWithDebugDisabled public function @covers ::switchDebugUtilities
LingotekSettingsTabUtilitiesFormTest::testSwitchDebugWithDebugEnabled public function @covers ::switchDebugUtilities
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.
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.