View source  
  <?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class LingotekContentTypeLocaleTranslationTest extends LingotekTestBase {
  
  public static $modules = [
    'block',
    'node',
    'image',
    'comment',
  ];
  
  protected $node;
  protected function setUp() : void {
    parent::setUp();
    
    $this
      ->drupalPlaceBlock('local_tasks_block');
    $this
      ->drupalPlaceBlock('page_title_block');
    
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);
    
    ConfigurableLanguage::createFromLangcode('es')
      ->setThirdPartySetting('lingotek', 'locale', 'es_ES')
      ->save();
    ConfigurableLanguage::createFromLangcode('es-ar')
      ->setThirdPartySetting('lingotek', 'locale', 'es_AR')
      ->save();
    drupal_static_reset();
    \Drupal::entityTypeManager()
      ->clearCachedDefinitions();
    $this
      ->applyEntityUpdates();
    
    $this
      ->rebuildContainer();
  }
  
  public function testContentTypeTranslation() {
    $assert_session = $this
      ->assertSession();
    
    \Drupal::state()
      ->set('lingotek.uploaded_content_type', 'content_type');
    
    $this
      ->drupalLogin($this->rootUser);
    $this
      ->drupalGet('/admin/config/regional/config-translation');
    $this
      ->drupalGet('/admin/config/regional/config-translation/node_type');
    $this
      ->clickLink(t('Translate'));
    $this
      ->clickLink(t('Upload'));
    $this
      ->assertText(t('Article uploaded successfully'));
    
    $data = json_decode(\Drupal::state()
      ->get('lingotek.uploaded_content', '[]'), TRUE);
    $this
      ->assertEqual(3, count($data));
    $this
      ->assertTrue(array_key_exists('name', $data));
    
    $this
      ->assertTrue(array_key_exists('description', $data));
    $this
      ->assertTrue(array_key_exists('help', $data));
    
    $uploaded_url = \Drupal::state()
      ->get('lingotek.uploaded_url');
    $this
      ->assertIdentical(\Drupal::request()
      ->getUriForPath('/admin/structure/types/manage/article'), $uploaded_url, 'The article type url was used.');
    
    $used_profile = \Drupal::state()
      ->get('lingotek.used_profile');
    $this
      ->assertIdentical('automatic', $used_profile, 'The automatic profile was used.');
    $this
      ->clickLink(t('Check upload status'));
    $this
      ->assertText(t('Article status checked successfully'));
    
    $link = $this
      ->xpath('//a[normalize-space()="Request translation" and contains(@href,"es_AR")]');
    $link[0]
      ->click();
    $this
      ->assertText(t('Translation to es_AR requested successfully'));
    $this
      ->assertIdentical('es_AR', \Drupal::state()
      ->get('lingotek.added_target_locale'));
    $this
      ->clickLink(t('Check Download'));
    $this
      ->assertText(t('Translation to es_AR status checked successfully'));
    $this
      ->clickLink('Download');
    $this
      ->assertText(t('Translation to es_AR downloaded successfully'));
    
    $basepath = \Drupal::request()
      ->getBasePath();
    $assert_session
      ->linkByHrefExists($basepath . '/admin/structure/types/manage/article/translate/es-ar/edit');
  }
}