You are here

public function LingotekUnitTest::testAddTarget in Lingotek Translation 8.2

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

@covers ::addTarget

File

tests/src/Unit/LingotekUnitTest.php, line 750

Class

LingotekUnitTest
@coversDefaultClass \Drupal\lingotek\Lingotek @group lingotek @preserveGlobalState disabled

Namespace

Drupal\Tests\lingotek\Unit

Code

public function testAddTarget() {
  $response = $this
    ->getMockBuilder(ResponseInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->expects($this
    ->any())
    ->method('getStatusCode')
    ->willReturn(Response::HTTP_CREATED);
  $language = $this
    ->createMock(ConfigurableLanguageInterface::class);
  $language
    ->expects($this
    ->any())
    ->method('getId')
    ->will($this
    ->returnValue('es'));
  $this->config
    ->expects($this
    ->any())
    ->method('get')
    ->will($this
    ->returnValueMap([
    [
      'default.workflow',
      'default_workflow',
    ],
  ]));
  $this->languageLocaleMapper
    ->expects($this
    ->any())
    ->method('getConfigurableLanguageForLocale')
    ->with('es_ES')
    ->will($this
    ->returnValue($language));

  // Workflow id has the original value.
  $this->api
    ->expects($this
    ->at(0))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', 'my_test_workflow')
    ->will($this
    ->returnValue($response));

  // Workflow id has changed.
  $this->api
    ->expects($this
    ->at(1))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', 'another_test_workflow')
    ->will($this
    ->returnValue($response));

  // If there is a profile with default workflow, it must be replaced.
  $this->api
    ->expects($this
    ->at(2))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', 'default_workflow')
    ->will($this
    ->returnValue($response));

  // If there is a profile with a language override must be used.
  $this->api
    ->expects($this
    ->at(3))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', 'overridden_workflow')
    ->will($this
    ->returnValue($response));

  // If there is a profile with a default workflow as override, it must be replaced.
  $this->api
    ->expects($this
    ->at(4))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', 'default_workflow')
    ->will($this
    ->returnValue($response));

  // If there is no profile, workflow should not be included.
  $this->api
    ->expects($this
    ->at(5))
    ->method('addTranslation')
    ->with('my_doc_id', 'es_ES', NULL)
    ->will($this
    ->returnValue($response));

  // We upload with a profile that has a workflow.
  $profile = new LingotekProfile([
    'id' => 'profile1',
    'workflow' => 'my_test_workflow',
  ], 'lingotek_profile');
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', $profile));

  // We upload with a profile that has another vault and another project.
  $profile = new LingotekProfile([
    'id' => 'profile2',
    'workflow' => 'another_test_workflow',
  ], 'lingotek_profile');
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', $profile));

  // We upload with a profile that has marked to use the default vault and project,
  // so must be replaced.
  $profile = new LingotekProfile([
    'id' => 'profile2',
    'workflow' => 'default',
  ], 'lingotek_profile');
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', $profile));

  // We upload with a profile that has marked to use the default vault and project,
  // but has an override.
  $profile = new LingotekProfile([
    'id' => 'profile2',
    'workflow' => 'default',
    'language_overrides' => [
      'es' => [
        'overrides' => 'custom',
        'custom' => [
          'workflow' => 'overridden_workflow',
        ],
      ],
    ],
  ], 'lingotek_profile');
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', $profile));

  // We upload with a profile that has another vault and another project, but
  // overridden with a default, so must be replaced.
  $profile = new LingotekProfile([
    'id' => 'profile2',
    'workflow' => 'a_different_test_workflow',
    'language_overrides' => [
      'es' => [
        'overrides' => 'custom',
        'custom' => [
          'workflow' => 'default',
        ],
      ],
    ],
  ], 'lingotek_profile');
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', $profile));

  // We upload without a profile
  $this
    ->assertTrue($this->lingotek
    ->addTarget('my_doc_id', 'es_ES', NULL));
}