class LingotekManagementFormTest in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 4.0.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.0.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.1.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.2.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.3.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.4.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.5.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.6.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 3.7.x tests/src/Unit/Form/LingotekManagementFormTest.php \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
- 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
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\lingotek\Unit\Form\LingotekManagementFormTest
Expanded class hierarchy of LingotekManagementFormTest
File
- tests/
src/ Unit/ Form/ LingotekManagementFormTest.php, line 30
Namespace
Drupal\Tests\lingotek\Unit\FormView source
class LingotekManagementFormTest extends UnitTestCase {
/**
* @var LingotekManagementForm
*/
protected $form;
/**
* The language-locale mapper.
*
* @var \Drupal\lingotek\LanguageLocaleMapperInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $languageLocaleMapper;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $languageManager;
/**
* The entity query factory service.
*
* @var \Drupal\Core\Entity\Query\QueryFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityQuery;
/**
* 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 $translation_service|\PHPUnit_Framework_MockObject_MockObject
*/
protected $contentTranslationService;
/**
* The tempstore factory.
*
* @var \Drupal\user\PrivateTempStoreFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $tempStoreFactory;
/**
* The state key value store.
*
* @var \Drupal\Core\State\StateInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $state;
protected function setUp() {
parent::setUp();
$this->entityManager = $this
->getMock(EntityManagerInterface::class);
$this->languageManager = $this
->getMock(LanguageManagerInterface::class);
$this->entityQuery = $this
->getMockBuilder(QueryFactory::class)
->disableOriginalConstructor()
->getMock();
$this->lingotek = $this
->getMock(LingotekInterface::class);
$this->lingotekConfiguration = $this
->getMock(LingotekConfigurationServiceInterface::class);
$this->languageLocaleMapper = $this
->getMock(LanguageLocaleMapperInterface::class);
$this->contentTranslationManager = $this
->getMock(ContentTranslationManagerInterface::class);
$this->contentTranslationService = $this
->getMock(LingotekContentTranslationServiceInterface::class);
$this->tempStoreFactory = $this
->getMockBuilder(PrivateTempStoreFactory::class)
->disableOriginalConstructor()
->getMock();
$this->state = $this
->getMock(StateInterface::class);
$this->form = new LingotekManagementForm($this->entityManager, $this->languageManager, $this->entityQuery, $this->lingotek, $this->lingotekConfiguration, $this->languageLocaleMapper, $this->contentTranslationManager, $this->contentTranslationService, $this->tempStoreFactory, $this->state, 'node');
$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() {
$query = $this
->getMock(QueryInterface::class);
$this->entityQuery
->expects($this
->once())
->method('get')
->with('node')
->willReturn($query);
$query
->expects($this
->once())
->method('pager')
->with(10, NULL)
->willReturn($query);
// Assert that condition is called filtering by the undefined language.
$query
->expects($this
->once())
->method('condition')
->with('langcode', 'und', '!=', NULL)
->willReturn($query);
$tempStore = $this
->getMockBuilder(PrivateTempStore::class)
->disableOriginalConstructor()
->getMock();
$this->tempStoreFactory
->expects($this
->at(0))
->method('get')
->with('lingotek.management.items_per_page')
->willReturn($tempStore);
$this->tempStoreFactory
->expects($this
->at(1))
->method('get')
->with('lingotek.management.filter.node')
->willReturn($tempStore);
$entityType = $this
->getMock(EntityTypeInterface::class);
$this->entityManager
->expects($this
->once())
->method('getDefinition')
->with('node')
->willReturn($entityType);
$entityType
->expects($this
->any())
->method('getKey')
->will($this
->returnArgument(0));
$storage = $this
->getMock(EntityStorageInterface::class);
$this->entityManager
->expects($this
->once())
->method('getStorage')
->with('node')
->willReturn($storage);
$storage
->expects($this
->once())
->method('loadMultiple')
->willReturn([]);
$this->entityManager
->expects($this
->once())
->method('getBundleInfo')
->willReturn([]);
$language = $this
->getMock(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->form
->buildForm([], new FormState());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LingotekManagementFormTest:: |
protected | property | The content translation manager. | |
LingotekManagementFormTest:: |
protected | property | The Lingotek content translation service. | |
LingotekManagementFormTest:: |
protected | property | The entity manager. | |
LingotekManagementFormTest:: |
protected | property | The entity query factory service. | |
LingotekManagementFormTest:: |
protected | property | ||
LingotekManagementFormTest:: |
protected | property | The language-locale mapper. | |
LingotekManagementFormTest:: |
protected | property | The language manager. | |
LingotekManagementFormTest:: |
protected | property | The Lingotek service | |
LingotekManagementFormTest:: |
protected | property | The Lingotek configuration service. | |
LingotekManagementFormTest:: |
protected | property | The state key value store. | |
LingotekManagementFormTest:: |
protected | property | The tempstore factory. | |
LingotekManagementFormTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LingotekManagementFormTest:: |
public | function | @covers ::getFormId | |
LingotekManagementFormTest:: |
public | function | @covers ::buildForm | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |