You are here

public function LingotekDashboardControllerTest::testNodeTypesEnabledForLingotekTranslation in Lingotek Translation 8

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

Tests that when the node entity type is enabled, the response contains the stats of nodes.

@covers ::endpoint

File

tests/src/Unit/Controller/LingotekDashboardControllerTest.php, line 175

Class

LingotekDashboardControllerTest
@coversDefaultClass \Drupal\lingotek\Controller\LingotekDashboardController @group lingotek @preserveGlobalState disabled

Namespace

Drupal\Tests\lingotek\Unit\Controller

Code

public function testNodeTypesEnabledForLingotekTranslation() {
  $this
    ->setUpConfigurableLanguageMock();
  $this->request
    ->expects($this
    ->any())
    ->method('getMethod')
    ->willReturn('GET');
  $languages = [];
  foreach ([
    'en',
    'fr',
  ] as $langcode) {
    $language = new Language([
      'id' => $langcode,
    ]);
    $languages[$langcode] = $language;
  }
  $query = $this
    ->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
  $query
    ->method('condition')
    ->willReturnSelf();
  $query
    ->method('count')
    ->willReturnSelf();
  $query
    ->expects($this
    ->any())
    ->method('execute')
    ->willReturn(3);
  $this->entityQueryFactory
    ->expects($this
    ->any())
    ->method('get')
    ->willReturn($query);
  $this->languageManager
    ->expects($this
    ->any())
    ->method('getLanguages')
    ->will($this
    ->returnValue($languages));
  $this->lingotekConfiguration
    ->expects($this
    ->any())
    ->method('getEnabledEntityTypes')
    ->will($this
    ->returnValue([
    'node' => 'node',
  ]));
  $this->languageLocaleMapper
    ->expects($this
    ->any())
    ->method('getLocaleForLangcode')
    ->will($this
    ->returnValueMap([
    [
      'en',
      'en_US',
    ],
    [
      'fr',
      'fr_CA',
    ],
  ]));

  /** @var JsonResponse $value */
  $response = $this->controller
    ->endpoint($this->request);
  $content = json_decode($response
    ->getContent(), TRUE);
  $this
    ->assertEquals('GET', $content['method']);
  $this
    ->assertEquals(2, count($content['languages']));
  $this
    ->assertEquals(3, $content['languages']['en_US']['source']['types']['node']);
  $this
    ->assertEquals(1, count($content['languages']['en_US']['source']['types']));
  $this
    ->assertEquals(3, $content['languages']['en_US']['target']['types']['node']);
  $this
    ->assertEquals(1, count($content['languages']['en_US']['target']['types']));
  $this
    ->assertEquals(3, $content['languages']['fr_CA']['source']['types']['node']);
  $this
    ->assertEquals(1, count($content['languages']['fr_CA']['source']['types']));
  $this
    ->assertEquals(3, $content['languages']['fr_CA']['target']['types']['node']);
  $this
    ->assertEquals(1, count($content['languages']['fr_CA']['target']['types']));
  $this
    ->assertEquals(6, $content['source']['types']['node']);
  $this
    ->assertEquals(6, $content['target']['types']['node']);
  $this
    ->assertEquals(6, $content['source']['total']);
  $this
    ->assertEquals(6, $content['target']['total']);
}