. namespace core; /** * Tests for the \core\setup class. * * @package core * @category test * @copyright Andrew Lyons * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ #[\PHPUnit\Framework\Attributes\CoversClass(\core\setup::class)] final class setup_test extends \advanced_testcase { #[\PHPUnit\Framework\Attributes\DataProvider('wwwroot_validity_provider')] public function test_wwwroot_ends_in_slash( string $wwwroot, bool $valid, ?string $exceptionstring = null, ): void { global $CFG; $this->resetAfterTest(true); $CFG->wwwroot = $wwwroot; if (!$valid) { $this->expectException(\core\exception\moodle_exception::class); $this->expectExceptionMessage($exceptionstring); } $this->assertTrue(di::get(setup::class)->validate_wwwroot()); } /** * Data provider for test_wwwroot_ends_in_slash. * * @return \Generator */ public static function wwwroot_validity_provider(): \Generator { foreach (['https', 'http'] as $protocol) { yield "Valid {$protocol} wwwroot on root domain" => [ "{$protocol}://example.com", true, ]; yield "Valid {$protocol} wwwroot on sub domain" => [ "{$protocol}://moodle.example.com", true, ]; yield "Valid {$protocol} wwwroot on directory" => [ "{$protocol}://example.com/moodle", true, ]; } yield "Root domain ends in slash" => [ "https://example.com/", false, get_string('wwwrootslash', 'error'), ]; yield "Sub domain ends in slash" => [ "https://moodle.example.com/", false, get_string('wwwrootslash', 'error'), ]; yield "Directory ends in slash" => [ "https://example.com/moodle/", false, get_string('wwwrootslash', 'error'), ]; yield "Directory ends in public and should not" => [ "https://example.com/public", false, get_string('wwwrootpublic', 'error'), ]; } }