You are here

class LingotekModerationFactoryTest in Lingotek Translation 3.1.x

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

Unit test for the moderation factory.

@coversDefaultClass \Drupal\lingotek\Moderation\LingotekModerationFactory @group lingotek @preserveGlobalState disabled

Hierarchy

Expanded class hierarchy of LingotekModerationFactoryTest

File

tests/src/Unit/Moderation/LingotekModerationFactoryTest.php, line 18

Namespace

Drupal\Tests\lingotek\Unit\Moderation
View source
class LingotekModerationFactoryTest extends UnitTestCase {

  /**
   * @var \Drupal\lingotek\Moderation\LingotekModerationFactoryInterface
   */
  protected $factory;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->factory = new LingotekModerationFactory();
  }

  /**
   * @covers ::addModerationConfiguration
   * @covers ::getModerationConfigurationService
   */
  public function testAddModerationConfiguration() {
    $configServiceLast = $this
      ->createMock(LingotekModerationConfigurationServiceInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationConfigurationServiceInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $this->factory
      ->addModerationConfiguration($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationConfiguration($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationConfigurationService();
    $this
      ->assertEquals($configService, $configServiceFirst, 'Priority is respected if all services apply.');
  }

  /**
   * @covers ::addModerationConfiguration
   * @covers ::getModerationConfigurationService
   */
  public function testAddModerationConfigurationWithANonApplyingService() {
    $configServiceLast = $this
      ->createMock(LingotekModerationConfigurationServiceInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationConfigurationServiceInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(FALSE);
    $this->factory
      ->addModerationConfiguration($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationConfiguration($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationConfigurationService();
    $this
      ->assertEquals($configService, $configServiceLast, 'Priority is respected, but we return a services that applies.');
  }

  /**
   * @covers ::addModerationForm
   * @covers ::getModerationSettingsForm
   */
  public function testAddModerationSettingsForm() {
    $configServiceLast = $this
      ->createMock(LingotekModerationSettingsFormInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationSettingsFormInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $this->factory
      ->addModerationForm($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationForm($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationSettingsForm();
    $this
      ->assertEquals($configService, $configServiceFirst, 'Priority is respected if all services apply.');
  }

  /**
   * @covers ::addModerationForm
   * @covers ::getModerationSettingsForm
   */
  public function testAddModerationSettingsFormWithANonApplyingService() {
    $configServiceLast = $this
      ->createMock(LingotekModerationSettingsFormInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationSettingsFormInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(FALSE);
    $this->factory
      ->addModerationForm($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationForm($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationSettingsForm();
    $this
      ->assertEquals($configService, $configServiceLast, 'Priority is respected, but we return a services that applies.');
  }

  /**
   * @covers ::addModerationHandler
   * @covers ::getModerationHandler
   */
  public function testAddModerationHandler() {
    $configServiceLast = $this
      ->createMock(LingotekModerationHandlerInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationHandlerInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $this->factory
      ->addModerationHandler($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationHandler($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationHandler();
    $this
      ->assertEquals($configService, $configServiceFirst, 'Priority is respected if all services apply.');
  }

  /**
   * @covers ::addModerationHandler
   * @covers ::getModerationHandler
   */
  public function testAddModerationHandlerWithANonApplyingService() {
    $configServiceLast = $this
      ->createMock(LingotekModerationHandlerInterface::class);
    $configServiceLast
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(TRUE);
    $configServiceFirst = $this
      ->createMock(LingotekModerationHandlerInterface::class);
    $configServiceFirst
      ->expects($this
      ->any())
      ->method('applies')
      ->willReturn(FALSE);
    $this->factory
      ->addModerationHandler($configServiceLast, 'last', 10);
    $this->factory
      ->addModerationHandler($configServiceFirst, 'first', 100);
    $configService = $this->factory
      ->getModerationHandler();
    $this
      ->assertEquals($configService, $configServiceLast, 'Priority is respected, but we return a services that applies.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekModerationFactoryTest::$factory protected property
LingotekModerationFactoryTest::setUp protected function Overrides UnitTestCase::setUp
LingotekModerationFactoryTest::testAddModerationConfiguration public function @covers ::addModerationConfiguration @covers ::getModerationConfigurationService
LingotekModerationFactoryTest::testAddModerationConfigurationWithANonApplyingService public function @covers ::addModerationConfiguration @covers ::getModerationConfigurationService
LingotekModerationFactoryTest::testAddModerationHandler public function @covers ::addModerationHandler @covers ::getModerationHandler
LingotekModerationFactoryTest::testAddModerationHandlerWithANonApplyingService public function @covers ::addModerationHandler @covers ::getModerationHandler
LingotekModerationFactoryTest::testAddModerationSettingsForm public function @covers ::addModerationForm @covers ::getModerationSettingsForm
LingotekModerationFactoryTest::testAddModerationSettingsFormWithANonApplyingService public function @covers ::addModerationForm @covers ::getModerationSettingsForm
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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.
UnitTestCase::setUpBeforeClass public static function