ConfigDevelSubscriberTestBase.php in Configuration development 8        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Kernel/ConfigDevelSubscriberTestBase.php
  
    View source  
  <?php
namespace Drupal\Tests\config_devel\Kernel;
use Drupal\Component\Serialization\Yaml;
use Drupal\KernelTests\KernelTestBase;
abstract class ConfigDevelSubscriberTestBase extends KernelTestBase {
  
  public static $modules = array(
    'config_devel',
  );
  
  const CONFIGNAME = '';
  
  protected $storage;
  
  public function testSubscribers() {
    
    $this->container
      ->get('config.installer')
      ->installDefaultConfig('module', 'config_devel');
    $filename = 'public://' . static::CONFIGNAME . '.yml';
    $this->container
      ->get('file_system')
      ->mkdir('public://exported');
    $exported_filename = 'public://exported/' . static::CONFIGNAME . '.yml';
    $this->container
      ->get('config.factory')
      ->getEditable('config_devel.settings')
      ->set('auto_import', array(
      array(
        'filename' => $filename,
        'hash' => '',
      ),
    ))
      ->set('auto_export', array(
      $exported_filename,
    ))
      ->save();
    $this->storage = \Drupal::service('config.storage');
    $this
      ->assertFalse($this->storage
      ->exists(static::CONFIGNAME));
    $subscriber = $this->container
      ->get('config_devel.auto_import_subscriber');
    for ($i = 2; $i; $i--) {
      $data['label'] = $this
        ->randomString();
      file_put_contents($filename, Yaml::encode($data));
      
      $subscriber
        ->autoImportConfig();
      $this
        ->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
    }
  }
  
  protected abstract function doAssert(array $data, array $exported_data);
}