Skip to content

Commit b006a9e

Browse files
committed
MBS-10672: move standalone tests into data providers
1 parent cf750c4 commit b006a9e

File tree

1 file changed

+33
-97
lines changed

1 file changed

+33
-97
lines changed

tests/base_purpose_test.php

Lines changed: 33 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2929
*/
3030
final class base_purpose_test extends \advanced_testcase {
31-
/** @var string Triple backtick for markdown code blocks. */
32-
private const CODEBLOCK = "\x60\x60\x60";
33-
34-
/** @var string Single backtick for inline code. */
35-
private const BACKTICK = "\x60";
36-
3731
/**
3832
* Test if all purpose plugins have a proper description.
3933
*
@@ -148,6 +142,23 @@ public static function format_output_html_escaping_provider(): array {
148142
'mustcontain' => ['<>&'],
149143
'mustnotcontain' => [],
150144
],
145+
'windows_line_endings' => [
146+
'input' => "Code:\r\n\r\n" . $codeblock . "html\r\n<div>Test</div>\r\n" . $codeblock,
147+
'mustcontain' => ['&lt;div&gt;'],
148+
'mustnotcontain' => [],
149+
],
150+
'mixed_content' => [
151+
'input' => '# Tutorial' . PHP_EOL . PHP_EOL
152+
. 'Here\'s how:' . PHP_EOL . PHP_EOL
153+
. '1. Write HTML' . PHP_EOL
154+
. '2. Add CSS' . PHP_EOL . PHP_EOL
155+
. $codeblock . 'html' . PHP_EOL
156+
. '<p>Hello</p>' . PHP_EOL
157+
. $codeblock . PHP_EOL . PHP_EOL
158+
. 'That\'s **all**!',
159+
'mustcontain' => ['<h1>', '<ol>', '&lt;p&gt;Hello&lt;/p&gt;', '<strong>all</strong>'],
160+
'mustnotcontain' => [],
161+
],
151162
];
152163
}
153164

@@ -254,6 +265,22 @@ public static function format_output_markdown_formatting_provider(): array {
254265
'input' => $codeblock . 'php' . PHP_EOL . 'echo \'Hello\';' . PHP_EOL . $codeblock,
255266
'mustcontain' => ['<pre>', '<code'],
256267
],
268+
'mathjax_inline_delimiters' => [
269+
'input' => 'The formula is \\(x^2 + y^2 = z^2\\)',
270+
'mustcontain' => ['\\(', '\\)'],
271+
],
272+
'mathjax_display_delimiters' => [
273+
'input' => 'Display math: \\[E = mc^2\\]',
274+
'mustcontain' => ['\\[', '\\]'],
275+
],
276+
'empty_input' => [
277+
'input' => '',
278+
'mustcontain' => [],
279+
],
280+
'plain_text' => [
281+
'input' => 'Just plain text without any formatting.',
282+
'mustcontain' => ['Just plain text'],
283+
],
257284
];
258285
}
259286

@@ -273,95 +300,4 @@ public function test_format_output_markdown_formatting(string $input, array $mus
273300
$this->assertStringContainsString($expected, $output);
274301
}
275302
}
276-
277-
/**
278-
* Test that MathJax inline delimiters are properly escaped.
279-
*
280-
* @covers \local_ai_manager\base_purpose::format_output
281-
*/
282-
public function test_format_output_mathjax_inline_delimiters_escaped(): void {
283-
$purpose = new base_purpose();
284-
$input = 'The formula is \\(x^2 + y^2 = z^2\\)';
285-
$output = $purpose->format_output($input);
286-
287-
// MathJax delimiters should be present (escaped for frontend processing).
288-
$this->assertStringContainsString('\\(', $output);
289-
$this->assertStringContainsString('\\)', $output);
290-
}
291-
292-
/**
293-
* Test that MathJax display delimiters are properly escaped.
294-
*
295-
* @covers \local_ai_manager\base_purpose::format_output
296-
*/
297-
public function test_format_output_mathjax_display_delimiters_escaped(): void {
298-
$purpose = new base_purpose();
299-
$input = 'Display math: \\[E = mc^2\\]';
300-
$output = $purpose->format_output($input);
301-
302-
// MathJax delimiters should be present (escaped for frontend processing).
303-
$this->assertStringContainsString('\\[', $output);
304-
$this->assertStringContainsString('\\]', $output);
305-
}
306-
307-
/**
308-
* Test empty input.
309-
*
310-
* @covers \local_ai_manager\base_purpose::format_output
311-
*/
312-
public function test_format_output_empty_input(): void {
313-
$purpose = new base_purpose();
314-
$output = $purpose->format_output('');
315-
316-
$this->assertEmpty(trim($output));
317-
}
318-
319-
/**
320-
* Test plain text without any markdown.
321-
*
322-
* @covers \local_ai_manager\base_purpose::format_output
323-
*/
324-
public function test_format_output_plain_text(): void {
325-
$purpose = new base_purpose();
326-
$input = 'Just plain text without any formatting.';
327-
$output = $purpose->format_output($input);
328-
329-
$this->assertStringContainsString('Just plain text', $output);
330-
}
331-
332-
/**
333-
* Test mixed content: text, code, lists together.
334-
*
335-
* @covers \local_ai_manager\base_purpose::format_output
336-
*/
337-
public function test_format_output_mixed_content(): void {
338-
$purpose = new base_purpose();
339-
$input = '# Tutorial' . PHP_EOL . PHP_EOL
340-
. 'Here\'s how:' . PHP_EOL . PHP_EOL
341-
. '1. Write HTML' . PHP_EOL
342-
. '2. Add CSS' . PHP_EOL . PHP_EOL
343-
. self::CODEBLOCK . 'html' . PHP_EOL
344-
. '<p>Hello</p>' . PHP_EOL
345-
. self::CODEBLOCK . PHP_EOL . PHP_EOL
346-
. 'That\'s **all**!';
347-
$output = $purpose->format_output($input);
348-
349-
$this->assertStringContainsString('<h1>', $output);
350-
$this->assertStringContainsString('<ol>', $output);
351-
$this->assertStringContainsString('&lt;p&gt;Hello&lt;/p&gt;', $output);
352-
$this->assertStringContainsString('<strong>all</strong>', $output);
353-
}
354-
355-
/**
356-
* Test Windows-style line endings in code blocks.
357-
*
358-
* @covers \local_ai_manager\base_purpose::format_output
359-
*/
360-
public function test_format_output_windows_line_endings(): void {
361-
$purpose = new base_purpose();
362-
$input = "Code:\r\n\r\n" . self::CODEBLOCK . "html\r\n<div>Test</div>\r\n" . self::CODEBLOCK;
363-
$output = $purpose->format_output($input);
364-
365-
$this->assertStringContainsString('&lt;div&gt;', $output);
366-
}
367303
}

0 commit comments

Comments
 (0)