/** * Process a structured array of info files lines to a flat array for merging. * * @param $lines * An array of lines keyed by label. * Place grouped labels (eg, dependencies) into an array of * their own, keyed numerically. * Eg: * name => module name * dependencies => array(foo, bar) * * @return * An array of lines for the .info file. */ function process_info_lines($lines) { $yaml_parser = new \Symfony\Component\Yaml\Yaml(); $yaml = $yaml_parser->dump($lines, 2, 2); //drush_print_r($yaml); // Because the yaml is all built for us, this is just a singleton array. return array($yaml); }
/** * Get the YAML body for the file. * * @param $yaml_data_array * An array of data to convert to YAML. * * @return * An array containing the YAML string. */ protected function getYamlBody($yaml_data_array) { $yaml_parser = new \Symfony\Component\Yaml\Yaml(); $yaml = $yaml_parser->dump($yaml_data_array, 6, 2); //drush_print_r($yaml); // Replace variables $variables = $this->getReplacements(); $yaml = strtr($yaml, $variables); // Because the yaml is all built for us, this is just a singleton array. $body = array($yaml); return $body; }
protected function exportModuleDependencies($io, $module, $dependencies) { $yaml = new \Symfony\Component\Yaml\Yaml(); $info_file = file_get_contents($this->getSite()->getModuleInfoFile($module)); $info_yaml = $yaml->parse($info_file); if (empty($info_yaml['dependencies'])) { $info_yaml['dependencies'] = $dependencies; } else { $info_yaml['dependencies'] = array_unique(array_merge($info_yaml['dependencies'], $dependencies)); } if (file_put_contents($this->getSite()->getModuleInfoFile($module), $yaml->dump($info_yaml))) { $io->info('[+] ' . sprintf($this->trans('commands.config.export.view.messages.depencies-included'), $this->getSite()->getModuleInfoFile($module))); foreach ($dependencies as $dependency) { $io->info(' [-] ' . $dependency); } } else { $io->error($this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $this->getSite()->getModuleInfoFile($module)); return []; } }
/** * Writes the dataset to a yaml file * * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataset */ public function write(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset) { $phpArr = []; $emptyTables = []; foreach ($dataset as $table) { $tableName = $table->getTableMetaData()->getTableName(); $rowCount = $table->getRowCount(); if (!$rowCount) { $emptyTables[] = $tableName; continue; } $phpArr[$tableName] = []; for ($i = 0; $i < $rowCount; $i++) { $phpArr[$tableName][] = $table->getRow($i); } } $emptyTablesAsString = ''; if (count($emptyTables)) { $emptyTablesAsString = implode(":\n", $emptyTables) . ":\n\n"; } file_put_contents($this->filename, Symfony\Component\Yaml\Yaml::dump($phpArr, 3) . $emptyTablesAsString); }
public static function dump($array, $inline = 2, $indent = 2) { $yaml = new \Symfony\Component\Yaml\Yaml(); return $yaml->dump($array, $inline, $indent); }
* bootstrap.yml creation * -> debug true|false * -> container cache directory /path/to/container/cache * -> container auto-generate true|false */ if (!isset($_POST['debug']) && !isset($_POST['container_dump_directory'])) { $bootstrap_requirements = new BootstrapRequirements(); $requirements = $bootstrap_requirements->getRequirements(); break; } else { $containerDirectory = realpath(__DIR__ . '/..') . '/cache/container'; if (!is_dir($containerDirectory)) { mkdir($containerDirectory, 755); } $bootstrap = ['debug' => (bool) intval($_POST['debug']), 'container' => ['dump_directory' => $containerDirectory, 'autogenerate' => true]]; file_put_contents(dirname(__DIR__) . '/repository/Config/bootstrap.yml', $yaml->dump($bootstrap)); $step = 3; } case 3: /** * doctrine.yml creation * dbal: * driver: pdo_mysql|pdo_pgsl|... See (http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html#driver) * host: localhost|mysql.domain.com * port: 3306 * dbname: myWonderfullWebsite * user: databaseUser * password: databasePassword * charset: utf8 the charset used to connect to the database * collation: utf8_general_ci * defaultTableOptions: { collate: utf8_general_ci, engine: InnoDB, charset: utf8 }
public static function convert($xml) { $xml = simplexml_load_string($xml); $map = ['bundles' => []]; foreach ($xml->xpath('module') as $_bundle) { $bundle = []; $bundle['name'] = (string) $_bundle['name']; $bundle['models'] = []; $bundle['associations'] = []; $bundle['manyToManys'] = []; foreach ($xml->xpath('module/entity') as $_model) { $model = []; $model['name'] = (string) $_model['name']; $model['description'] = (string) $_model['description']; if (!empty($_model->{'orm-attributes'})) { foreach ($_model->{'orm-attributes'}->attribute as $n => $orm_attribute) { $model['ormAttributes'][(string) $orm_attribute['name']] = (string) $orm_attribute; } } $model['fields'] = []; foreach ($_model->xpath('field') as $_field) { $field = []; $field['name'] = (string) $_field['name']; $field['type'] = (string) $_field['type']; $field['size'] = (string) $_field['size']; $field['default'] = (string) $_field['default']; $field['required'] = (string) $_field['required']; $field['unique'] = (string) $_field['unique']; $field['primary'] = (string) $_field['primary']; $field['autoIncrement'] = (string) $_field['auto-increment']; $model['fields'][] = $field; } $bundle['models'][] = $model; } foreach ($xml->xpath('module/association') as $_association) { $association = []; $association['caption'] = (string) $_association['caption']; $association['from'] = (string) $_association['from']; $association['to'] = (string) $_association['to']; $association['ownerAlias'] = (string) $_association['owner-alias']; $association['inverseAlias'] = (string) $_association['inverse-alias']; $association['field']['from'] = (string) $_association->xpath('association-field')[0]['from']; $association['field']['to'] = (string) $_association->xpath('association-field')[0]['to']; $bundle['associations'][] = $association; } foreach ($xml->xpath('module/many-to-many') as $_manyToMany) { $manyToMany = []; $_manyToManyModels = $_manyToMany->xpath('many-to-many-entity'); $manyToMany['name'] = (string) $_manyToMany['mn-entity']; $manyToMany['caption'] = (string) $_manyToMany['caption']; $manyToMany['owner'] = ['name' => (string) $_manyToManyModels[0]['name'], 'alias' => (string) $_manyToManyModels[0]['alias'], 'field' => ['from' => (string) $_manyToManyModels[0]->xpath('many-to-many-field')[0]['from'], 'to' => (string) $_manyToManyModels[0]->xpath('many-to-many-field')[0]['to']]]; $manyToMany['inverse'] = ['name' => (string) $_manyToManyModels[1]['name'], 'alias' => (string) $_manyToManyModels[1]['alias'], 'field' => ['from' => (string) $_manyToManyModels[1]->xpath('many-to-many-field')[0]['from'], 'to' => (string) $_manyToManyModels[1]->xpath('many-to-many-field')[0]['to']]]; $bundle['manyToManys'][] = $manyToMany; } $map['bundles'][] = $bundle; } // return $map; $yaml = new \Symfony\Component\Yaml\Yaml(); return $yaml->dump($map['bundles'][0], 7, 2); exit; }
/** * Returns a string containing the YAML representation of $value. * * @param array $value The value being encoded * @param int $inline The level where you switch to inline YAML * * @return string */ public static function yamlEncode(array $value, $inline = 3) { return Symfony\Component\Yaml\Yaml::dump($value, $inline, 4); }
protected function overrideServices($env, $output) { $services_settings = $this->getServicesSettings($env); $directory = $this->getDrupalHelper()->getRoot() . '/' . \Drupal::service('site.path'); $settings_services_file = $directory . '/services.yml'; if (!file_exists($settings_services_file)) { // Copying default services $default_services_file = $this->getDrupalHelper()->getRoot() . '/sites/default/default.services.yml'; if (!copy($default_services_file, $directory . '/services.yml')) { $output->writeln(' <error>' . $this->trans('commands.site.mode.messages.error-copying-file') . ': ' . $directory . '/services.yml' . '</error>'); return []; } } $yaml = new \Symfony\Component\Yaml\Yaml(); $content = file_get_contents($directory . '/services.yml'); $services = $yaml->parse($content); $result = []; foreach ($services_settings as $service => $parameters) { foreach ($parameters as $parameter => $value) { $services['parameters'][$service][$parameter] = $value; // Set values for output $result[$parameter]['service'] = $service; $result[$parameter]['parameter'] = $parameter; if (is_bool($value)) { $value = $value ? 'true' : 'false'; } $result[$parameter]['value'] = $value; } } if (file_put_contents($directory . '/services.yml', $yaml->dump($services))) { $output->writeln('<info>' . sprintf($this->trans('commands.site.mode.messages.services-file-overwritten'), $directory . '/services.yml') . '</info>'); } else { $output->writeln(' <error>' . $this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $directory . '/services.yml' . '</error>'); return []; } sort($result); return $result; }
<?php /** * * 0 "${APP_PATH}/patch_yaml/patch_yaml.php" * 1 "${APP_PATH}/array.yml" * 2 "$MYSQL_DB_NAME" * 3 "$MYSQL_USER_NAME" * 4 "$MYSQL_USER_PASSWORD"` * */ try { $autoload = (require_once __DIR__ . '/../vendor/autoload.php'); $array = Symfony\Component\Yaml\Yaml::parse(file_get_contents($argv[1])); $db = $array["db"]; $db["dbname"] = $argv[2]; $db["user"] = $argv[3]; $db["pass"] = $argv[4]; $array["db"] = $db; file_put_contents($argv[1], Symfony\Component\Yaml\Yaml::dump($array, 4, 4, true)); } catch (\Exception $e) { echo "Error: " . $e->getMessage(); exit(1); } echo "OK"; exit(0);
/** * Behat config file specifing the main context class, * the required Behat extensions and Moodle test wwwroot. * * @param array $features The system feature files * @param array $stepsdefinitions The system steps definitions * @return string */ protected static function get_config_file_contents($features, $stepsdefinitions) { global $CFG; // We require here when we are sure behat dependencies are available. require_once $CFG->dirroot . '/vendor/autoload.php'; $selenium2wdhost = array('wd_host' => 'http://localhost:4444/wd/hub'); $parallelruns = self::get_parallel_test_runs(); // If parallel run, then only divide features. if (!empty($CFG->behatrunprocess) && !empty($parallelruns)) { // Attempt to split into weighted buckets using timing information, if available. if ($alloc = self::profile_guided_allocate($features, max(1, $parallelruns), $CFG->behatrunprocess)) { $features = $alloc; } else { // Divide the list of feature files amongst the parallel runners. srand(crc32(floor(time() / 3600 / 24) . var_export($features, true))); shuffle($features); // Pull out the features for just this worker. if (count($features)) { $features = array_chunk($features, ceil(count($features) / max(1, $parallelruns))); // Check if there is any feature file for this process. if (!empty($features[$CFG->behatrunprocess - 1])) { $features = $features[$CFG->behatrunprocess - 1]; } else { $features = null; } } } // Set proper selenium2 wd_host if defined. if (!empty($CFG->behat_parallel_run[$CFG->behatrunprocess - 1]['wd_host'])) { $selenium2wdhost = array('wd_host' => $CFG->behat_parallel_run[$CFG->behatrunprocess - 1]['wd_host']); } } // It is possible that it has no value as we don't require a full behat setup to list the step definitions. if (empty($CFG->behat_wwwroot)) { $CFG->behat_wwwroot = 'http://itwillnotbeused.com'; } $basedir = $CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat'; $config = array('default' => array('paths' => array('features' => $basedir . DIRECTORY_SEPARATOR . 'features', 'bootstrap' => $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'bootstrap'), 'context' => array('class' => 'behat_init_context'), 'extensions' => array('Behat\\MinkExtension\\Extension' => array('base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => $selenium2wdhost), 'Moodle\\BehatExtension\\Extension' => array('formatters' => array('moodle_progress' => 'Moodle\\BehatExtension\\Formatter\\MoodleProgressFormatter', 'moodle_list' => 'Moodle\\BehatExtension\\Formatter\\MoodleListFormatter', 'moodle_step_count' => 'Moodle\\BehatExtension\\Formatter\\MoodleStepCountFormatter'), 'features' => $features, 'steps_definitions' => $stepsdefinitions)), 'formatter' => array('name' => 'moodle_progress'))); // In case user defined overrides respect them over our default ones. if (!empty($CFG->behat_config)) { $config = self::merge_config($config, $CFG->behat_config); } // Check for Moodle custom ones. if (!empty($CFG->behat_profiles) && is_array($CFG->behat_profiles)) { foreach ($CFG->behat_profiles as $profile => $values) { $config = self::merge_config($config, self::get_behat_profile($profile, $values)); } } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }
/** * Exports one or more variables to the selected format * Available formats: php (for testing purposes), yaml, xml and json * @param vars format and variables to dump */ public function export() { $args = func_get_args(); $format = strtolower($args[0]); $vars = array_slice($args, 1); $this->nodes = $this->_readVars($vars); $response = null; $exportArray = array(); $i = 1; foreach ($this->nodes as $v) { $exportArray['var' . $i] = $v->export(); $i++; } switch ($format) { case self::EXPORT_FORMAT_PHP: $response = $exportArray; break; case self::EXPORT_FORMAT_YAML: $yaml = new \Symfony\Component\Yaml\Yaml(); $response = $yaml->dump($exportArray); break; case self::EXPORT_FORMAT_XML: $serializer = new \Symfony\Component\Serializer\Encoder\XmlEncoder(); $response = $serializer->encode($exportArray, 'xml'); break; case self::EXPORT_FORMAT_JSON: $response = json_encode($exportArray); break; default: throw new InvalidFormatException(); } return $response; }
/** * Store the website details into the YML file * * @param string $folderPath * @param string $filePath * @param array $ymlContent * * @return null */ public function storeUpdateWebsiteDetailsToYml($folderPath, $filePath, $ymlContent) { if (empty($folderPath) || empty($filePath)) { return; } try { if (!file_exists($folderPath)) { \Cx\Lib\FileSystem\FileSystem::make_folder($folderPath); } $file = new \Cx\Lib\FileSystem\File($filePath); $file->touch(); $yaml = new \Symfony\Component\Yaml\Yaml(); $file->write($yaml->dump(array('PendingCodeBaseChanges' => $ymlContent))); } catch (\Exception $e) { \DBG::log($e->getMessage()); } }
/** * Behat config file specifing the main context class, * the required Behat extensions and Moodle test wwwroot. * * @param array $features The system feature files * @param array $contexts The system steps definitions * @param string $tags filter features with specified tags. * @param int $parallelruns number of parallel runs. * @param int $currentrun current run for which config file is needed. * @return string */ public function get_config_file_contents($features = '', $contexts = '', $tags = '', $parallelruns = 0, $currentrun = 0) { global $CFG; // Set current run and parallel run. if (!empty($parallelruns) && !empty($currentrun)) { $this->set_parallel_run($parallelruns, $currentrun); } // If tags defined then use them. This is for BC. if (!empty($tags)) { $this->set_tag_for_feature_filter($tags); } // If features not passed then get it. Empty array means we don't need to include features. if (empty($features) && !is_array($features)) { $features = $this->get_components_features(); } else { $this->features = $features; } // If stepdefinitions not passed then get the list. if (empty($contexts)) { $this->get_components_contexts(); } else { $this->contexts = $contexts; } // We require here when we are sure behat dependencies are available. require_once $CFG->dirroot . '/vendor/autoload.php'; $config = $this->build_config(); $config = $this->merge_behat_config($config); $config = $this->merge_behat_profiles($config); return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }
/** * Sets up a Drupal site for running functional and integration tests. * * Installs Drupal with the installation profile specified in * \Drupal\simpletest\WebTestBase::$profile into the prefixed database. * * Afterwards, installs any additional modules specified in the static * \Drupal\simpletest\WebTestBase::$modules property of each class in the * class hierarchy. * * After installation all caches are flushed and several configuration values * are reset to the values of the parent site executing the test, since the * default values may be incompatible with the environment in which tests are * being executed. */ protected function setUp() { // When running tests through the Simpletest UI (vs. on the command line), // Simpletest's batch conflicts with the installer's batch. Batch API does // not support the concept of nested batches (in which the nested is not // progressive), so we need to temporarily pretend there was no batch. // Backup the currently running Simpletest batch. $this->originalBatch = batch_get(); // Define information about the user 1 account. $this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => '*****@*****.**', 'pass_raw' => $this->randomMachineName())); // The child site derives its session name from the database prefix when // running web tests. $this->generateSessionName($this->databasePrefix); // Reset the static batch to remove Simpletest's batch operations. $batch =& batch_get(); $batch = array(); // Get parameters for install_drupal() before removing global variables. $parameters = $this->installParameters(); // Prepare installer settings that are not install_drupal() parameters. // Copy and prepare an actual settings.php, so as to resemble a regular // installation. // Not using File API; a potential error must trigger a PHP warning. $directory = DRUPAL_ROOT . '/' . $this->siteDirectory; copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php'); copy(DRUPAL_ROOT . '/sites/default/default.services.yml', $directory . '/services.yml'); // All file system paths are created by System module during installation. // @see system_requirements() // @see TestBase::prepareEnvironment() $settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE); $settings['settings']['file_private_path'] = (object) array('value' => $this->privateFilesDirectory, 'required' => TRUE); // Save the original site directory path, so that extensions in the // site-specific directory can still be discovered in the test site // environment. // @see \Drupal\Core\Extension\ExtensionDiscovery::scan() $settings['settings']['test_parent_site'] = (object) array('value' => $this->originalSite, 'required' => TRUE); // Add the parent profile's search path to the child site's search paths. // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories() $settings['conf']['simpletest.settings']['parent_profile'] = (object) array('value' => $this->originalProfile, 'required' => TRUE); $settings['settings']['apcu_ensure_unique_prefix'] = (object) array('value' => FALSE, 'required' => TRUE); $this->writeSettings($settings); // Allow for test-specific overrides. $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php'; if (file_exists($settings_testing_file)) { // Copy the testing-specific settings.php overrides in place. copy($settings_testing_file, $directory . '/settings.testing.php'); // Add the name of the testing class to settings.php and include the // testing specific overrides file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND); } $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml'; if (file_exists($settings_services_file)) { // Copy the testing-specific service overrides in place. copy($settings_services_file, $directory . '/services.yml'); } if ($this->strictConfigSchema) { // Add a listener to validate configuration schema on save. $yaml = new \Symfony\Component\Yaml\Yaml(); $services = $yaml->parse($directory . '/services.yml'); $services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed'], 'tags' => [['name' => 'event_subscriber']]]; file_put_contents($directory . '/services.yml', $yaml->dump($services)); } // Since Drupal is bootstrapped already, install_begin_request() will not // bootstrap again. Hence, we have to reload the newly written custom // settings.php manually. $class_loader = (require DRUPAL_ROOT . '/autoload.php'); Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader); // Execute the non-interactive installer. require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; install_drupal($class_loader, $parameters); // Import new settings.php written by the installer. Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader); foreach ($GLOBALS['config_directories'] as $type => $path) { $this->configDirectories[$type] = $path; } // After writing settings.php, the installer removes write permissions // from the site directory. To allow drupal_generate_test_ua() to write // a file containing the private key for drupal_valid_test_ua(), the site // directory has to be writable. // TestBase::restoreEnvironment() will delete the entire site directory. // Not using File API; a potential error must trigger a PHP warning. chmod($directory, 0777); $request = \Drupal::request(); $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', TRUE); $this->kernel->prepareLegacyRequest($request); // Force the container to be built from scratch instead of loaded from the // disk. This forces us to not accidentally load the parent site. $container = $this->kernel->rebuildContainer(); $config = $container->get('config.factory'); // Manually create and configure private and temporary files directories. // While these could be preset/enforced in settings.php like the public // files directory above, some tests expect them to be configurable in the // UI. If declared in settings.php, they would no longer be configurable. file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY); file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY); $config->getEditable('system.file')->set('path.temporary', $this->tempFilesDirectory)->save(); // Manually configure the test mail collector implementation to prevent // tests from sending out emails and collect them in state instead. // While this should be enforced via settings.php prior to installation, // some tests expect to be able to test mail system implementations. $config->getEditable('system.mail')->set('interface.default', 'test_mail_collector')->save(); // By default, verbosely display all errors and disable all production // environment optimizations for all tests to avoid needless overhead and // ensure a sane default experience for test authors. // @see https://www.drupal.org/node/2259167 $config->getEditable('system.logging')->set('error_level', 'verbose')->save(); $config->getEditable('system.performance')->set('css.preprocess', FALSE)->set('js.preprocess', FALSE)->save(); // Collect modules to install. $class = get_class($this); $modules = array(); while ($class) { if (property_exists($class, 'modules')) { $modules = array_merge($modules, $class::$modules); } $class = get_parent_class($class); } if ($modules) { $modules = array_unique($modules); try { $success = $container->get('module_installer')->install($modules, TRUE); $this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); } catch (\Drupal\Core\Extension\MissingDependencyException $e) { // The exception message has all the details. $this->fail($e->getMessage()); } $this->rebuildContainer(); } // Restore the original Simpletest batch. $batch =& batch_get(); $batch = $this->originalBatch; // Reset/rebuild all data structures after enabling the modules, primarily // to synchronize all data structures and caches between the test runner and // the child site. // @see \Drupal\Core\DrupalKernel::bootCode() // @todo Test-specific setUp() methods may set up further fixtures; find a // way to execute this after setUp() is done, or to eliminate it entirely. $this->resetAll(); $this->kernel->prepareLegacyRequest($request); // Explicitly call register() again on the container registered in \Drupal. // @todo This should already be called through // DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that // appears to be calling a different container. $this->container->get('stream_wrapper_manager')->register(); }
/** * Writes the component.yml file with the data defined in component data array * * @param \Cx\Core\View\Model\Entity\Theme $theme the theme object */ public function saveComponentData(\Cx\Core\View\Model\Entity\Theme $theme) { global $_ARRAYLANG; if (!file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) { if (!\Cx\Lib\FileSystem\FileSystem::make_folder(\Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername())) { \Message::add($theme->getFoldername() . " : " . $_ARRAYLANG['TXT_THEME_UNABLE_TO_CREATE']); } } $filePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . '/component.yml'; try { $file = new \Cx\Lib\FileSystem\File($filePath); $file->touch(); $yaml = new \Symfony\Component\Yaml\Yaml(); $file->write($yaml->dump(array('DlcInfo' => $theme->getComponentData()))); } catch (\Exception $e) { \DBG::log($e->getMessage()); throw new $e(); } }
/** * Behat config file specifing the main context class, * the required Behat extensions and Moodle test wwwroot. * * @param array $features The system feature files * @param array $stepsdefinitions The system steps definitions * @return string */ protected static function get_config_file_contents($features, $stepsdefinitions) { global $CFG; // We require here when we are sure behat dependencies are available. require_once $CFG->dirroot . '/vendor/autoload.php'; // It is possible that it has no value as we don't require a full behat setup to list the step definitions. if (empty($CFG->behat_wwwroot)) { $CFG->behat_wwwroot = 'http://itwillnotbeused.com'; } $basedir = $CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat'; $config = array('default' => array('paths' => array('features' => $basedir . DIRECTORY_SEPARATOR . 'features', 'bootstrap' => $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'bootstrap'), 'context' => array('class' => 'behat_init_context'), 'extensions' => array('Behat\\MinkExtension\\Extension' => array('base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => null), 'Moodle\\BehatExtension\\Extension' => array('formatters' => array('moodle_progress' => 'Moodle\\BehatExtension\\Formatter\\MoodleProgressFormatter', 'moodle_list' => 'Moodle\\BehatExtension\\Formatter\\MoodleListFormatter'), 'features' => $features, 'steps_definitions' => $stepsdefinitions)), 'formatter' => array('name' => 'moodle_progress'))); // In case user defined overrides respect them over our default ones. if (!empty($CFG->behat_config)) { $config = self::merge_config($config, $CFG->behat_config); } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }
/** * Prepares site settings and services before installation. */ protected function prepareSettings() { // Prepare installer settings that are not install_drupal() parameters. // Copy and prepare an actual settings.php, so as to resemble a regular // installation. // Not using File API; a potential error must trigger a PHP warning. $directory = DRUPAL_ROOT . '/' . $this->siteDirectory; copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php'); // All file system paths are created by System module during installation. // @see system_requirements() // @see TestBase::prepareEnvironment() $settings['settings']['file_public_path'] = (object) ['value' => $this->publicFilesDirectory, 'required' => TRUE]; $settings['settings']['file_private_path'] = (object) ['value' => $this->privateFilesDirectory, 'required' => TRUE]; // Save the original site directory path, so that extensions in the // site-specific directory can still be discovered in the test site // environment. // @see \Drupal\Core\Extension\ExtensionDiscovery::scan() $settings['settings']['test_parent_site'] = (object) ['value' => $this->originalSite, 'required' => TRUE]; // Add the parent profile's search path to the child site's search paths. // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories() $settings['conf']['simpletest.settings']['parent_profile'] = (object) ['value' => $this->originalProfile, 'required' => TRUE]; $settings['settings']['apcu_ensure_unique_prefix'] = (object) ['value' => FALSE, 'required' => TRUE]; $this->writeSettings($settings); // Allow for test-specific overrides. $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php'; if (file_exists($settings_testing_file)) { // Copy the testing-specific settings.php overrides in place. copy($settings_testing_file, $directory . '/settings.testing.php'); // Add the name of the testing class to settings.php and include the // testing specific overrides file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND); } $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml'; if (!file_exists($settings_services_file)) { // Otherwise, use the default services as a starting point for overrides. $settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml'; } // Copy the testing-specific service overrides in place. copy($settings_services_file, $directory . '/services.yml'); if ($this->strictConfigSchema) { // Add a listener to validate configuration schema on save. $yaml = new \Symfony\Component\Yaml\Yaml(); $content = file_get_contents($directory . '/services.yml'); $services = $yaml->parse($content); $services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed', $this->getConfigSchemaExclusions()], 'tags' => [['name' => 'event_subscriber']]]; file_put_contents($directory . '/services.yml', $yaml->dump($services)); } // Since Drupal is bootstrapped already, install_begin_request() will not // bootstrap again. Hence, we have to reload the newly written custom // settings.php manually. Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader); }
/** * Behat config file specifing the main context class, * the required Behat extensions and Mahara test wwwroot. * * @param array $features The system feature files * @param array $stepsdefinitions The system steps definitions * @return string */ protected static function get_config_file_contents($features, $stepsdefinitions) { global $CFG; // We require here when we are sure behat dependencies are available. require_once $CFG->docroot . '../external/vendor/autoload.php'; // It is possible that it has no value as we don't require a full behat setup to list the step definitions. if (empty($CFG->behat_wwwroot)) { $CFG->behat_wwwroot = 'http://example.com'; } $basedir = $CFG->docroot . 'testing' . DIRECTORY_SEPARATOR . 'frameworks' . DIRECTORY_SEPARATOR . 'behat'; $config = array('default' => array('paths' => array('features' => $basedir . DIRECTORY_SEPARATOR . 'features', 'bootstrap' => $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'bootstrap'), 'context' => array('class' => 'BehatMaharaInitContext'), 'extensions' => array('Behat\\MinkExtension\\Extension' => array('base_url' => $CFG->behat_wwwroot, 'files_path' => get_mahararoot_dir() . '/test/behat/upload_files', 'goutte' => null, 'selenium2' => null), $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'MaharaExtension.php' => array('formatters' => array('mahara_progress' => 'MaharaProgressFormatter'), 'features' => $features, 'steps_definitions' => $stepsdefinitions)), 'formatter' => array('name' => 'mahara_progress'))); // In case user defined overrides respect them over our default ones. if (!empty($CFG->behat_config)) { $config = self::merge_config($config, $CFG->behat_config); } return Symfony\Component\Yaml\Yaml::dump($config, 10, 2); }