117 : array
118 {
119
120
121
122 $tests = [
123 'Test with empty string.' => ['', '', [], []],
124 'Test with correct link and target = _self is added.' => [
125 'A link to <a href="%scrs_345%s" target="_self">a course</a>.',
126 'A link to <a href="%scrs_345%s">somewhere</a>.',
127 [345 => 5],
128 [5 => 'a course'],
129 ],
130 'Test with multiple correct links.' => [
131 'A link to <a href="%scrs_345%s" target="_self">a course</a> and to <a href="%scrs_87%s" target="_self">another course</a>.',
132 'A link to <a href="%scrs_345%s">somewhere</a> and to <a href="%scrs_87%s">somewhere else</a>.',
133 [345 => 5, 87 => 45],
134 [5 => 'a course', 45 => 'another course'],
135 ],
136 'Test links with invalid ref id.' => [
137 'A link to <a href="%scrs_345%s">somewhere</a>.',
138 'A link to <a href="%scrs_345%s">somewhere</a>.',
139 [345 => 0],
140 [],
141 ],
142 'The target attribute is REPLACED with _self.' => [
143 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
144 'A link to <a target="bogus target" href="%scrs_345%s">somewhere</a>.',
145 [345 => 8],
146 [8 => 'some course'],
147 ],
148 'The attributes position does not matter, it is always replaced with target="_self".' => [
149 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
150 'A link to <a href="%scrs_345%s" target="bogus target">somewhere</a>.',
151 [345 => 8],
152 [8 => 'some course'],
153 ],
154 'All attributes are removed from the link.' => [
155 'A link to <a href="%scrs_345%s" target="_self">some course</a>.',
156 'A link to <a href="%scrs_345%s" class="very-important-css-class">somewhere</a>.',
157 [345 => 8],
158 [8 => 'some course'],
159 ],
160 ];
161
162 $linkFormats = [
163 'With goto.php: ' => [self::HTTP_HOST . '/goto.php?target=', ''],
164 'With goto_*.html: ' => [self::HTTP_HOST . '/goto_', '.html'],
165 ];
166
167 $repeatForFormat = static function (string $format, array $values): array {
168 return array_merge(
169 ...array_fill(0, (count(explode('%s', $format)) - 1) / 2, $values)
170 );
171 };
172
173 $allTests = [];
174 foreach ($linkFormats as $name => $args) {
175 foreach ($tests as $key => $array) {
176 $allTests[$name . $key] = array_merge([
177 sprintf($array[0], ...$repeatForFormat($array[0], $args)),
178 sprintf($array[1], ...$repeatForFormat($array[1], $args)),
179 ], array_slice($array, 2));
180 }
181 }
182
183 return $allTests;
184 }