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/>.
18 * Nasty strings to use in tests.
22 * @copyright 2013 David Monllaó
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die;
29 * Nasty strings manager.
31 * Responds to nasty strings requests with a random string of the list
32 * to try with different combinations in different places.
36 * @copyright 2013 David Monllaó
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 * List of different strings to fill fields and assert against them
44 * Non of these strings can be a part of another one, this would not be good
45 * when using more one string at the same time and asserting results.
50 protected static $strings = array(
51 '< > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ \\\" \\ , ; : . 日本語% %%',
52 '& \' \\" \ \'$@NULL@$ < > & < > @@TEST@@ \\\" \\ , ; : . 日本語% %%',
53 '< > & < > & \' \\" \ \\\" \\ , ; : . \'$@NULL@$ @@TEST@@ 日本語% %%',
54 '< > & < > & \' \\" \ \'$@NULL@$ 日本語% %%@@TEST@@ \. \\" \\ , ; :',
55 '< > & < > \\\" \\ , ; : . 日本語& \' \\" \ \'$@NULL@$ @@TEST@@% %%',
56 '\' \\" \ \'$@NULL@$ @@TEST@@ < > & < > & \\\" \\ , ; : . 日本語% %%',
57 '\\\" \\ , ; : . 日本語% < > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ %%',
58 '< > & < > & \' \\" \ \'$@NULL@$ 日本語% %% @@TEST@@ \\\" \\ . , ; :',
59 '. 日本語& \' \\" < > & < > \\ , ; : \ \'$@NULL@$ \\\" @@TEST@@% %%',
60 '& \' \\" \ < > & < > \\\" \\ , ; : . 日本語\'$@NULL@$ @@TEST@@% %%',
64 * Already used nasty strings.
66 * This array will be cleaned before each scenario.
71 protected static $usedstrings = array();
74 * Returns a nasty string and stores the key mapping.
77 * @param string $key The key
80 public static function get($key) {
82 // If have been used during the this tests return it.
83 if (isset(self
::$usedstrings[$key])) {
84 return self
::$strings[self
::$usedstrings[$key]];
87 // Getting non-used random string.
89 $index = self
::random_index();
90 } while (in_array($index, self
::$usedstrings));
92 // Mark the string as already used.
93 self
::$usedstrings[$key] = $index;
95 return self
::$strings[$index];
99 * Resets the used strings var.
103 public static function reset_used_strings() {
104 self
::$usedstrings = array();
108 * Returns a random index.
112 protected static function random_index() {
113 return mt_rand(0, count(self
::$strings) - 1);