/
githubmirror
/
joomla-cms
Обзор
Документация
Войти
/
githubmirror
/
joomla-cms
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
5.4-dev
tests/Unit/Libraries/Cms/Form/Rule/UrlRuleTest.php
94 строки
3 KB
Richard Fath
Joomla! 5.4.3 Release Candidate 1
06 фев 2026, 20:27
06 фев 2026, 20:27
09d26dc
Код
Авторство
О чём код?
<?php /** * @package Joomla.UnitTest * @subpackage Form * * @copyright (C) 2026 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Tests\Unit\Libraries\Cms\Form\Rule; use Joomla\CMS\Form\Rule\UrlRule; use Joomla\Tests\Unit\UnitTestCase; /** * Test class for UrlRule. * * @since 5.4.3 */ class UrlRuleTest extends UnitTestCase { /** * Test data for the testRule method * * @return array * * @since 5.4.3 */ public function dataTest(): array { $xml = new \SimpleXMLElement('<field name="unittest" type="text" validate="url" required="true" />'); $xmlschemes = new \SimpleXMLElement('<field name="unittest" type="text" validate="url" required="true" schemes="http,https" />'); $xmlrelative = new \SimpleXMLElement('<field name="unittest" type="text" validate="url" required="true" relative="true" />'); return [ [true, $xml, 'https://example.com'], [true, $xml, 'https://example.com/test'], [true, $xml, 'https://example.com:8080'], [true, $xml, 'ftp://example.com/resource'], [true, $xml, 'mailto:test@example.com'], [true, $xml, 'tel:+49123456789'], [true, $xml, 'file:///etc/passwd'], [true, $xml, 'gopher://example.com'], [true, $xmlschemes, 'https://example.com'], [true, $xmlrelative, 'https://example.com'], [true, $xmlrelative, '/relative/path'], [false, $xml, ''], [false, $xml, 'invalid://example.com'], [false, $xml, 'example.com'], [false, $xml, '/relative/path'], [false, $xml, 'http:///example.com'], [false, $xml, 'http:example.com'], [false, $xml, "https://exa\x80mple.com"], [false, $xml, "https://example.com/pa\x80th"], [false, $xml, 'https://example.com:0'], [false, $xmlschemes, 'ftp://example.com'], ]; } /** * Tests the UrlRule::test method. * * @param bool $expected The expected test result * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object. * @param string $value The form field value to validate. * * @return void * * @since 5.4.3 * @dataProvider dataTest */ public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void { $this->assertEquals($expected, (new UrlRule())->test(clone $element, $value)); } }