MDL-80203 courseformat: Fix some typos and PHPDoc
[moodle.git] / lib / tests / behat_lib_test.php
blobfefaf4c36298669256c9376a00fc25187f742a54
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.
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/>.
17 /**
18 * Unit tests for parts of /lib/behat/lib.php.
20 * @package core
21 * @category test
22 * @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /**
27 * Unit tests for parts of /lib/behat/lib.php.
29 * @package core
30 * @category test
31 * @copyright 2021 Université Rennes 2 {@link https://www.univ-rennes2.fr}
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class behat_lib_test extends advanced_testcase {
36 /**
37 * Setup function
39 * Skip these tests if behat is not configured.
41 * @return void
43 public function setUp(): void {
44 global $CFG;
46 if (empty($CFG->behat_wwwroot) || empty($CFG->behat_dataroot) || empty($CFG->behat_prefix)) {
47 $this->markTestSkipped('Behat not configured');
51 /**
52 * Tests for behat_is_requested_url() function.
54 * @dataProvider url_provider
55 * @covers ::behat_is_requested_url
57 * @param string $url URL used with behat_is_requested_url() function.
58 * @param bool $expectedvalue Expected value returned by behat_is_requested_url() function.
59 * @param array $environment Values to override $_SERVER global variable.
61 public function test_behat_is_requested_url($url, $expectedvalue, $environment) {
62 // Save $_SERVER variable.
63 $server = $_SERVER;
65 // Setup $_SERVER variable for test.
66 list($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['SCRIPT_NAME']) = $environment;
68 // Test behat_is_requested_url() function.
69 $this->assertSame($expectedvalue, behat_is_requested_url($url));
71 // Restore $_SERVER variable.
72 $_SERVER = $server;
75 /**
76 * Data provider for test_behat_is_requested_url.
78 * @return array Array of values to test behat_is_requested_url() function.
80 public function url_provider() {
81 return [
82 // Tests for common ports.
83 ['http://behat.moodle.org', true, ['behat.moodle.org', 80, '']],
84 ['https://behat.moodle.org', true, ['behat.moodle.org', 443, '']],
86 // Test for custom port.
87 ['http://behat.moodle.org:8080', true, ['behat.moodle.org', 8080, '']],
89 // Test for url with path.
90 ['http://behat.moodle.org/behat', true, ['behat.moodle.org', 80, '/behat']],
92 // Test for url that does not match with environment.
93 ['http://behat.moodle.org', false, ['moodle.org', 80, '']],