2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
20 * Unit tests for the xhprof class.
24 * @copyright 2019 Brendan Heywood <brendan@catalyst-au.net>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 class xhprof_test
extends \advanced_testcase
{
30 * Data provider for string matches
34 public function profiling_string_matches_provider() {
36 ['/index.php', '/index.php', true],
37 ['/some/dir/index.php', '/index.php', false],
38 ['/course/view.php', '/course/view.php', true],
39 ['/view.php', '/course/view.php', false],
40 ['/mod/forum', '/mod/forum/*', false],
41 ['/mod/forum/', '/mod/forum/*', true],
42 ['/mod/forum/index.php', '/mod/forum/*', true],
43 ['/mod/forum/foo.php', '/mod/forum/*', true],
44 ['/mod/forum/view.php', '/mod/*/view.php', true],
45 ['/mod/one/two/view.php', '/mod/*/view.php', true],
46 ['/view.php', '*/view.php', true],
47 ['/mod/one/two/view.php', '*/view.php', true],
48 ['/foo.php', '/foo.php,/bar.php', true],
49 ['/bar.php', '/foo.php,/bar.php', true],
50 ['/foo/bar.php', "/foo.php,/bar.php", false],
51 ['/foo/bar.php', "/foo.php,*/bar.php", true],
52 ['/foo/bar.php', "/foo*.php,/bar.php", true],
53 ['/foo.php', "/foo.php\n/bar.php", true],
54 ['/bar.php', "/foo.php\n/bar.php", true],
55 ['/foo/bar.php', "/foo.php\n/bar.php", false],
56 ['/foo/bar.php', "/foo.php\n*/bar.php", true],
57 ['/foo/bar.php', "/foo*.php\n/bar.php", true],
62 * Test the matching syntax
64 * @dataProvider profiling_string_matches_provider
65 * @param string $string
66 * @param string $patterns
67 * @param bool $expected
69 public function test_profiling_string_matches($string, $patterns, $expected) {
72 require_once($CFG->libdir
. '/xhprof/xhprof_moodle.php');
74 $result = profiling_string_matches($string, $patterns);
75 $this->assertSame($result, $expected);