mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-81960 core: Move progress_trace tests out of weblib
This commit is contained in:
parent
b6d08ad1d7
commit
e3f795fc72
@ -25,14 +25,14 @@ use core\output\progress_trace;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
*/
|
||||
class combined_progress_trace extends \progress_trace {
|
||||
class combined_progress_trace extends progress_trace {
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param array $traces multiple traces
|
||||
*/
|
||||
public function __construct(
|
||||
/** @var array The list of traces */
|
||||
/** @var progress_trace[] The list of traces */
|
||||
protected array $traces,
|
||||
) {
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use core\output\progress_trace;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package core
|
||||
*/
|
||||
class progress_trace_buffer extends \progress_trace {
|
||||
class progress_trace_buffer extends progress_trace {
|
||||
/** @var string output buffer */
|
||||
protected string $buffer = '';
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\html_list_progress_trace.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\html_list_progress_trace
|
||||
*/
|
||||
final class html_list_progress_trace_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$trace = new html_list_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("<ul>\n<li>do<ul>\n<li>re<ul>\n<li>mi</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n");
|
||||
}
|
||||
}
|
40
lib/tests/output/progress_trace/html_progress_trace_test.php
Normal file
40
lib/tests/output/progress_trace/html_progress_trace_test.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\html_progress_trace.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\html_progress_trace
|
||||
*/
|
||||
final class html_progress_trace_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$trace = new html_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n");
|
||||
}
|
||||
}
|
42
lib/tests/output/progress_trace/null_progress_trace_test.php
Normal file
42
lib/tests/output/progress_trace/null_progress_trace_test.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\null_progress_trace.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\null_progress_trace
|
||||
*/
|
||||
final class null_progress_trace_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$trace = new null_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$output = ob_get_contents();
|
||||
$this->assertSame('', $output);
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\progress_trace_buffer.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\progress_trace_buffer
|
||||
*/
|
||||
final class progress_trace_buffer_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$trace = new progress_trace_buffer(new html_progress_trace());
|
||||
ob_start();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $output);
|
||||
$this->assertSame($output, $trace->get_buffer());
|
||||
|
||||
$trace = new progress_trace_buffer(new html_progress_trace(), false);
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer());
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer());
|
||||
$trace->reset_buffer();
|
||||
$this->assertSame('', $trace->get_buffer());
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\test_combined_progress_trace.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\test_combined_progress_trace
|
||||
*/
|
||||
final class test_combined_progress_trace_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$trace1 = new progress_trace_buffer(new html_progress_trace(), false);
|
||||
$trace2 = new progress_trace_buffer(new text_progress_trace(), false);
|
||||
|
||||
$trace = new combined_progress_trace([$trace1, $trace2]);
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace1->get_buffer());
|
||||
$this->assertSame("do\n re\n mi\n", $trace2->get_buffer());
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
}
|
42
lib/tests/output/progress_trace/text_progress_trace_test.php
Normal file
42
lib/tests/output/progress_trace/text_progress_trace_test.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output\progress_trace;
|
||||
|
||||
/**
|
||||
* Tests for \core\progress_trace\text_progress_trace.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core\progress_trace\text_progress_trace
|
||||
*/
|
||||
final class text_progress_trace_test extends \advanced_testcase {
|
||||
/**
|
||||
* Tests for the trace.
|
||||
*/
|
||||
public function test_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new text_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("do\n re\n mi\n");
|
||||
}
|
||||
}
|
@ -510,112 +510,6 @@ class weblib_test extends advanced_testcase {
|
||||
$this->assertSame($CFG->wwwroot.'/course/view.php?id=1', qualified_me());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \null_progress_trace
|
||||
*/
|
||||
public function test_null_progress_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new null_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$output = ob_get_contents();
|
||||
$this->assertSame('', $output);
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \null_progress_trace
|
||||
*/
|
||||
public function test_text_progress_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new text_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("do\n re\n mi\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \html_progress_trace
|
||||
*/
|
||||
public function test_html_progress_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new html_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \html_list_progress_trace
|
||||
*/
|
||||
public function test_html_list_progress_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new html_list_progress_trace();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->expectOutputString("<ul>\n<li>do<ul>\n<li>re<ul>\n<li>mi</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \progress_trace_buffer
|
||||
*/
|
||||
public function test_progress_trace_buffer(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace = new progress_trace_buffer(new html_progress_trace());
|
||||
ob_start();
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $output);
|
||||
$this->assertSame($output, $trace->get_buffer());
|
||||
|
||||
$trace = new progress_trace_buffer(new html_progress_trace(), false);
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer());
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace->get_buffer());
|
||||
$trace->reset_buffer();
|
||||
$this->assertSame('', $trace->get_buffer());
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \combined_progress_trace
|
||||
*/
|
||||
public function test_combined_progress_trace(): void {
|
||||
$this->resetAfterTest(false);
|
||||
|
||||
$trace1 = new progress_trace_buffer(new html_progress_trace(), false);
|
||||
$trace2 = new progress_trace_buffer(new text_progress_trace(), false);
|
||||
|
||||
$trace = new combined_progress_trace(array($trace1, $trace2));
|
||||
$trace->output('do');
|
||||
$trace->output('re', 1);
|
||||
$trace->output('mi', 2);
|
||||
$trace->finished();
|
||||
$this->assertSame("<p>do</p>\n<p>  re</p>\n<p>    mi</p>\n", $trace1->get_buffer());
|
||||
$this->assertSame("do\n re\n mi\n", $trace2->get_buffer());
|
||||
$this->expectOutputString('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_debugging
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user