MDL-37046 behat: Added to standard plugins list
[moodle.git] / admin / tool / behat / cli / util.php
CommitLineData
ecbd3cbe
DM
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
0b5f481b 18 * CLI tool
ecbd3cbe
DM
19 *
20 * @package tool_behat
21 * @copyright 2012 David MonllaĆ³
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25define('CLI_SCRIPT', true);
26
27require(__DIR__ . '/../../../../config.php');
28require_once($CFG->libdir . '/clilib.php');
29require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/behat/locallib.php');
30
a09534f4 31// CLI options.
ecbd3cbe
DM
32list($options, $unrecognized) = cli_get_params(
33 array(
0b5f481b
DM
34 'help' => false,
35 'enable' => false,
36 'disable' => false,
ecbd3cbe
DM
37 ),
38 array(
39 'h' => 'help'
40 )
41);
42
43$help = "
44Behat tool
45
ecbd3cbe 46Options:
ff2ec29b 47--enable Enables test environment and updates tests list
0b5f481b 48--disable Disables test environment
ecbd3cbe
DM
49
50-h, --help Print out this help
51
52Example from Moodle root directory:
0b5f481b 53\$ php admin/tool/behat/cli/util.php --enable
25833ef8 54
a09534f4 55More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests
ecbd3cbe
DM
56";
57
58if (!empty($options['help'])) {
59 echo $help;
60 exit(0);
61}
62
63if ($unrecognized) {
64 $unrecognized = implode("\n ", $unrecognized);
65 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
66}
67
0b5f481b
DM
68// Run command.
69if ($options['enable']) {
70 $action = 'enable';
71} else if ($options['disable']) {
72 $action = 'disable';
73} else {
ecbd3cbe
DM
74 echo $help;
75 exit(0);
76}
77
0b5f481b 78tool_behat::switchenvironment($action);
6d994c51 79
0b5f481b 80mtrace(get_string('testenvironment' . $action, 'tool_behat'));
ecbd3cbe 81