Subir proyecto
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
use RockLobsterInc\Swv\Rules\{AllRule, RequiredRule};
|
||||
|
||||
final class AllRuleTest extends TestCase
|
||||
{
|
||||
public function testValidity(): void
|
||||
{
|
||||
$rule = new AllRule();
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-1",
|
||||
"error" => "Error in field-1.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-2",
|
||||
"error" => "Error in field-2.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-3",
|
||||
"error" => "Error in field-3.",
|
||||
]),
|
||||
);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"field-1" => "1",
|
||||
"field-2" => "1",
|
||||
"field-3" => "1",
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data, ["text" => true]);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testInvalidity(): void
|
||||
{
|
||||
$rule = new AllRule();
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-1",
|
||||
"error" => "Error in field-1.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-2",
|
||||
"error" => "Error in field-2.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-3",
|
||||
"error" => "Error in field-3.",
|
||||
]),
|
||||
);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"field-1" => "1",
|
||||
"field-2" => "",
|
||||
"field-3" => "1",
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Error in field-2.");
|
||||
|
||||
$rule->validate($form_data, ["text" => true]);
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
use RockLobsterInc\Swv\Rules\{AnyRule, RequiredRule};
|
||||
|
||||
final class AnyRuleTest extends TestCase
|
||||
{
|
||||
public function testValidity(): void
|
||||
{
|
||||
$rule = new AnyRule();
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-1",
|
||||
"error" => "Error in field-1.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-2",
|
||||
"error" => "Error in field-2.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-3",
|
||||
"error" => "Error in field-3.",
|
||||
]),
|
||||
);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"field-1" => "",
|
||||
"field-2" => "1",
|
||||
"field-3" => "",
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data, ["text" => true]);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testInvalidity(): void
|
||||
{
|
||||
$rule = new AnyRule([
|
||||
"field" => "field-3",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-1",
|
||||
"error" => "Error in field-1.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-2",
|
||||
"error" => "Error in field-2.",
|
||||
]),
|
||||
);
|
||||
|
||||
$rule->addRule(
|
||||
new RequiredRule([
|
||||
"field" => "field-3",
|
||||
"error" => "Error in field-3.",
|
||||
]),
|
||||
);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"field-1" => "",
|
||||
"field-2" => "",
|
||||
"field-3" => "",
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data, ["text" => true]);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class DateRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\DateRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"valid" => ["2026-07-26"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid date"],
|
||||
"non-bissextile" => ["2026-02-29"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class DayofweekRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\DayofweekRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", [1, 3, 5]],
|
||||
"non-date" => ["Monday", [1, 3, 5]],
|
||||
"valid" => ["2026-07-27", [1, 3, 5]],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["2026-07-26", [1, 3, 5]],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class EmailRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\EmailRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"valid" => ["testing@example.com"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid email"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class EnumRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\EnumRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", ["a", "b", "c"]],
|
||||
"valid" => ["c", ["a", "b", "c"]],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["z", ["a", "b", "c"]],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class FileRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\FileRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"blank" => [null, ["image/png"]],
|
||||
"valid" => [$file, ["image/png"]],
|
||||
"wildcard" => [$file, ["image/*"]],
|
||||
"extension" => [$file, [".png"]],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"invalid" => [$file, ["image/jpeg"]],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $accept): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"accept" => $accept,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MaxDateRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MaxDateRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", "2026-07-28"],
|
||||
"non-date" => ["xxx", "2026-07-28"],
|
||||
"valid" => ["2026-07-28", "2026-07-28"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["2026-07-29", "2026-07-28"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MaxFilesizeRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MaxFilesizeRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"blank" => [null, 1000],
|
||||
"valid" => [$file, 1000],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"invalid" => [$file, 999],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MaxItemsRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MaxItemsRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [[], 3],
|
||||
"valid" => [["a", "b", "c"], 3],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => [["a", "b", "c", "d"], 3],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MaxLengthRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MaxLengthRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", 6],
|
||||
"valid" => ["abc一二三", 6],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["abc一二🥺", 6],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MaxNumberRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MaxNumberRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", 12],
|
||||
"non-number" => ["xxx", 12],
|
||||
"valid" => ["12.0", 12],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["12.01", 12],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MinDateRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MinDateRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", "2026-07-28"],
|
||||
"non-date" => ["xxx", "2026-07-28"],
|
||||
"valid" => ["2026-07-28", "2026-07-28"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["2026-07-27", "2026-07-28"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MinFilesizeRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MinFilesizeRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"blank" => [null, 1000],
|
||||
"valid" => [$file, 1000],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"invalid" => [$file, 1001],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MinItemsRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MinItemsRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [[], 3],
|
||||
"valid" => [["a", "b", "c"], 3],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => [["a", "b"], 3],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MinLengthRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MinLengthRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", 6],
|
||||
"valid" => ["abc一二三", 6],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["abc一二", 6],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class MinNumberRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\MinNumberRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", 12],
|
||||
"non-number" => ["xxx", 12],
|
||||
"valid" => ["12.0", 12],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["11.99", 12],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $threshold): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"threshold" => $threshold,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class NumberRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\NumberRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"integer" => ["12345"],
|
||||
"decimal" => ["0.12345"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid number"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class RequiredFileRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\RequiredFileRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
$file = new FileMock([
|
||||
"name" => "example.png",
|
||||
"size" => 1000,
|
||||
"temporaryFilePath" => "/temporary/file/path/example.png",
|
||||
"error" => UPLOAD_ERR_OK,
|
||||
]);
|
||||
|
||||
return [
|
||||
"has-value" => [$file],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [null],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"files" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class RequiredRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\RequiredRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"has-value" => ["some text"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class StepNumberRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\StepNumberRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => ["", 1.3, 3],
|
||||
"non-number" => ["xxx", 1.3, 3],
|
||||
"valid" => ["10.3", 1.3, 3],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["11.3", 1.3, 3],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value, $base, $interval): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"base" => $base,
|
||||
"interval" => $interval,
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value, $base, $interval): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"base" => $base,
|
||||
"interval" => $interval,
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class TelRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\TelRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"valid" => ["1234567"],
|
||||
"country-coded" => ["+81 1234567"],
|
||||
"with-extension" => ["1234567#abcdef"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid tel"],
|
||||
"too-long" => ["1234567890123456"],
|
||||
"too-short" => ["12345"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class TimeRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\TimeRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"valid" => ["16:08:12"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid time"],
|
||||
"non-time" => ["24:60:60"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use RockLobsterInc\FormDataTree\FormDataTree;
|
||||
use RockLobsterInc\Swv\InvalidityException;
|
||||
|
||||
final class UrlRuleTest extends TestCase
|
||||
{
|
||||
public static string $ruleClass = "\RockLobsterInc\Swv\Rules\UrlRule";
|
||||
|
||||
public static function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"blank" => [""],
|
||||
"valid" => ["http://example.com/example"],
|
||||
];
|
||||
}
|
||||
|
||||
public static function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
"invalid" => ["invalid url"],
|
||||
"telnet" => ["telnet://203.0.113.0"],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider("validValueProvider")]
|
||||
public function testValidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $rule->validate($form_data);
|
||||
} catch (InvalidityException $error) {
|
||||
}
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
#[DataProvider("invalidValueProvider")]
|
||||
public function testInvalidity($field_value): void
|
||||
{
|
||||
$rule = new self::$ruleClass([
|
||||
"field" => "the-field-name",
|
||||
"error" => "Just another error message.",
|
||||
]);
|
||||
|
||||
$form_data = new FormDataTree([
|
||||
"post" => [
|
||||
"the-field-name" => $field_value,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvalidityException::class);
|
||||
$this->expectExceptionMessage("Just another error message.");
|
||||
|
||||
$rule->validate($form_data);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
use RockLobsterInc\FormDataTree\FileInterface;
|
||||
|
||||
class FileMock implements FileInterface
|
||||
{
|
||||
private string $name;
|
||||
private int $size;
|
||||
private string $temporaryFilePath;
|
||||
private int $error;
|
||||
|
||||
public function __construct(array $properties = [])
|
||||
{
|
||||
$this->name = $properties["name"];
|
||||
$this->size = $properties["size"];
|
||||
$this->temporaryFilePath = $properties["temporaryFilePath"];
|
||||
$this->error = $properties["error"];
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function size(): int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function temporaryFilePath(): string
|
||||
{
|
||||
return $this->temporaryFilePath;
|
||||
}
|
||||
|
||||
public function error(): int
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user