You are here

class LingotekConfigSubscriberUnitTest in Lingotek Translation 8.2

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

@coversDefaultClass \Drupal\lingotek\EventSubscriber\LingotekConfigSubscriber @group lingotek @preserveGlobalState disabled

Hierarchy

Expanded class hierarchy of LingotekConfigSubscriberUnitTest

File

tests/src/Unit/EventSubscriber/LingotekConfigSubscriberUnitTest.php, line 23

Namespace

Drupal\Tests\lingotek\Unit\EventSubscriber
View source
class LingotekConfigSubscriberUnitTest extends UnitTestCase {

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

  /**
   * The mapper manager.
   *
   * @var \Drupal\config_translation\ConfigMapperManagerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $mapperManager;

  /**
   * A array of configuration mapper instances.
   *
   * @var \Drupal\config_translation\ConfigMapperInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
   */
  protected $mappers;

  /**
   * A configuration mapper instance.
   *
   * @var \Drupal\config_translation\ConfigMapperInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $mapper;

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

  /**
   * 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 config subscriber under test.
   *
   * @var \Drupal\lingotek\EventSubscriber\LingotekConfigSubscriber
   */
  protected $configSubscriber;
  protected function setUp() {
    parent::setUp();
    $this->translationService = $this
      ->createMock(LingotekConfigTranslationServiceInterface::class);
    $this->mapperManager = $this
      ->createMock(ConfigMapperManagerInterface::class);
    $this->mapper = $this
      ->createMock(ConfigNamesMapper::class);
    $this->lingotekConfiguration = $this
      ->createMock(LingotekConfigurationServiceInterface::class);
    $this->entityTypeManager = $this
      ->createMock(EntityTypeManagerInterface::class);
    $this->entityFieldManager = $this
      ->createMock(EntityFieldManagerInterface::class);
    $this->mappers = [
      $this->mapper,
    ];
    $this->mapperManager
      ->expects($this
      ->any())
      ->method('getMappers')
      ->willReturn($this->mappers);
    $this->configSubscriber = new LingotekConfigSubscriber($this->translationService, $this->mapperManager, $this->lingotekConfiguration, $this->entityTypeManager, $this->entityFieldManager);
  }

  /**
   * @covers ::onConfigSave
   */
  public function testOnConfigSaveWhenFieldDefinitionDoesntExist() {
    $id = 'node.article.myfieldname';
    $field_id = 'field.field.' . $id;
    $config = $this
      ->createMock(FieldConfig::class);
    $config
      ->expects($this
      ->at(1))
      ->method('getName')
      ->willReturn($field_id);
    $config
      ->expects($this
      ->at(2))
      ->method('get')
      ->with('id')
      ->willReturn($id);
    $config
      ->expects($this
      ->at(3))
      ->method('get')
      ->with('translatable')
      ->willReturn(FALSE);
    $event = $this
      ->createMock(ConfigCrudEvent::class);
    $event
      ->expects($this
      ->any())
      ->method('getConfig')
      ->willReturn($config);
    $event
      ->expects($this
      ->once())
      ->method('isChanged')
      ->with('translatable')
      ->willReturn(TRUE);
    $this->entityFieldManager
      ->expects($this
      ->once())
      ->method('getFieldDefinitions')
      ->with('node', 'article')
      ->willReturn([
      'myfieldname' => NULL,
    ]);
    $this->configSubscriber
      ->onConfigSave($event);
  }

  /**
   * @covers ::onConfigSave
   */
  public function testOnConfigSaveWhenProfileIsNull() {
    $id = 'my.settings';
    $this->mapper
      ->expects($this
      ->once())
      ->method('getConfigNames')
      ->willReturn([
      $id,
    ]);
    $config = $this
      ->createMock(Config::class);
    $config
      ->expects($this
      ->at(0))
      ->method('getName')
      ->willReturn($id);
    $event = $this
      ->createMock(ConfigCrudEvent::class);
    $event
      ->expects($this
      ->any())
      ->method('getConfig')
      ->willReturn($config);
    $this->mapper
      ->expects($this
      ->once())
      ->method('getPluginId')
      ->willReturn('a_config_plugin_for_config');
    $this->lingotekConfiguration
      ->expects($this
      ->once())
      ->method('getConfigProfile')
      ->with('a_config_plugin_for_config')
      ->willReturn(NULL);
    $this->configSubscriber
      ->onConfigSave($event);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekConfigSubscriberUnitTest::$configSubscriber protected property The config subscriber under test.
LingotekConfigSubscriberUnitTest::$entityFieldManager protected property The entity field manager.
LingotekConfigSubscriberUnitTest::$entityTypeBundleInfo protected property The entity type bundle info.
LingotekConfigSubscriberUnitTest::$entityTypeManager protected property Entity manager.
LingotekConfigSubscriberUnitTest::$lingotekConfiguration protected property The Lingotek configuration service.
LingotekConfigSubscriberUnitTest::$mapper protected property A configuration mapper instance.
LingotekConfigSubscriberUnitTest::$mapperManager protected property The mapper manager.
LingotekConfigSubscriberUnitTest::$mappers protected property A array of configuration mapper instances.
LingotekConfigSubscriberUnitTest::$translationService protected property The Lingotek content translation service.
LingotekConfigSubscriberUnitTest::setUp protected function Overrides UnitTestCase::setUp
LingotekConfigSubscriberUnitTest::testOnConfigSaveWhenFieldDefinitionDoesntExist public function @covers ::onConfigSave
LingotekConfigSubscriberUnitTest::testOnConfigSaveWhenProfileIsNull public function @covers ::onConfigSave
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.