Esempio n. 1
0
 /**
  * behat_config_manager tests.
  */
 public function test_config_file_contents()
 {
     global $CFG;
     // Skip tests if behat is not installed.
     $vendorpath = $CFG->dirroot . '/vendor';
     if (!file_exists($vendorpath . '/autoload.php') || !is_dir($vendorpath . '/behat')) {
         $this->markTestSkipped('Behat not installed.');
     }
     // It is possible that it has no value.
     if (empty($CFG->behat_wwwroot)) {
         $CFG->behat_wwwroot = behat_get_wwwroot();
     }
     // To avoid user value at config.php level.
     unset($CFG->behat_config);
     // List.
     $features = array('feature1', 'feature2', 'feature3');
     // Associative array.
     $stepsdefinitions = array('micarro' => '/me/lo/robaron', 'anoche' => '/cuando/yo/dormia');
     $contents = testable_behat_config_manager::get_config_file_contents($features, $stepsdefinitions);
     // YAML decides when is is necessary to wrap strings between single quotes, so not controlled
     // values like paths should not be asserted including the key name as they would depend on the
     // directories values.
     $this->assertContains($CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'features', $contents);
     // Not quoted strings.
     $this->assertContains('micarro: /me/lo/robaron', $contents);
     $this->assertContains('class: behat_init_context', $contents);
     // YAML uses single quotes to wrap URL strings.
     $this->assertContains("base_url: '" . $CFG->behat_wwwroot . "'", $contents);
     // Lists.
     $this->assertContains('- feature1', $contents);
     $this->assertContains('- feature3', $contents);
     unset($CFG->behat_wwwroot);
 }
 /**
  * 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.
     if (empty($CFG->behat_wwwroot)) {
         $CFG->behat_wwwroot = behat_get_wwwroot();
     }
     $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'), '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);
 }
Esempio n. 3
0
define('BEHAT_UTIL', true);
define('CLI_SCRIPT', true);
define('ABORT_AFTER_CONFIG', true);
define('NO_OUTPUT_BUFFERING', true);
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
// Getting $CFG data.
require_once __DIR__ . '/../../../../config.php';
// When we use the utilities we don't know how the site
// will be accessed, so if neither $CFG->behat_switchcompletely or
// $CFG->behat_wwwroot are set we must think that the site will
// be accessed using the built-in server which is set by default
// to localhost:8000. We need to do this to prevent uses of the production
// wwwroot when the site is being installed / dropped...
$CFG->behat_wwwroot = behat_get_wwwroot();
// Checking the integrity of the provided $CFG->behat_* vars
// to prevent conflicts with production and phpunit environments.
behat_check_config_vars();
// Create behat_dataroot if it doesn't exists.
if (!file_exists($CFG->behat_dataroot)) {
    if (!mkdir($CFG->behat_dataroot, $CFG->directorypermissions)) {
        behat_error(BEHAT_EXITCODE_PERMISSIONS, '$CFG->behat_dataroot directory can not be created');
    }
}
if (!is_dir($CFG->behat_dataroot) || !is_writable($CFG->behat_dataroot)) {
    behat_error(BEHAT_EXITCODE_PERMISSIONS, '$CFG->behat_dataroot directory has no permissions or is not a directory');
}
// Check that the directory does not contains other things.
if (!file_exists("{$CFG->behat_dataroot}/behattestdir.txt")) {
    if ($dh = opendir($CFG->behat_dataroot)) {
Esempio n. 4
0
    }
    echo 'Fatal error: $CFG->wwwroot is not configured! Exiting.' . "\n";
    exit(1);
}
// Test environment is requested if:
// * If $CFG->behat_switchcompletely has been set (maintains CLI scripts behaviour, which ATM is only preventive).
// * If we are accessing though the built-in web server (cli-server).
// * Behat is running (constant set hooking the behat init process before requiring config.php).
// * If $CFG->behat_wwwroot has been set and the hostname/port match what the page was requested with.
// Test environment is enabled if:
// * User has previously enabled through admin/tool/behat/cli/util.php --enable or admin/tool/behat/cli/init.php
// Both are required to switch to test mode
if (!defined('BEHAT_SITE_RUNNING') && !empty($CFG->behat_dataroot) && !empty($CFG->behat_prefix) && file_exists($CFG->behat_dataroot)) {
    // Only included if behat_* are set, it is not likely to be a production site.
    require_once __DIR__ . '/../lib/behat/lib.php';
    $defaultbehatwwwroot = behat_get_wwwroot();
    if (!empty($CFG->behat_switchcompletely) && php_sapi_name() !== 'cli') {
        // Switch completely uses the production wwwroot as the test site URL.
        $behatwwwroot = $defaultbehatwwwroot;
    } elseif (php_sapi_name() === 'cli-server') {
        // If we are using the built-in server we use the provided $CFG->behat_wwwroot
        // value or the default one if $CFG->behat_wwwroot is not set, only if it matches
        // the requested URL.
        if (behat_is_requested_url($defaultbehatwwwroot)) {
            $behatwwwroot = $defaultbehatwwwroot;
        }
    } elseif (defined('BEHAT_TEST')) {
        // This is when moodle codebase runs through vendor/bin/behat, we "are not supposed"
        // to need a wwwroot, but before using the production one we should set something else
        // as an alternative.
        $behatwwwroot = $defaultbehatwwwroot;