View source  
  <?php
namespace Drupal\lingotek\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\lingotek\Lingotek;
use Drupal\lingotek\LingotekConfigTranslationServiceInterface;
class LingotekConfigDependenciesTest extends LingotekTestBase {
  
  public static $modules = [
    'lingotek',
    'block',
    'node',
    'field_ui',
  ];
  public function testExportingConfigDependencies() {
    
    $config_translation_service = \Drupal::service('lingotek.config_translation');
    
    $this
      ->drupalPlaceBlock('local_tasks_block', [
      'region' => 'highlighted',
    ]);
    $this
      ->drupalPlaceBlock('page_title_block', [
      'region' => 'highlighted',
    ]);
    
    $content_type = $this
      ->drupalCreateContentType([
      'type' => 'article',
      'label' => 'Article',
    ]);
    
    ConfigurableLanguage::createFromLangcode('es')
      ->save();
    
    $this
      ->drupalLogin($this->rootUser);
    
    ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
      ->setLanguageAlterable(TRUE)
      ->save();
    \Drupal::service('content_translation.manager')
      ->setEnabled('node', 'article', TRUE);
    
    $this
      ->drupalGet('admin/lingotek/settings');
    $this
      ->assertResponse(200);
    
    $edit = [
      'node[article][enabled]' => 1,
      'node[article][profiles]' => 'manual',
      'node[article][fields][title]' => 1,
      'node[article][fields][body]' => 1,
    ];
    $this
      ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-content-form');
    
    $edit = [
      'table[node_type][enabled]' => 1,
      'table[node_type][profile]' => 'manual',
      'table[node_fields][enabled]' => 1,
      'table[node_fields][profile]' => 'automatic',
    ];
    $this
      ->drupalPostForm('admin/lingotek/settings', $edit, 'Save', [], [], 'lingoteksettings-tab-configuration-form');
    
    $this
      ->goToConfigBulkManagementForm('node_type');
    
    $this
      ->clickLink('EN');
    $this
      ->assertText('article uploaded successfully');
    $this
      ->assertEqual(Lingotek::STATUS_IMPORTING, $config_translation_service
      ->getSourceStatus($content_type));
    $field = \Drupal::entityManager()
      ->getStorage('field_config')
      ->load('node.article.body');
    
    $this
      ->goToConfigBulkManagementForm('node_fields');
    
    $this
      ->clickLink('EN');
    $this
      ->assertText('Body uploaded successfully');
    $this
      ->assertEqual(Lingotek::STATUS_IMPORTING, $config_translation_service
      ->getSourceStatus($field));
    
    $this
      ->copyConfig($this->container
      ->get('config.storage'), $this->container
      ->get('config.storage.sync'));
    
    $content_type
      ->delete();
    
    $type = \Drupal::entityManager()
      ->getStorage('node_type')
      ->load('article');
    $this
      ->assertNull($type, 'Article doesn\'t exist anymore');
    $field = \Drupal::entityManager()
      ->getStorage('field_config')
      ->load('node.article.body');
    $this
      ->assertNull($field, 'Article Body doesn\'t exist anymore');
    
    $this
      ->configImporter()
      ->import();
    
    $type = \Drupal::entityManager()
      ->getStorage('node_type')
      ->load('article');
    $this
      ->assertNotNull($type, 'Article is back');
    $this
      ->assertEqual(Lingotek::STATUS_IMPORTING, $config_translation_service
      ->getSourceStatus($type));
    
    $field = \Drupal::entityManager()
      ->getStorage('field_config')
      ->load('node.article.body');
    $this
      ->assertNotNull($field, 'Article Body is back');
    $this
      ->assertEqual(Lingotek::STATUS_IMPORTING, $config_translation_service
      ->getSourceStatus($field));
  }
}