You are here

class LingotekManagementFormTest in Lingotek Translation 8.2

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

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

Hierarchy

Expanded class hierarchy of LingotekManagementFormTest

File

tests/src/Unit/Form/LingotekManagementFormTest.php, line 33

Namespace

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

  /**
   * @var LingotekManagementForm
   */
  protected $form;

  /**
   * The connection object on which to run queries.
   *
   * @var \Drupal\Core\Database\Connection|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $connection;

  /**
   * The language-locale mapper.
   *
   * @var \Drupal\lingotek\LanguageLocaleMapperInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $languageLocaleMapper;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityTypeManager;

  /**
   * The entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityFieldManager;

  /**
   * The entity type bundle info.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $entityTypeBundleInfo;

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $languageManager;

  /**
   * The Lingotek configuration service.
   *
   * @var \Drupal\lingotek\LingotekConfigurationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $lingotekConfiguration;

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

  /**
   * The content translation manager.
   *
   * @var \Drupal\content_translation\ContentTranslationManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $contentTranslationManager;

  /**
   * The Lingotek content translation service.
   *
   * @var \Drupal\lingotek\LingotekContentTranslationServiceInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $contentTranslationService;

  /**
   * The tempstore factory.
   *
   * @var \Drupal\Core\TempStore\PrivateTempStoreFactory|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $tempStoreFactory;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $moduleHandler;

  /**
   * The state key value store.
   *
   * @var \Drupal\Core\State\StateInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $state;

  /**
   * The link generator.
   *
   * @var \Drupal\Core\Utility\LinkGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $linkGenerator;
  protected function setUp() {
    parent::setUp();
    $this->connection = $this
      ->getMockBuilder(Connection::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->entityTypeManager = $this
      ->createMock(EntityTypeManagerInterface::class);
    $this->entityFieldManager = $this
      ->createMock(EntityFieldManagerInterface::class);
    $this->entityTypeBundleInfo = $this
      ->createMock(EntityTypeBundleInfoInterface::class);
    $this->languageManager = $this
      ->createMock(LanguageManagerInterface::class);
    $this->lingotek = $this
      ->createMock(LingotekInterface::class);
    $this->lingotekConfiguration = $this
      ->createMock(LingotekConfigurationServiceInterface::class);
    $this->languageLocaleMapper = $this
      ->createMock(LanguageLocaleMapperInterface::class);
    $this->contentTranslationManager = $this
      ->createMock(ContentTranslationManagerInterface::class);
    $this->contentTranslationService = $this
      ->createMock(LingotekContentTranslationServiceInterface::class);
    $this->tempStoreFactory = $this
      ->getMockBuilder(PrivateTempStoreFactory::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->state = $this
      ->createMock(StateInterface::class);
    $this->moduleHandler = $this
      ->createMock(ModuleHandlerInterface::class);
    $this->linkGenerator = $this
      ->createMock(LinkGeneratorInterface::class);
    $this->form = new LingotekManagementForm($this->connection, $this->entityTypeManager, $this->languageManager, $this->lingotek, $this->lingotekConfiguration, $this->languageLocaleMapper, $this->contentTranslationManager, $this->contentTranslationService, $this->tempStoreFactory, $this->state, $this->moduleHandler, 'node', $this->entityFieldManager, $this->entityTypeBundleInfo, $this->linkGenerator);
    $this->form
      ->setConfigFactory($this
      ->getConfigFactoryStub([
      'lingotek.settings' => [
        'account' => [
          'access_token' => 'token',
          'login_id' => 'test@example.com',
        ],
      ],
    ]));
    $this->form
      ->setStringTranslation($this
      ->getStringTranslationStub());
  }

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

  /**
   * @covers ::buildForm
   */
  public function testQueryExcludesUndefinedLanguageContent() {
    $select = $this
      ->getMockBuilder(PagerSelectExtender::class)
      ->disableOriginalConstructor()
      ->getMock();
    $select
      ->expects($this
      ->any())
      ->method('extend')
      ->with('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
      ->willReturnSelf();
    $select
      ->expects($this
      ->any())
      ->method('fields')
      ->with('entity_table', [
      'id',
    ])
      ->willReturnSelf();
    $statement = $this
      ->createMock(StatementInterface::class);

    // Assert that condition is called filtering by the undefined language.
    $select
      ->expects($this
      ->any())
      ->method('condition')
      ->with('entity_table.langcode', 'und', '!=')
      ->willReturnSelf();
    $select
      ->expects($this
      ->once())
      ->method('limit')
      ->with(10)
      ->willReturnSelf();
    $select
      ->expects($this
      ->once())
      ->method('execute')
      ->willReturn($statement);
    $statement
      ->expects($this
      ->once())
      ->method('fetchCol')
      ->with(0)
      ->willReturn([]);
    $this->connection
      ->expects($this
      ->once())
      ->method('select')
      ->willReturn($select);
    $tempStore = $this
      ->getMockBuilder(PrivateTempStoreFactory::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->tempStoreFactory
      ->expects($this
      ->at(0))
      ->method('get')
      ->with('lingotek.management.filter.node')
      ->willReturn($tempStore);
    $this->tempStoreFactory
      ->expects($this
      ->at(1))
      ->method('get')
      ->with('lingotek.management.filter.node')
      ->willReturn($tempStore);
    $this->tempStoreFactory
      ->expects($this
      ->at(2))
      ->method('get')
      ->with('lingotek.management.items_per_page')
      ->willReturn($tempStore);
    $this->tempStoreFactory
      ->expects($this
      ->at(3))
      ->method('get')
      ->with('lingotek.management.filter.node')
      ->willReturn($tempStore);
    $this->tempStoreFactory
      ->expects($this
      ->at(4))
      ->method('get')
      ->with('lingotek.management.items_per_page')
      ->willReturn($tempStore);
    $tempStore
      ->expects($this
      ->at(0))
      ->method('get')
      ->with('label')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(1))
      ->method('get')
      ->with('bundle')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(2))
      ->method('get')
      ->with('job')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(3))
      ->method('get')
      ->with('document_id')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(4))
      ->method('get')
      ->with('entity_id')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(5))
      ->method('get')
      ->with('source_language')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(6))
      ->method('get')
      ->with('source_status')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(7))
      ->method('get')
      ->with('target_status')
      ->willReturn(NULL);
    $tempStore
      ->expects($this
      ->at(8))
      ->method('get')
      ->with('profile')
      ->willReturn(NULL);
    $entityType = $this
      ->createMock(EntityTypeInterface::class);
    $entityType
      ->expects($this
      ->any())
      ->method('get')
      ->with('bundle_entity_type')
      ->willReturn('node');
    $this->entityTypeManager
      ->expects($this
      ->any())
      ->method('getDefinition')
      ->with('node')
      ->willReturn($entityType);
    $entityType
      ->expects($this
      ->any())
      ->method('getKey')
      ->will($this
      ->returnArgument(0));
    $storage = $this
      ->createMock(EntityStorageInterface::class);
    $this->entityTypeManager
      ->expects($this
      ->once())
      ->method('getStorage')
      ->with('node')
      ->willReturn($storage);
    $storage
      ->expects($this
      ->once())
      ->method('loadMultiple')
      ->willReturn([]);
    $this->entityTypeBundleInfo
      ->expects($this
      ->once())
      ->method('getBundleInfo')
      ->willReturn([]);
    $language = $this
      ->createMock(ConfigurableLanguageInterface::class);
    $this->languageManager
      ->expects($this
      ->any())
      ->method('getLanguages')
      ->willReturn([
      'en' => $language,
    ]);
    $this->lingotekConfiguration
      ->expects($this
      ->any())
      ->method('getProfileOptions')
      ->willReturn([
      'manual',
    ]);
    $this->state
      ->expects($this
      ->once())
      ->method('get')
      ->with('lingotek.enable_debug_utilities')
      ->willReturn(FALSE);
    $this->moduleHandler
      ->expects($this
      ->at(0))
      ->method('moduleExists')
      ->with('group')
      ->willReturn(FALSE);
    $this->form
      ->buildForm([], new FormState());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekManagementFormTest::$connection protected property The connection object on which to run queries.
LingotekManagementFormTest::$contentTranslationManager protected property The content translation manager.
LingotekManagementFormTest::$contentTranslationService protected property The Lingotek content translation service.
LingotekManagementFormTest::$entityFieldManager protected property The entity field manager.
LingotekManagementFormTest::$entityTypeBundleInfo protected property The entity type bundle info.
LingotekManagementFormTest::$entityTypeManager protected property The entity manager.
LingotekManagementFormTest::$form protected property
LingotekManagementFormTest::$languageLocaleMapper protected property The language-locale mapper.
LingotekManagementFormTest::$languageManager protected property The language manager.
LingotekManagementFormTest::$lingotek protected property The Lingotek service
LingotekManagementFormTest::$lingotekConfiguration protected property The Lingotek configuration service.
LingotekManagementFormTest::$linkGenerator protected property The link generator.
LingotekManagementFormTest::$moduleHandler protected property The module handler.
LingotekManagementFormTest::$state protected property The state key value store.
LingotekManagementFormTest::$tempStoreFactory protected property The tempstore factory.
LingotekManagementFormTest::setUp protected function Overrides UnitTestCase::setUp
LingotekManagementFormTest::testGetFormId public function @covers ::getFormId
LingotekManagementFormTest::testQueryExcludesUndefinedLanguageContent public function @covers ::buildForm
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.