/** * behat_config_manager tests. */ public function test_config_file_contents() { global $CFG; $this->resetAfterTest(true); // 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.'); } // Add some fake test url. $CFG->behat_wwwroot = 'http://example.com/behat'; // 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); $this->assertDebuggingCalled("Use of get_config_file_contents is deprecated, please see behat_config_util"); // 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, $contents['default']['extensions']['Moodle\\BehatExtension']['moodledirroot']); // Not quoted strings. $this->assertEquals('/me/lo/robaron', $contents['default']['extensions']['Moodle\\BehatExtension']['steps_definitions']['micarro']); // YAML uses single quotes to wrap URL strings. $this->assertEquals($CFG->behat_wwwroot, $contents['default']['extensions']['Behat\\MinkExtension']['base_url']); // Lists. $this->assertEquals('feature1', $contents['default']['suites']['default']['paths'][0]); $this->assertEquals('feature3', $contents['default']['suites']['default']['paths'][2]); unset($CFG->behat_wwwroot); }
/** * 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); }