Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions tests/Unit/Libraries/Cms/Form/Rule/BooleanRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\BooleanRule;
use Joomla\Tests\Unit\UnitTestCase;

/**
* Test class for BooleanRule.
*
* @since __DEPLOY_VERSION__
*/
class BooleanRuleTest extends UnitTestCase
{
/**
* Test data for the testRule method
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function dataTest(): array
{
$xml = new \SimpleXMLElement('<field
name="unittest"
type="text"
validate="boolean"
/>');

return [
[true, $xml, 'true'],
[true, $xml, 'false'],
[true, $xml, '0'],
[true, $xml, '1'],
[true, $xml, 'TRUE'],
[true, $xml, 'FALSE'],
[true, $xml, 'True'],
[true, $xml, 'False'],
[false, $xml, ''],
[false, $xml, 'tu re'],
[false, $xml, 'false1'],
[false, $xml, 'none'],
];
}

/**
* Tests the BooleanRule::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 __DEPLOY_VERSION__
* @dataProvider dataTest
*/
public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void
{
$this->assertEquals($expected, (new BooleanRule())->test($element, $value));
}
}
69 changes: 69 additions & 0 deletions tests/Unit/Libraries/Cms/Form/Rule/CalendarRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\CalendarRule;
use Joomla\Tests\Unit\UnitTestCase;

/**
* Test class for CalendarRule.
*
* @since __DEPLOY_VERSION__
*/
class CalendarRuleTest extends UnitTestCase
{
/**
* Test data for the testRule method
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function dataTest(): array
{
$xml = new \SimpleXMLElement('<field
name="unittest"
type="text"
validate="calendar"
/>');

return [
[true, $xml, ''],
[true, $xml, 'now'],
[true, $xml, 'NOW'],
[true, $xml, 'Now'],
[true, $xml, '2026-05-01'],
[true, $xml, '2026-05-01 00:00:00'],
[true, $xml, '2028-10-13 14:15:16'],
[false, $xml, 'test'],
[false, $xml, '2026-05-01 12:65:00'],
[false, $xml, '2026-05-01 26:30:00'],
[false, $xml, '2026-13-01'],
];
}

/**
* Tests the CalendarRule::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 __DEPLOY_VERSION__
* @dataProvider dataTest
*/
public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void
{
$this->assertEquals($expected, (new CalendarRule())->test($element, $value));
}
}
72 changes: 72 additions & 0 deletions tests/Unit/Libraries/Cms/Form/Rule/ColorRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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\ColorRule;
use Joomla\Tests\Unit\UnitTestCase;

/**
* Test class for ColorRule.
*
* @since __DEPLOY_VERSION__
*/
class ColorRuleTest extends UnitTestCase
{
/**
* Test data for the testRule method
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function dataTest(): array
{
$xml = new \SimpleXMLElement('<field
name="unittest"
type="text"
validate="color"
/>');

return [
[true, $xml, ''],
[true, $xml, '#000000'],
[true, $xml, '#FFFFFF'],
[true, $xml, '#FF0000'],
[true, $xml, '#00FF00'],
[true, $xml, '#0000ff'],
[true, $xml, '#c0a'],
[true, $xml, '#4FF'],
[false, $xml, 'test'],
[false, $xml, '451'],
[false, $xml, '123456'],
[false, $xml, '#12345G'],
[false, $xml, '#4H0'],
[false, $xml, '#FFFF'],
];
}

/**
* Tests the ColorRule::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 __DEPLOY_VERSION__
* @dataProvider dataTest
*/
public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void
{
$this->assertEquals($expected, (new ColorRule())->test($element, $value));
}
}
73 changes: 73 additions & 0 deletions tests/Unit/Libraries/Cms/Form/Rule/CssIdentifierRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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\CssIdentifierRule;
use Joomla\Tests\Unit\UnitTestCase;

/**
* Test class for CssIdentifierRule.
*
* @since __DEPLOY_VERSION__
*/
class CssIdentifierRuleTest extends UnitTestCase
{
/**
* Test data for the testRule method
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function dataTest(): array
{
$xml = new \SimpleXMLElement('<field
name="unittest"
type="text"
validate="cssidentifier"
/>');

return [
[true, $xml, ''],
[true, $xml, 'header'],
[true, $xml, 'main-content'],
[true, $xml, 'footer'],
[true, $xml, '-sidebar'],
[true, $xml, 'navigation'],
[true, $xml, 'hero-section'],
[true, $xml, 'login-form2'],
[true, $xml, 'user_profile'],
[true, $xml, '@search-box'],
[true, $xml, 'contact-form table'],
[false, $xml, '2footer'],
[false, $xml, '-5navigation'],
[false, $xml, '--header'],
[false, $xml, 'main-content!'],
];
}

/**
* Tests the CssIdentifierRule::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 __DEPLOY_VERSION__
* @dataProvider dataTest
*/
public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void
{
$this->assertEquals($expected, (new CssIdentifierRule())->test($element, $value));
}
}
80 changes: 80 additions & 0 deletions tests/Unit/Libraries/Cms/Form/Rule/EmailRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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\EmailRule;
use Joomla\Tests\Unit\UnitTestCase;

/**
* Test class for EmailRule.
*
* @since __DEPLOY_VERSION__
*/
class EmailRuleTest extends UnitTestCase
{
/**
* Test data for the testRule method
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function dataTest(): array
{
$xml = new \SimpleXMLElement('<field
name="unittest"
type="text"
validate="email"
/>');

return [
[true, $xml, '[email protected]'],
[true, $xml, 'user@example'],
[true, $xml, '[email protected]'],
[true, $xml, '[email protected]'],
[true, $xml, '[email protected]'],
[true, $xml, 'special.chars!#$%&\'*+/=?^_{|}[email protected]'],
[true, $xml, '[email protected]'],
[false, $xml, 'userexample.com'],
[false, $xml, '@example.com'],
[false, $xml, 'user@'],
[false, $xml, '[email protected]'],
[false, $xml, '[email protected]'],
[false, $xml, 'user@@example.com'],
[false, $xml, 'user@ex!ample.com'],
[false, $xml, 'user@exam_ple.com'],
[false, $xml, '[email protected].'],
[false, $xml, 'user [email protected]'],
];
}

/**
* Tests the EmailRule::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 __DEPLOY_VERSION__
* @dataProvider dataTest
*/
public function testRule(bool $expected, \SimpleXMLElement $element, string $value): void
{
if ($expected) {
$this->assertTrue((new EmailRule())->test($element, $value));
} else {
$this->expectException(\UnexpectedValueException::class);
(new EmailRule())->test($element, $value);
}
}
}
Loading