LingotekSettingsTabUtilitiesFormTest.php in Lingotek Translation 8.2
File
tests/src/Unit/Form/LingotekSettingsTabUtilitiesFormTest.php
View source
<?php
namespace Drupal\Tests\lingotek\Unit\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Routing\RouteBuilderInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Drupal\lingotek\Form\LingotekSettingsTabUtilitiesForm;
use Drupal\lingotek\LingotekInterface;
use Drupal\Tests\UnitTestCase;
class LingotekSettingsTabUtilitiesFormTest extends UnitTestCase {
protected $lingotek;
protected $configFactory;
protected $state;
protected $routeBuilder;
protected $form;
protected $urlGenerator;
protected $linkGenerator;
protected function setUp() {
parent::setUp();
$this->lingotek = $this
->createMock(LingotekInterface::class);
$this->configFactory = $this
->createMock(ConfigFactoryInterface::class);
$this->state = $this
->createMock(StateInterface::class);
$this->routeBuilder = $this
->createMock(RouteBuilderInterface::class);
$this->urlGenerator = $this
->createMock(UrlGeneratorInterface::class);
$this->linkGenerator = $this
->createMock(LinkGeneratorInterface::class);
$messenger = $this
->createMock(MessengerInterface::class);
$this->form = new LingotekSettingsTabUtilitiesForm($this->lingotek, $this->configFactory, $this->state, $this->routeBuilder, $this->urlGenerator, $this->linkGenerator);
$this->form
->setStringTranslation($this
->getStringTranslationStub());
$this->form
->setMessenger($messenger);
}
public function testGetFormId() {
$form_id = $this->form
->getFormID();
$this
->assertSame('lingotek.settings_tab_utilities_form', $form_id);
}
public function testFormDebugUtilityWithDebugDisabled() {
$this->state
->expects($this
->any())
->method('get')
->with('lingotek.enable_debug_utilities')
->will($this
->returnValue(FALSE));
$build = [];
$form_state = $this
->createMock(FormStateInterface::class);
$build = $this->form
->buildForm($build, $form_state);
$this
->assertSame($build['utilities']['lingotek_table']['enable_debug_utilities']['actions']['submit']['#value']
->getUntranslatedString(), 'Enable debug operations');
}
public function testFormDebugUtilityWithDebugEnabled() {
$this->state
->expects($this
->any())
->method('get')
->with('lingotek.enable_debug_utilities')
->will($this
->returnValue(TRUE));
$build = [];
$form_state = $this
->createMock(FormStateInterface::class);
$build = $this->form
->buildForm($build, $form_state);
$this
->assertSame($build['utilities']['lingotek_table']['enable_debug_utilities']['actions']['submit']['#value']
->getUntranslatedString(), 'Disable debug operations');
}
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();
}
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();
}
}