ConfigInstallProfileUnmetDependenciesTest.php in Drupal 8        
                          
                  
                        
  
  
  
  
File
  core/modules/config/tests/src/Functional/ConfigInstallProfileUnmetDependenciesTest.php
  
    View source  
  <?php
namespace Drupal\Tests\config\Functional;
use Drupal\FunctionalTests\Installer\InstallerTestBase;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Serialization\Yaml;
class ConfigInstallProfileUnmetDependenciesTest extends InstallerTestBase {
  
  protected $profile = 'testing_config_overrides';
  
  protected $expectedException = FALSE;
  
  protected $defaultTheme = 'stark';
  
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $this
      ->copyTestingOverrides();
  }
  
  protected function setUp() {
    
    try {
      parent::setUp();
    } catch (\Exception $exception) {
      $this->expectedException = $exception;
    }
  }
  
  protected function copyTestingOverrides() {
    $dest = $this->siteDirectory . '/profiles/testing_config_overrides';
    mkdir($dest, 0777, TRUE);
    $source = DRUPAL_ROOT . '/core/profiles/testing_config_overrides';
    $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
    foreach ($iterator as $item) {
      if ($item
        ->isDir()) {
        mkdir($dest . DIRECTORY_SEPARATOR . $iterator
          ->getSubPathName());
      }
      else {
        copy($item, $dest . DIRECTORY_SEPARATOR . $iterator
          ->getSubPathName());
      }
    }
    
    $config_file = $dest . DIRECTORY_SEPARATOR . InstallStorage::CONFIG_INSTALL_DIRECTORY . DIRECTORY_SEPARATOR . 'system.action.user_block_user_action.yml';
    $action = Yaml::decode(file_get_contents($config_file));
    $action['dependencies']['module'][] = 'does_not_exist';
    file_put_contents($config_file, Yaml::encode($action));
  }
  
  public function testInstalled() {
    if ($this->expectedException) {
      $this
        ->assertStringContainsString('Configuration objects provided by <em class="placeholder">testing_config_overrides</em> have unmet dependencies: <em class="placeholder">system.action.user_block_user_action (does_not_exist)</em>', $this->expectedException
        ->getMessage());
      $this
        ->assertStringContainsString('Drupal\\Core\\Config\\UnmetDependenciesException', $this->expectedException
        ->getMessage());
    }
    else {
      $this
        ->fail('Expected Drupal\\Core\\Config\\UnmetDependenciesException exception not thrown');
    }
  }
}