From a2955c6382493a23dc784f4def62895650b489e0 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 21 Oct 2025 10:47:52 +0100
Subject: [PATCH] chore: remove validators
---
README.md | 10 +-
composer.json | 3 +-
composer.lock | 75 ++++++++++---
docs/Getting-Starting-Guide.md | 3 +-
example/src/server.php | 2 +-
phpunit.xml | 1 -
src/Http/Validator.php | 22 ----
src/Http/Validator/AllOf.php | 86 --------------
src/Http/Validator/AnyOf.php | 99 ----------------
src/Http/Validator/ArrayList.php | 120 --------------------
src/Http/Validator/Assoc.php | 88 ---------------
src/Http/Validator/Boolean.php | 94 ----------------
src/Http/Validator/Domain.php | 136 ----------------------
src/Http/Validator/FloatValidator.php | 88 ---------------
src/Http/Validator/HexColor.php | 53 ---------
src/Http/Validator/Host.php | 82 --------------
src/Http/Validator/Hostname.php | 114 -------------------
src/Http/Validator/IP.php | 113 -------------------
src/Http/Validator/Integer.php | 88 ---------------
src/Http/Validator/JSON.php | 59 ----------
src/Http/Validator/Multiple.php | 115 -------------------
src/Http/Validator/NoneOf.php | 88 ---------------
src/Http/Validator/Nullable.php | 73 ------------
src/Http/Validator/Numeric.php | 66 -----------
src/Http/Validator/Range.php | 149 -------------------------
src/Http/Validator/Text.php | 138 -----------------------
src/Http/Validator/URL.php | 86 --------------
src/Http/Validator/WhiteList.php | 119 --------------------
src/Http/Validator/Wildcard.php | 62 ----------
tests/HookTest.php | 4 +-
tests/HttpTest.php | 2 +-
tests/RouteTest.php | 2 +-
tests/Validator/ArrayListTest.php | 52 ---------
tests/Validator/AssocTest.php | 43 -------
tests/Validator/BooleanTest.php | 46 --------
tests/Validator/DomainTest.php | 86 --------------
tests/Validator/FloatValidatorTest.php | 39 -------
tests/Validator/HexColorTest.php | 26 -----
tests/Validator/HostTest.php | 42 -------
tests/Validator/HostnameTest.php | 106 ------------------
tests/Validator/IPTest.php | 78 -------------
tests/Validator/IntegerTest.php | 36 ------
tests/Validator/JSONTest.php | 28 -----
tests/Validator/MultipleOfTest.php | 65 -----------
tests/Validator/NullableTest.php | 22 ----
tests/Validator/NumericTest.php | 24 ----
tests/Validator/RangeTest.php | 60 ----------
tests/Validator/TextTest.php | 88 ---------------
tests/Validator/URLTest.php | 55 ---------
tests/Validator/WhiteListTest.php | 58 ----------
tests/Validator/WildcardTest.php | 21 ----
tests/e2e/init.php | 2 +-
52 files changed, 75 insertions(+), 3142 deletions(-)
delete mode 100755 src/Http/Validator.php
delete mode 100644 src/Http/Validator/AllOf.php
delete mode 100644 src/Http/Validator/AnyOf.php
delete mode 100644 src/Http/Validator/ArrayList.php
delete mode 100644 src/Http/Validator/Assoc.php
delete mode 100644 src/Http/Validator/Boolean.php
delete mode 100644 src/Http/Validator/Domain.php
delete mode 100755 src/Http/Validator/FloatValidator.php
delete mode 100644 src/Http/Validator/HexColor.php
delete mode 100755 src/Http/Validator/Host.php
delete mode 100644 src/Http/Validator/Hostname.php
delete mode 100644 src/Http/Validator/IP.php
delete mode 100755 src/Http/Validator/Integer.php
delete mode 100644 src/Http/Validator/JSON.php
delete mode 100644 src/Http/Validator/Multiple.php
delete mode 100644 src/Http/Validator/NoneOf.php
delete mode 100644 src/Http/Validator/Nullable.php
delete mode 100755 src/Http/Validator/Numeric.php
delete mode 100755 src/Http/Validator/Range.php
delete mode 100644 src/Http/Validator/Text.php
delete mode 100644 src/Http/Validator/URL.php
delete mode 100755 src/Http/Validator/WhiteList.php
delete mode 100644 src/Http/Validator/Wildcard.php
delete mode 100755 tests/Validator/ArrayListTest.php
delete mode 100755 tests/Validator/AssocTest.php
delete mode 100755 tests/Validator/BooleanTest.php
delete mode 100644 tests/Validator/DomainTest.php
delete mode 100755 tests/Validator/FloatValidatorTest.php
delete mode 100755 tests/Validator/HexColorTest.php
delete mode 100644 tests/Validator/HostTest.php
delete mode 100755 tests/Validator/HostnameTest.php
delete mode 100644 tests/Validator/IPTest.php
delete mode 100755 tests/Validator/IntegerTest.php
delete mode 100755 tests/Validator/JSONTest.php
delete mode 100644 tests/Validator/MultipleOfTest.php
delete mode 100755 tests/Validator/NullableTest.php
delete mode 100755 tests/Validator/NumericTest.php
delete mode 100755 tests/Validator/RangeTest.php
delete mode 100755 tests/Validator/TextTest.php
delete mode 100644 tests/Validator/URLTest.php
delete mode 100755 tests/Validator/WhiteListTest.php
delete mode 100644 tests/Validator/WildcardTest.php
diff --git a/README.md b/README.md
index 9487d581..116ce14b 100644
--- a/README.md
+++ b/README.md
@@ -42,9 +42,9 @@ $user
->setCallback(fn (Request $request) => $request->getHeader('x-user-id', 'John Doe'));
$container->set($user);
-
-// Defining Route
-Http::get('/hello-world')
+
+// Defining Route
+Http::get('/hello-world')
->inject('request') // Auto-injected each request
->inject('response') // Auto-injected each request
->inject('user')
@@ -67,7 +67,7 @@ $http->start();
Run HTTP server:
```bash
-php -S localhost:8000 src/server.php
+php -S localhost:8000 src/server.php
```
Send HTTP request:
@@ -130,7 +130,7 @@ $http->start();
Parameters are used to receive input into endpoint action from the HTTP request. Parameters could be defined as URL parameters or in a body with a structure such as JSON.
-Every parameter must have a validator defined. Validators are simple classes that verify the input and ensure the security of inputs. You can define your own validators or use some of [built-in validators](/src/Http/Validator).
+Every parameter must have a validator defined. Validators are simple classes that verify the input and ensure the security of inputs. You can define your own validators or use some of [built-in validators](https://github.com/utopia-php/validators).
Define an endpoint with params:
diff --git a/composer.json b/composer.json
index 1055fc31..3d44c94b 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,8 @@
"require": {
"php": ">=8.1",
"ext-swoole": "*",
- "utopia-php/servers": "0.1.*",
+ "utopia-php/servers": "0.2.*",
+ "utopia-php/validators": "0.0.*",
"utopia-php/compression": "0.1.*",
"utopia-php/telemetry": "0.1.*"
},
diff --git a/composer.lock b/composer.lock
index bb426596..d02255f2 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "11b6587ef7f59f67e889d3869763a726",
+ "content-hash": "3f80c15a17f2b7b72066d37d3aee2dd6",
"packages": [
{
"name": "brick/math",
@@ -145,16 +145,16 @@
},
{
"name": "google/protobuf",
- "version": "v4.32.1",
+ "version": "v4.33.0",
"source": {
"type": "git",
"url": "https://github.com/protocolbuffers/protobuf-php.git",
- "reference": "c4ed1c1f9bbc1e91766e2cd6c0af749324fe87cb"
+ "reference": "b50269e23204e5ae859a326ec3d90f09efe3047d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/c4ed1c1f9bbc1e91766e2cd6c0af749324fe87cb",
- "reference": "c4ed1c1f9bbc1e91766e2cd6c0af749324fe87cb",
+ "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/b50269e23204e5ae859a326ec3d90f09efe3047d",
+ "reference": "b50269e23204e5ae859a326ec3d90f09efe3047d",
"shasum": ""
},
"require": {
@@ -183,9 +183,9 @@
"proto"
],
"support": {
- "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.32.1"
+ "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.33.0"
},
- "time": "2025-09-14T05:14:52+00:00"
+ "time": "2025-10-15T20:10:28+00:00"
},
{
"name": "nyholm/psr7",
@@ -1958,21 +1958,22 @@
},
{
"name": "utopia-php/servers",
- "version": "0.1.1",
+ "version": "0.2.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/servers.git",
- "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a"
+ "reference": "c6ec23b0597f657020a75d4a2f8ef03177d7edaa"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/utopia-php/servers/zipball/fd5c8d32778f265256c1936372a071b944f5ba8a",
- "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a",
+ "url": "https://api.github.com/repos/utopia-php/servers/zipball/c6ec23b0597f657020a75d4a2f8ef03177d7edaa",
+ "reference": "c6ec23b0597f657020a75d4a2f8ef03177d7edaa",
"shasum": ""
},
"require": {
"php": ">=8.0",
- "utopia-php/di": "0.1.*"
+ "utopia-php/di": "0.1.*",
+ "utopia-php/validators": "0.0.*"
},
"require-dev": {
"laravel/pint": "^0.2.3",
@@ -2005,9 +2006,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/servers/issues",
- "source": "https://github.com/utopia-php/servers/tree/0.1.1"
+ "source": "https://github.com/utopia-php/servers/tree/0.2.1"
},
- "time": "2024-09-06T02:25:56+00:00"
+ "time": "2025-10-21T10:08:19+00:00"
},
{
"name": "utopia-php/telemetry",
@@ -2058,6 +2059,52 @@
"source": "https://github.com/utopia-php/telemetry/tree/0.1.1"
},
"time": "2025-03-17T11:57:52+00:00"
+ },
+ {
+ "name": "utopia-php/validators",
+ "version": "0.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/utopia-php/validators.git",
+ "reference": "894210695c5d35fa248fb65f7fe7237b6ff4fb0b"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/utopia-php/validators/zipball/894210695c5d35fa248fb65f7fe7237b6ff4fb0b",
+ "reference": "894210695c5d35fa248fb65f7fe7237b6ff4fb0b",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=8.1"
+ },
+ "require-dev": {
+ "ext-xdebug": "*",
+ "laravel/pint": "^1.2",
+ "phpstan/phpstan": "1.*",
+ "phpunit/phpunit": "^9.5.25"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Utopia\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "A lightweight collection of reusable validators for Utopia projects",
+ "keywords": [
+ "php",
+ "utopia",
+ "validation",
+ "validator"
+ ],
+ "support": {
+ "issues": "https://github.com/utopia-php/validators/issues",
+ "source": "https://github.com/utopia-php/validators/tree/0.0.2"
+ },
+ "time": "2025-10-20T21:52:28+00:00"
}
],
"packages-dev": [
diff --git a/docs/Getting-Starting-Guide.md b/docs/Getting-Starting-Guide.md
index b0f46a4b..4dbb9933 100644
--- a/docs/Getting-Starting-Guide.md
+++ b/docs/Getting-Starting-Guide.md
@@ -144,7 +144,7 @@ use Utopia\Http\Swoole\Response;
use Swoole\Http\Server;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;
-use Utopia\Http\Validator\Wildcard;
+use Utopia\Validator\Wildcard;
$http = new Server("0.0.0.0", 8080);
@@ -284,4 +284,3 @@ If you have PHP and Composer installed on your device, you can run Utopia apps l
> Utopia HTTP requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.
Wonderful! 😄 You’re all set to create a basic demo app using the Utopia HTTP. If you have any issues or questions feel free to reach out to us on our [Discord Server](https://appwrite.io/discord).
-
diff --git a/example/src/server.php b/example/src/server.php
index 0697870a..813d650a 100644
--- a/example/src/server.php
+++ b/example/src/server.php
@@ -7,7 +7,7 @@
use Utopia\Http\Http;
use Utopia\Http\Response;
use Utopia\Http\Adapter\Swoole\Server;
-use Utopia\Http\Validator\Text;
+use Utopia\Validator\Text;
class User
{
diff --git a/phpunit.xml b/phpunit.xml
index c7210e5e..365b1a57 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -20,7 +20,6 @@
./tests/RouterTest.php
./tests/RouteTest.php
./tests/UtopiaFPMRequestTest.php
- ./tests/Validator/
./tests/e2e/Client.php
diff --git a/src/Http/Validator.php b/src/Http/Validator.php
deleted file mode 100755
index f75b1550..00000000
--- a/src/Http/Validator.php
+++ /dev/null
@@ -1,22 +0,0 @@
- $validators
- */
- public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED)
- {
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- if (!(\is_null($this->failedRule))) {
- $description = $this->failedRule->getDescription();
- } else {
- $description = $this->validators[0]->getDescription();
- }
-
- return $description;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- foreach ($this->validators as $rule) {
- $valid = $rule->isValid($value);
-
- if (!$valid) {
- $this->failedRule = $rule;
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-}
diff --git a/src/Http/Validator/AnyOf.php b/src/Http/Validator/AnyOf.php
deleted file mode 100644
index 7d760a0b..00000000
--- a/src/Http/Validator/AnyOf.php
+++ /dev/null
@@ -1,99 +0,0 @@
- $validators
- */
- public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED)
- {
- }
-
- /**
- * Get Validators
- *
- * Returns validators array
- *
- * @return array
- */
- public function getValidators(): array
- {
- return $this->validators;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- if (!(\is_null($this->failedRule))) {
- $description = $this->failedRule->getDescription();
- } else {
- $description = $this->validators[0]->getDescription();
- }
-
- return $description;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- foreach ($this->validators as $rule) {
- $valid = $rule->isValid($value);
-
- $this->failedRule = $rule;
-
- if ($valid) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-}
diff --git a/src/Http/Validator/ArrayList.php b/src/Http/Validator/ArrayList.php
deleted file mode 100644
index 599859e7..00000000
--- a/src/Http/Validator/ArrayList.php
+++ /dev/null
@@ -1,120 +0,0 @@
-validator = $validator;
- $this->length = $length;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- $msg = 'Value must a valid array';
-
- if ($this->length > 0) {
- $msg .= ' no longer than ' . $this->length . ' items';
- }
-
- if (!empty($this->validator->getDescription())) {
- $msg .= ' and ' . $this->validator->getDescription();
- }
-
- return $msg;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->validator->getType();
- }
-
- /**
- * Get Nested Validator
- *
- * @return Validator
- */
- public function getValidator(): Validator
- {
- return $this->validator;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is valid array and validator is valid.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if (!\is_array($value)) {
- return false;
- }
-
- foreach ($value as $element) {
- if (!$this->validator->isValid($element)) {
- return false;
- }
- }
-
- if ($this->length && \count($value) > $this->length) {
- return false;
- }
-
- return true;
- }
-}
diff --git a/src/Http/Validator/Assoc.php b/src/Http/Validator/Assoc.php
deleted file mode 100644
index 9b7697e4..00000000
--- a/src/Http/Validator/Assoc.php
+++ /dev/null
@@ -1,88 +0,0 @@
-length = $length;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid object.';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_ARRAY;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is valid assoc array.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- if (!\is_array($value)) {
- return false;
- }
-
- $jsonString = \json_encode($value);
- $jsonStringSize = \strlen($jsonString);
-
- if ($jsonStringSize > $this->length) {
- return false;
- }
-
- return \array_keys($value) !== \range(0, \count($value) - 1);
- }
-}
diff --git a/src/Http/Validator/Boolean.php b/src/Http/Validator/Boolean.php
deleted file mode 100644
index 38b498ec..00000000
--- a/src/Http/Validator/Boolean.php
+++ /dev/null
@@ -1,94 +0,0 @@
-loose = $loose;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid boolean';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_BOOLEAN;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value has a boolean value.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- if ($this->loose && ($value === 'true' || $value === 'false')) { // Accept strings
- return true;
- }
-
- if ($this->loose && ($value === '1' || $value === '0')) { // Accept numeric strings
- return true;
- }
-
- if ($this->loose && ($value === 1 || $value === 0)) { // Accept integers
- return true;
- }
-
- if (\is_bool($value)) {
- return true;
- }
-
- return false;
- }
-}
diff --git a/src/Http/Validator/Domain.php b/src/Http/Validator/Domain.php
deleted file mode 100644
index 5c3fe907..00000000
--- a/src/Http/Validator/Domain.php
+++ /dev/null
@@ -1,136 +0,0 @@
- $prefixDenyList Disallowed beginning of domain, useful for reserved behaviours, such as prefixing "branch-" for preview domains
- *
- */
- public static function createRestriction(string $hostname, ?int $levels = null, array $prefixDenyList = [])
- {
- return [
- 'hostname' => $hostname,
- 'levels' => $levels,
- 'prefixDenyList' => $prefixDenyList,
- ];
- }
-
- /**
- * @param array $restrictions Set of conditions that prevent validation from passing
- */
- public function __construct(protected array $restrictions = [])
- {
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid domain';
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is valid domain.
- *
- * Validates domain names against RFC 1034, RFC 1035, RFC 952, RFC 1123, RFC 2732, RFC 2181, and RFC 1123.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- if (empty($value)) {
- return false;
- }
-
- if (!is_string($value)) {
- return false;
- }
-
- if (\filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) {
- return false;
- }
-
- if (\str_ends_with($value, '.') || \str_ends_with($value, '-')) {
- return false;
- }
-
- foreach ($this->restrictions as $restriction) {
- $hostname = $restriction['hostname'];
- $levels = $restriction['levels'];
- $prefixDenyList = $restriction['prefixDenyList'];
-
- // Only apply restriction rules to relevant domains
- if (!\str_ends_with($value, $hostname)) {
- continue;
- }
-
- // Domain-level restriction
- if (!is_null($levels)) {
- $expectedPartsCount = $levels;
- $partsCount = \count(\explode('.', $value, $expectedPartsCount + 1));
- if ($partsCount !== $expectedPartsCount) {
- return false;
- }
- }
-
- // Domain prefix (beginning) restriction
- if (!empty($prefixDenyList)) {
- foreach ($prefixDenyList as $deniedPrefix) {
- if (\str_starts_with($value, $deniedPrefix)) {
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-}
diff --git a/src/Http/Validator/FloatValidator.php b/src/Http/Validator/FloatValidator.php
deleted file mode 100755
index 23d27ef0..00000000
--- a/src/Http/Validator/FloatValidator.php
+++ /dev/null
@@ -1,88 +0,0 @@
-loose = $loose;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid float';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_FLOAT;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is float.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if ($this->loose) {
- if (!\is_numeric($value)) {
- return false;
- }
- $value = $value + 0;
- }
- if (!\is_float($value) && !\is_int($value)) {
- return false;
- }
-
- return true;
- }
-}
diff --git a/src/Http/Validator/HexColor.php b/src/Http/Validator/HexColor.php
deleted file mode 100644
index fe9d5926..00000000
--- a/src/Http/Validator/HexColor.php
+++ /dev/null
@@ -1,53 +0,0 @@
-whitelist = $whitelist;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'URL host must be one of: ' . \implode(', ', $this->whitelist);
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value starts with one of the given hosts
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- $urlValidator = new URL();
-
- if (!$urlValidator->isValid($value)) {
- return false;
- }
-
- $hostnameValidator = new Hostname($this->whitelist);
-
- return $hostnameValidator->isValid(\parse_url($value, PHP_URL_HOST));
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-}
diff --git a/src/Http/Validator/Hostname.php b/src/Http/Validator/Hostname.php
deleted file mode 100644
index d3231f10..00000000
--- a/src/Http/Validator/Hostname.php
+++ /dev/null
@@ -1,114 +0,0 @@
-allowList = $allowList;
- }
-
- /**
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid hostname without path, port and protocol.';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-
- /**
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- // Validate proper format
- if (!\is_string($value) || empty($value)) {
- return false;
- }
-
- // Max length 253 chars: https://en.wikipedia.org/wiki/Hostname#:~:text=The%20entire%20hostname%2C%20including%20the,maximum%20of%20253%20ASCII%20characters
- if (\mb_strlen($value) > 253) {
- return false;
- }
-
- // This tests: 'http://', 'https://', and 'myapp.com/route'
- if (\str_contains($value, '/')) {
- return false;
- }
-
- // This tests for: 'myapp.com:3000'
- if (\str_contains($value, ':')) {
- return false;
- }
-
- // Logic #1: Empty allowList means everything is allowed
- if (empty($this->allowList)) {
- return true;
- }
-
- // Logic #2: Allow List not empty, there are rules to check
- // Loop through all allowed hostnames until match is found
- foreach ($this->allowList as $allowedHostname) {
- // If exact match; allow
- // If *, allow everything
- if ($value === $allowedHostname || $allowedHostname === '*') {
- return true;
- }
-
- // If wildcard symbol used
- if (\str_starts_with($allowedHostname, '*')) {
- // Remove starting * symbol before comparing
- $allowedHostname = substr($allowedHostname, 1);
-
- // If rest of hostname match; allow
- // Notice allowedHostname still includes starting dot. Root domain is NOT allowed by wildcard.
- if (\str_ends_with($value, $allowedHostname)) {
- return true;
- }
- }
- }
-
- // If finished loop above without result, match is not found
- return false;
- }
-}
diff --git a/src/Http/Validator/IP.php b/src/Http/Validator/IP.php
deleted file mode 100644
index 4bbe9d43..00000000
--- a/src/Http/Validator/IP.php
+++ /dev/null
@@ -1,113 +0,0 @@
-type = $type;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid IP address';
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is valid IP address.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- switch ($this->type) {
- case self::ALL:
- if (\filter_var($value, FILTER_VALIDATE_IP)) {
- return true;
- }
- break;
-
- case self::V4:
- if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
- return true;
- }
- break;
-
- case self::V6:
- if (\filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
- return true;
- }
- break;
-
- default:
- return false;
- }
-
- return false;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-}
diff --git a/src/Http/Validator/Integer.php b/src/Http/Validator/Integer.php
deleted file mode 100755
index 76af2aa4..00000000
--- a/src/Http/Validator/Integer.php
+++ /dev/null
@@ -1,88 +0,0 @@
-loose = $loose;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid integer';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_INTEGER;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is integer.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if ($this->loose) {
- if (!\is_numeric($value)) {
- return false;
- }
- $value = $value + 0;
- }
- if (!\is_int($value)) {
- return false;
- }
-
- return true;
- }
-}
diff --git a/src/Http/Validator/JSON.php b/src/Http/Validator/JSON.php
deleted file mode 100644
index 5bb734f6..00000000
--- a/src/Http/Validator/JSON.php
+++ /dev/null
@@ -1,59 +0,0 @@
-addRule($rule);
- }
-
- $this->type = $type;
- }
- /**
- * Add rule
- *
- * Add a new rule to the end of the rules containing array
- *
- * @param Validator $rule
- * @return $this
- */
- public function addRule(Validator $rule)
- {
- $this->rules[] = $rule;
-
- return $this;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- $description = '';
- foreach ($this->rules as $key => $rule) {
- $description .= ++$key . '. ' . $rule->getDescription() . " \n";
- }
-
- return $description;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- foreach ($this->rules as $rule) { /* @var $rule Validator */
- if (false === $rule->isValid($value)) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-}
diff --git a/src/Http/Validator/NoneOf.php b/src/Http/Validator/NoneOf.php
deleted file mode 100644
index c6348a62..00000000
--- a/src/Http/Validator/NoneOf.php
+++ /dev/null
@@ -1,88 +0,0 @@
- $validators
- */
- public function __construct(protected array $validators, protected string $type = self::TYPE_MIXED)
- {
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- $description = '';
-
- if (!(\is_null($this->failedRule))) {
- $description = $this->failedRule->getDescription();
- } else {
- $description = $this->validators[0]->getDescription();
- }
-
- return $description;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when all rules are valid if only one of the rules is invalid validation will fail.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- foreach ($this->validators as $rule) {
- $valid = $rule->isValid($value);
-
- if ($valid) {
- $this->failedRule = $rule;
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return true;
- }
-}
diff --git a/src/Http/Validator/Nullable.php b/src/Http/Validator/Nullable.php
deleted file mode 100644
index b6c0007b..00000000
--- a/src/Http/Validator/Nullable.php
+++ /dev/null
@@ -1,73 +0,0 @@
-validator->getDescription() . ' or null';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->validator->getType();
- }
-
- /**
- * @return Validator
- */
- public function getValidator(): Validator
- {
- return $this->validator;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is text with valid length.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if (\is_null($value)) {
- return true;
- }
-
- return $this->validator->isValid($value);
- }
-}
diff --git a/src/Http/Validator/Numeric.php b/src/Http/Validator/Numeric.php
deleted file mode 100755
index 13c88610..00000000
--- a/src/Http/Validator/Numeric.php
+++ /dev/null
@@ -1,66 +0,0 @@
-min = $min;
- $this->max = $max;
- $this->format = $format;
- }
-
- /**
- * Get Range Minimum Value
- *
- * @return int|float
- */
- public function getMin(): int|float
- {
- return $this->min;
- }
-
- /**
- * Get Range Maximum Value
- *
- * @return int|float
- */
- public function getMax(): int|float
- {
- return $this->max;
- }
-
- /**
- * Get Range Format
- *
- * @return string
- */
- public function getFormat(): string
- {
- return $this->format;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be a valid range between '.\number_format($this->min).' and '.\number_format($this->max);
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->format;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value number is bigger or equal than $min number and lower or equal than $max.
- * Not strict, considers any valid integer to be a valid float
- * Considers infinity to be a valid integer
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if (!parent::isValid($value)) {
- return false;
- }
-
- switch ($this->format) {
- case self::TYPE_INTEGER:
- // Accept infinity as an integer
- // Since gettype(INF) === TYPE_FLOAT
- if ($value === INF || $value === -INF) {
- break; // move to check if value is within range
- }
- $value = $value + 0;
- if (!is_int($value)) {
- return false;
- }
- break;
- case self::TYPE_FLOAT:
- if (!is_numeric($value)) {
- return false;
- }
- $value = $value + 0.0;
- break;
- default:
- return false;
- }
-
- if ($this->min <= $value && $this->max >= $value) {
- return true;
- }
-
- return false;
- }
-}
diff --git a/src/Http/Validator/Text.php b/src/Http/Validator/Text.php
deleted file mode 100644
index 4df5d7e4..00000000
--- a/src/Http/Validator/Text.php
+++ /dev/null
@@ -1,138 +0,0 @@
-length = $length;
- $this->min = $min;
- $this->allowList = $allowList;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- $message = 'Value must be a valid string';
-
- if ($this->min === $this->length) {
- $message .= ' and exactly '.$this->length.' chars';
- } else {
- if ($this->min) {
- $message .= ' and at least '.$this->min.' chars';
- }
-
- if ($this->length) {
- $message .= ' and no longer than '.$this->length.' chars';
- }
- }
-
- if ($this->allowList) {
- $message .= ' and only consist of \''.\implode(', ', $this->allowList).'\' chars';
- }
-
- return $message;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is text with valid length.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if (!\is_string($value)) {
- return false;
- }
-
- if (\mb_strlen($value) < $this->min) {
- return false;
- }
-
- if (\mb_strlen($value) > $this->length && $this->length !== 0) {
- return false;
- }
-
- if (\count($this->allowList) > 0) {
- foreach (\str_split($value) as $char) {
- if (!\in_array($char, $this->allowList)) {
- return false;
- }
- }
- }
-
- return true;
- }
-}
diff --git a/src/Http/Validator/URL.php b/src/Http/Validator/URL.php
deleted file mode 100644
index f6434e98..00000000
--- a/src/Http/Validator/URL.php
+++ /dev/null
@@ -1,86 +0,0 @@
-allowedSchemes = $allowedSchemes;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- if (!empty($this->allowedSchemes)) {
- return 'Value must be a valid URL with following schemes (' . \implode(', ', $this->allowedSchemes) . ')';
- }
-
- return 'Value must be a valid URL';
- }
-
- /**
- * Is valid
- *
- * Validation will pass when $value is valid URL.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid($value): bool
- {
- if (\filter_var($value, FILTER_VALIDATE_URL) === false) {
- return false;
- }
-
- if (!empty($this->allowedSchemes) && !\in_array(\parse_url($value, PHP_URL_SCHEME), $this->allowedSchemes)) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return self::TYPE_STRING;
- }
-}
diff --git a/src/Http/Validator/WhiteList.php b/src/Http/Validator/WhiteList.php
deleted file mode 100755
index 53a6bb16..00000000
--- a/src/Http/Validator/WhiteList.php
+++ /dev/null
@@ -1,119 +0,0 @@
-list = $list;
- $this->strict = $strict;
- $this->type = $type;
-
- if (!$this->strict) {
- foreach ($this->list as $key => &$value) {
- $this->list[$key] = \strtolower($value);
- }
- }
- }
-
- /**
- * Get List of All Allowed Values
- *
- * @return array
- */
- public function getList(): array
- {
- return $this->list;
- }
-
- /**
- * Get Description
- *
- * Returns validator description
- *
- * @return string
- */
- public function getDescription(): string
- {
- return 'Value must be one of ('.\implode(', ', $this->list).')';
- }
-
- /**
- * Is array
- *
- * Function will return true if object is array.
- *
- * @return bool
- */
- public function isArray(): bool
- {
- return false;
- }
-
- /**
- * Get Type
- *
- * Returns validator type.
- *
- * @return string
- */
- public function getType(): string
- {
- return $this->type;
- }
-
- /**
- * Is valid
- *
- * Validation will pass if $value is in the white list array.
- *
- * @param mixed $value
- * @return bool
- */
- public function isValid(mixed $value): bool
- {
- if (\is_array($value)) {
- return false;
- }
-
- $value = ($this->strict) ? $value : \strtolower($value);
-
- if (!\in_array($value, $this->list, $this->strict)) {
- return false;
- }
-
- return true;
- }
-}
diff --git a/src/Http/Validator/Wildcard.php b/src/Http/Validator/Wildcard.php
deleted file mode 100644
index 1e7314a8..00000000
--- a/src/Http/Validator/Wildcard.php
+++ /dev/null
@@ -1,62 +0,0 @@
-assertFalse($arrayList->isValid(['text']));
- $this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());
-
- $arrayList = new ArrayList(new Integer(), 3);
- $this->assertFalse($arrayList->isValid(['a', 'b', 'c', 'd']));
- $this->assertEquals('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription());
- }
-
- public function testCanValidateTextValues(): void
- {
- $arrayList = new ArrayList(new Text(100));
- $this->assertTrue($arrayList->isArray(), 'true');
- $this->assertTrue($arrayList->isValid([0 => 'string', 1 => 'string']));
- $this->assertTrue($arrayList->isValid(['string', 'string']));
- $this->assertFalse($arrayList->isValid(['string', 'string', 3]));
- $this->assertFalse($arrayList->isValid('string'));
- $this->assertFalse($arrayList->isValid('string'));
- $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $arrayList->getType());
- $this->assertInstanceOf(Text::class, $arrayList->getValidator());
- }
-
- public function testCanValidateNumericValues(): void
- {
- $arrayList = new ArrayList(new Numeric());
- $this->assertTrue($arrayList->isValid([1, 2, 3]));
- $this->assertFalse($arrayList->isValid(1));
- $this->assertFalse($arrayList->isValid('string'));
- $this->assertEquals(\Utopia\Http\Validator::TYPE_MIXED, $arrayList->getType());
- $this->assertInstanceOf(Numeric::class, $arrayList->getValidator());
- }
-
- public function testCanValidateNumericValuesWithBoundaries(): void
- {
- $arrayList = new ArrayList(new Numeric(), 2);
- $this->assertTrue($arrayList->isValid([1]));
- $this->assertTrue($arrayList->isValid([1, 2]));
- $this->assertFalse($arrayList->isValid([1, 2, 3]));
- $this->assertEquals($arrayList->getType(), \Utopia\Http\Validator::TYPE_MIXED);
- $this->assertInstanceOf(Numeric::class, $arrayList->getValidator());
- }
-}
diff --git a/tests/Validator/AssocTest.php b/tests/Validator/AssocTest.php
deleted file mode 100755
index 2036998b..00000000
--- a/tests/Validator/AssocTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
-assoc = new Assoc();
- }
-
- public function tearDown(): void
- {
- $this->assoc = null;
- }
-
- public function testCanValidateAssocArray(): void
- {
- $this->assertTrue($this->assoc->isValid(['1' => 'a', '0' => 'b', '2' => 'c']));
- $this->assertTrue($this->assoc->isValid(['a' => 'a', 'b' => 'b', 'c' => 'c']));
- $this->assertTrue($this->assoc->isValid([]));
- $this->assertTrue($this->assoc->isValid(['value' => str_repeat('-', 62000)]));
- $this->assertTrue($this->assoc->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_ARRAY, $this->assoc->getType());
- }
-
- public function testCantValidateSequentialArray(): void
- {
- $this->assertFalse($this->assoc->isValid([0 => 'string', 1 => 'string']));
- $this->assertFalse($this->assoc->isValid(['a']));
- $this->assertFalse($this->assoc->isValid(['a', 'b', 'c']));
- $this->assertFalse($this->assoc->isValid(['0' => 'a', '1' => 'b', '2' => 'c']));
- }
-
- public function testCantValidateAssocArrayWithOver65kCharacters(): void
- {
- $this->assertFalse($this->assoc->isValid(['value' => str_repeat('-', 66000)]));
- }
-}
diff --git a/tests/Validator/BooleanTest.php b/tests/Validator/BooleanTest.php
deleted file mode 100755
index bda71580..00000000
--- a/tests/Validator/BooleanTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-assertTrue($boolean->isValid(true));
- $this->assertTrue($boolean->isValid(false));
- $this->assertFalse($boolean->isValid('false'));
- $this->assertFalse($boolean->isValid('true'));
- $this->assertFalse($boolean->isValid('0'));
- $this->assertFalse($boolean->isValid('1'));
- $this->assertFalse($boolean->isValid(0));
- $this->assertFalse($boolean->isValid(1));
- $this->assertFalse($boolean->isValid(['string', 'string']));
- $this->assertFalse($boolean->isValid('string'));
- $this->assertFalse($boolean->isValid(1.2));
- $this->assertFalse($boolean->isArray());
- $this->assertEquals($boolean->getType(), \Utopia\Http\Validator::TYPE_BOOLEAN);
- }
-
- public function testCanValidateLoosely()
- {
- $boolean = new Boolean(true);
-
- $this->assertTrue($boolean->isValid(true));
- $this->assertTrue($boolean->isValid(false));
- $this->assertTrue($boolean->isValid('false'));
- $this->assertTrue($boolean->isValid('true'));
- $this->assertTrue($boolean->isValid('0'));
- $this->assertTrue($boolean->isValid('1'));
- $this->assertTrue($boolean->isValid(0));
- $this->assertTrue($boolean->isValid(1));
- $this->assertFalse($boolean->isValid(['string', 'string']));
- $this->assertFalse($boolean->isValid('string'));
- $this->assertFalse($boolean->isValid(1.2));
- $this->assertFalse($boolean->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_BOOLEAN, $boolean->getType());
- }
-}
diff --git a/tests/Validator/DomainTest.php b/tests/Validator/DomainTest.php
deleted file mode 100644
index 9561fec4..00000000
--- a/tests/Validator/DomainTest.php
+++ /dev/null
@@ -1,86 +0,0 @@
-
- * @version 1.0 RC4
- * @license The MIT License (MIT)
- */
-
-namespace Utopia\Http\Validator;
-
-use PHPUnit\Framework\TestCase;
-
-class DomainTest extends TestCase
-{
- protected Domain $domain;
-
- public function setUp(): void
- {
- $this->domain = new Domain();
- }
-
- public function testIsValid()
- {
- // Assertions
- $this->assertEquals(true, $this->domain->isValid('example.com'));
- $this->assertEquals(true, $this->domain->isValid('subdomain.example.com'));
- $this->assertEquals(true, $this->domain->isValid('subdomain.example-app.com'));
- $this->assertEquals(false, $this->domain->isValid('subdomain.example_app.com'));
- $this->assertEquals(true, $this->domain->isValid('subdomain-new.example.com'));
- $this->assertEquals(false, $this->domain->isValid('subdomain_new.example.com'));
- $this->assertEquals(true, $this->domain->isValid('localhost'));
- $this->assertEquals(true, $this->domain->isValid('example.io'));
- $this->assertEquals(true, $this->domain->isValid('example.org'));
- $this->assertEquals(true, $this->domain->isValid('example.org'));
- $this->assertEquals(false, $this->domain->isValid(false));
- $this->assertEquals(false, $this->domain->isValid('api.appwrite.io.'));
- $this->assertEquals(false, $this->domain->isValid('.api.appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('.api.appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('api..appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('api-.appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('api.-appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('app write.io'));
- $this->assertEquals(false, $this->domain->isValid(' appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('appwrite.io '));
- $this->assertEquals(false, $this->domain->isValid('-appwrite.io'));
- $this->assertEquals(false, $this->domain->isValid('appwrite.io-'));
- $this->assertEquals(false, $this->domain->isValid('.'));
- $this->assertEquals(false, $this->domain->isValid('..'));
- $this->assertEquals(false, $this->domain->isValid(''));
- $this->assertEquals(false, $this->domain->isValid(['string', 'string']));
- $this->assertEquals(false, $this->domain->isValid(1));
- $this->assertEquals(false, $this->domain->isValid(1.2));
- }
-
- public function testRestrictions()
- {
- $validator = new Domain([
- Domain::createRestriction('appwrite.network', 3, ['preview-', 'branch-']),
- Domain::createRestriction('fra.appwrite.run', 4),
- ]);
-
- $this->assertEquals(true, $validator->isValid('google.com'));
- $this->assertEquals(true, $validator->isValid('stage.google.com'));
- $this->assertEquals(true, $validator->isValid('shard4.stage.google.com'));
-
- $this->assertEquals(false, $validator->isValid('appwrite.network'));
- $this->assertEquals(false, $validator->isValid('preview-a.appwrite.network'));
- $this->assertEquals(false, $validator->isValid('branch-a.appwrite.network'));
- $this->assertEquals(true, $validator->isValid('google.appwrite.network'));
- $this->assertEquals(false, $validator->isValid('stage.google.appwrite.network'));
- $this->assertEquals(false, $validator->isValid('shard4.stage.google.appwrite.network'));
-
- $this->assertEquals(false, $validator->isValid('fra.appwrite.run'));
- $this->assertEquals(true, $validator->isValid('appwrite.run'));
- $this->assertEquals(true, $validator->isValid('google.fra.appwrite.run'));
- $this->assertEquals(false, $validator->isValid('shard4.google.fra.appwrite.run'));
- $this->assertEquals(true, $validator->isValid('branch-google.fra.appwrite.run'));
- $this->assertEquals(true, $validator->isValid('preview-google.fra.appwrite.run'));
- }
-}
diff --git a/tests/Validator/FloatValidatorTest.php b/tests/Validator/FloatValidatorTest.php
deleted file mode 100755
index be905b68..00000000
--- a/tests/Validator/FloatValidatorTest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-assertTrue($validator->isValid(27.25));
- $this->assertTrue($validator->isValid(23));
- $this->assertTrue($validator->isValid(23.5));
- $this->assertTrue($validator->isValid(1e7));
- $this->assertFalse($validator->isValid('abc'));
- $this->assertFalse($validator->isValid(true));
- $this->assertFalse($validator->isValid('23.5'));
- $this->assertFalse($validator->isValid('23'));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $validator->getType());
- }
-
- public function testCanValidateLoosely(): void
- {
- $validator = new FloatValidator(true);
-
- $this->assertTrue($validator->isValid(27.25));
- $this->assertTrue($validator->isValid(23));
- $this->assertTrue($validator->isValid(23.5));
- $this->assertTrue($validator->isValid(1e7));
- $this->assertTrue($validator->isValid('23.5'));
- $this->assertTrue($validator->isValid('23'));
- $this->assertFalse($validator->isValid('abc'));
- $this->assertFalse($validator->isValid(true));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $validator->getType());
- }
-}
diff --git a/tests/Validator/HexColorTest.php b/tests/Validator/HexColorTest.php
deleted file mode 100755
index f90d92fe..00000000
--- a/tests/Validator/HexColorTest.php
+++ /dev/null
@@ -1,26 +0,0 @@
-assertTrue($hexColor->isValid('000'));
- $this->assertTrue($hexColor->isValid('ffffff'));
- $this->assertTrue($hexColor->isValid('fff'));
- $this->assertTrue($hexColor->isValid('000000'));
-
- $this->assertFalse($hexColor->isValid('AB10BC99'));
- $this->assertFalse($hexColor->isValid('AR1012'));
- $this->assertFalse($hexColor->isValid('ab12bc99'));
- $this->assertFalse($hexColor->isValid('00'));
- $this->assertFalse($hexColor->isValid('ffff'));
- $this->assertFalse($hexColor->isArray());
-
- $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $hexColor->getType());
- }
-}
diff --git a/tests/Validator/HostTest.php b/tests/Validator/HostTest.php
deleted file mode 100644
index 7805adda..00000000
--- a/tests/Validator/HostTest.php
+++ /dev/null
@@ -1,42 +0,0 @@
-
- * @version 1.0 RC4
- * @license The MIT License (MIT)
- */
-
-namespace Utopia\Http\Validator;
-
-use PHPUnit\Framework\TestCase;
-
-class HostTest extends TestCase
-{
- protected Host $host;
-
- public function setUp(): void
- {
- $this->host = new Host(['example.io', 'subdomain.example.test', 'localhost', '*.appwrite.io']);
- }
-
- public function testIsValid()
- {
- // Assertions
- $this->assertEquals($this->host->isValid('https://example.io/link'), true);
- $this->assertEquals($this->host->isValid('https://localhost'), true);
- $this->assertEquals($this->host->isValid('localhost'), false);
- $this->assertEquals($this->host->isValid('http://subdomain.example.test/path'), true);
- $this->assertEquals($this->host->isValid('http://test.subdomain.example.test/path'), false);
- $this->assertEquals($this->host->isValid('http://appwrite.io/path'), false);
- $this->assertEquals($this->host->isValid('http://me.appwrite.io/path'), true);
- $this->assertEquals($this->host->isValid('http://you.appwrite.io/path'), true);
- $this->assertEquals($this->host->isValid('http://us.together.appwrite.io/path'), true);
- $this->assertEquals($this->host->getType(), 'string');
- }
-}
diff --git a/tests/Validator/HostnameTest.php b/tests/Validator/HostnameTest.php
deleted file mode 100755
index 2760648d..00000000
--- a/tests/Validator/HostnameTest.php
+++ /dev/null
@@ -1,106 +0,0 @@
-assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType());
- $this->assertFalse($validator->isArray());
-
- $this->assertTrue($validator->isValid('myweb.com'));
- $this->assertTrue($validator->isValid('httpmyweb.com'));
- $this->assertTrue($validator->isValid('httpsmyweb.com'));
- $this->assertTrue($validator->isValid('wsmyweb.com'));
- $this->assertTrue($validator->isValid('wssmyweb.com'));
- $this->assertTrue($validator->isValid('vercel.app'));
- $this->assertTrue($validator->isValid('web.vercel.app'));
- $this->assertTrue($validator->isValid('my-web.vercel.app'));
- $this->assertTrue($validator->isValid('my-project.my-web.vercel.app'));
- $this->assertTrue($validator->isValid('my-commit.my-project.my-web.vercel.app'));
- $this->assertTrue($validator->isValid('myapp.co.uk'));
- $this->assertTrue($validator->isValid('*.myapp.com'));
- $this->assertTrue($validator->isValid('myapp.*'));
-
- $this->assertFalse($validator->isValid('https://myweb.com'));
- $this->assertFalse($validator->isValid('ws://myweb.com'));
- $this->assertFalse($validator->isValid('wss://myweb.com'));
- $this->assertFalse($validator->isValid('http://myweb.com'));
- $this->assertFalse($validator->isValid('http://myweb.com:3000'));
- $this->assertFalse($validator->isValid('http://myweb.com/blog'));
- $this->assertFalse($validator->isValid('myweb.com:80'));
- $this->assertFalse($validator->isValid('myweb.com:3000'));
- $this->assertFalse($validator->isValid('myweb.com/blog'));
- $this->assertFalse($validator->isValid('myweb.com/blog/article1'));
-
- // Max length test
- $domain = \str_repeat('bestdomain', 25); // 250 chars total
-
- $domain .= '.sk'; // Exactly at the limit
- $this->assertTrue($validator->isValid($domain));
-
- $domain .= 'a'; // Exactly over the limit
- $this->assertFalse($validator->isValid($domain));
- }
-
- public function testCanValidateHostnamesWithAllowList(): void
- {
- // allowList tests
- $validator = new Hostname([
- 'myweb.vercel.app',
- 'myweb.com',
- '*.myapp.com',
- ]);
-
- $this->assertTrue($validator->isValid('myweb.vercel.app'));
- $this->assertFalse($validator->isValid('myweb.vercel.com'));
- $this->assertFalse($validator->isValid('myweb2.vercel.app'));
- $this->assertFalse($validator->isValid('vercel.app'));
- $this->assertFalse($validator->isValid('mycommit.myweb.vercel.app'));
-
- $this->assertTrue($validator->isValid('myweb.com'));
- $this->assertFalse($validator->isValid('myweb.eu'));
- $this->assertFalse($validator->isValid('project.myweb.eu'));
- $this->assertFalse($validator->isValid('commit.project.myweb.eu'));
-
- $this->assertTrue($validator->isValid('project1.myapp.com'));
- $this->assertTrue($validator->isValid('project2.myapp.com'));
- $this->assertTrue($validator->isValid('project-with-dash.myapp.com'));
- $this->assertTrue($validator->isValid('anything.myapp.com'));
- $this->assertTrue($validator->isValid('commit.anything.myapp.com'));
- $this->assertFalse($validator->isValid('anything.myapp.eu'));
- $this->assertFalse($validator->isValid('myapp.com'));
-
- $validator = new Hostname(['localhost']);
- $this->assertTrue($validator->isValid('localhost'));
- }
-
- public function testCanValidateHostnamesWithWildcard(): void
- {
- $validator = new Hostname();
- $this->assertTrue($validator->isValid('*'));
-
- $validator = new Hostname(['netlify.*']);
- $this->assertFalse($validator->isValid('netlify.com'));
- $this->assertFalse($validator->isValid('netlify.eu'));
- $this->assertFalse($validator->isValid('netlify.app'));
-
- $validator = new Hostname(['*.*.app.io']);
- $this->assertFalse($validator->isValid('app.io'));
- $this->assertFalse($validator->isValid('project.app.io'));
- $this->assertFalse($validator->isValid('commit.project.app.io'));
- $this->assertFalse($validator->isValid('api.commit.project.app.io'));
-
- $validator = new Hostname(['*']);
- $this->assertTrue($validator->isValid('*'));
- $this->assertTrue($validator->isValid('localhost'));
- $this->assertTrue($validator->isValid('anything')); // Like localhost
- $this->assertTrue($validator->isValid('anything.com'));
- $this->assertTrue($validator->isValid('anything.with.subdomains.eu'));
- }
-}
diff --git a/tests/Validator/IPTest.php b/tests/Validator/IPTest.php
deleted file mode 100644
index ac0ae1e5..00000000
--- a/tests/Validator/IPTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-
- * @version 1.0 RC4
- * @license The MIT License (MIT)
- */
-
-namespace Utopia\Http\Validator;
-
-use PHPUnit\Framework\TestCase;
-
-class IPTest extends TestCase
-{
- protected IP $validator;
-
- public function testIsValidIP()
- {
- $validator = new IP();
-
- // Assertions
- $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
- $this->assertEquals($validator->isValid('109.67.204.101'), true);
- $this->assertEquals($validator->isValid(23.5), false);
- $this->assertEquals($validator->isValid('23.5'), false);
- $this->assertEquals($validator->isValid(null), false);
- $this->assertEquals($validator->isValid(true), false);
- $this->assertEquals($validator->isValid(false), false);
- $this->assertEquals($validator->getType(), 'string');
- }
-
- public function testIsValidIPALL()
- {
- $validator = new IP(IP::ALL);
-
- // Assertions
- $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
- $this->assertEquals($validator->isValid('109.67.204.101'), true);
- $this->assertEquals($validator->isValid(23.5), false);
- $this->assertEquals($validator->isValid('23.5'), false);
- $this->assertEquals($validator->isValid(null), false);
- $this->assertEquals($validator->isValid(true), false);
- $this->assertEquals($validator->isValid(false), false);
- }
-
- public function testIsValidIPV4()
- {
- $validator = new IP(IP::V4);
-
- // Assertions
- $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), false);
- $this->assertEquals($validator->isValid('109.67.204.101'), true);
- $this->assertEquals($validator->isValid(23.5), false);
- $this->assertEquals($validator->isValid('23.5'), false);
- $this->assertEquals($validator->isValid(null), false);
- $this->assertEquals($validator->isValid(true), false);
- $this->assertEquals($validator->isValid(false), false);
- }
-
- public function testIsValidIPV6()
- {
- $validator = new IP(IP::V6);
-
- // Assertions
- $this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
- $this->assertEquals($validator->isValid('109.67.204.101'), false);
- $this->assertEquals($validator->isValid(23.5), false);
- $this->assertEquals($validator->isValid('23.5'), false);
- $this->assertEquals($validator->isValid(null), false);
- $this->assertEquals($validator->isValid(true), false);
- $this->assertEquals($validator->isValid(false), false);
- }
-}
diff --git a/tests/Validator/IntegerTest.php b/tests/Validator/IntegerTest.php
deleted file mode 100755
index faddca2c..00000000
--- a/tests/Validator/IntegerTest.php
+++ /dev/null
@@ -1,36 +0,0 @@
-assertTrue($validator->isValid(23));
- $this->assertFalse($validator->isValid('23'));
- $this->assertFalse($validator->isValid(23.5));
- $this->assertFalse($validator->isValid('23.5'));
- $this->assertFalse($validator->isValid(null));
- $this->assertFalse($validator->isValid(true));
- $this->assertFalse($validator->isValid(false));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $validator->getType());
- }
-
- public function testCanValidateLoosely()
- {
- $validator = new Integer(true);
- $this->assertTrue($validator->isValid(23));
- $this->assertTrue($validator->isValid('23'));
- $this->assertFalse($validator->isValid(23.5));
- $this->assertFalse($validator->isValid('23.5'));
- $this->assertFalse($validator->isValid(null));
- $this->assertFalse($validator->isValid(true));
- $this->assertFalse($validator->isValid(false));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $validator->getType());
- }
-}
diff --git a/tests/Validator/JSONTest.php b/tests/Validator/JSONTest.php
deleted file mode 100755
index d4a4e358..00000000
--- a/tests/Validator/JSONTest.php
+++ /dev/null
@@ -1,28 +0,0 @@
-assertTrue($json->isValid('{}'));
- $this->assertTrue($json->isValid([]));
- $this->assertTrue($json->isValid(['test']));
- $this->assertTrue($json->isValid(['test' => 'demo']));
- $this->assertTrue($json->isValid('{"test": "demo"}'));
-
- $this->assertFalse($json->isValid(''));
- $this->assertFalse($json->isValid(false));
- $this->assertFalse($json->isValid(null));
- $this->assertFalse($json->isValid('string'));
- $this->assertFalse($json->isValid(1));
- $this->assertFalse($json->isValid(1.2));
- $this->assertFalse($json->isValid("{'test': 'demo'}"));
- $this->assertFalse($json->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_OBJECT, $json->getType());
- }
-}
diff --git a/tests/Validator/MultipleOfTest.php b/tests/Validator/MultipleOfTest.php
deleted file mode 100644
index 5c541223..00000000
--- a/tests/Validator/MultipleOfTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-assertEquals('string', $validator->getType());
- $this->assertEquals("Value must be a valid string and at least 1 chars and no longer than 20 chars", $validator->getDescription());
-
- // Valid URL but invalid text length
- $this->assertFalse($validator->isValid('http://example.com/very-long-url'));
-
- // Valid text within length, but invalid URL
- $this->assertFalse($validator->isValid('hello world'));
-
- // Both conditions satisfied
- $this->assertTrue($validator->isValid('http://example.com'));
- $this->assertTrue($validator->isValid('https://google.com'));
-
- // Neither condition satisfied
- $this->assertFalse($validator->isValid('example.com/hello-world'));
- $this->assertFalse($validator->isValid(''));
- }
-
- public function testRules()
- {
- $validTextValidUrl = 'http://example.com';
- $validTextInvalidUrl = 'hello world';
- $invalidTextValidUrl = 'http://example.com/very-long-url';
- $invalidTextInvalidUrl = 'Some very long text that is also not an URL';
-
- $vaidator = new AllOf([new Text(20), new URL()], Validator::TYPE_STRING);
- $this->assertTrue($vaidator->isValid($validTextValidUrl));
- $this->assertFalse($vaidator->isValid($validTextInvalidUrl));
- $this->assertFalse($vaidator->isValid($invalidTextValidUrl));
- $this->assertFalse($vaidator->isValid($invalidTextInvalidUrl));
-
- $vaidator = new AnyOf([new Text(20), new URL()], Validator::TYPE_STRING);
- $this->assertTrue($vaidator->isValid($validTextValidUrl));
- $this->assertTrue($vaidator->isValid($validTextInvalidUrl));
- $this->assertTrue($vaidator->isValid($invalidTextValidUrl));
- $this->assertFalse($vaidator->isValid($invalidTextInvalidUrl));
-
- $this->assertCount(2, $vaidator->getValidators());
- $this->assertEquals("Utopia\Http\Validator\Text", \get_class($vaidator->getValidators()[0]));
- $this->assertEquals("Utopia\Http\Validator\URL", \get_class($vaidator->getValidators()[1]));
-
- $vaidator = new NoneOf([new Text(20), new URL()], Validator::TYPE_STRING);
- $this->assertFalse($vaidator->isValid($validTextValidUrl));
- $this->assertFalse($vaidator->isValid($validTextInvalidUrl));
- $this->assertFalse($vaidator->isValid($invalidTextValidUrl));
- $this->assertTrue($vaidator->isValid($invalidTextInvalidUrl));
- }
-}
diff --git a/tests/Validator/NullableTest.php b/tests/Validator/NullableTest.php
deleted file mode 100755
index ebd24834..00000000
--- a/tests/Validator/NullableTest.php
+++ /dev/null
@@ -1,22 +0,0 @@
-assertTrue($validator->isValid('text'));
- $this->assertTrue($validator->isValid(null));
- $this->assertFalse($validator->isValid(123));
- }
-
- public function testCanReturnValidator(): void
- {
- $validator = new Nullable(new Text(0));
- $this->assertTrue($validator->getValidator() instanceof Text);
- }
-}
diff --git a/tests/Validator/NumericTest.php b/tests/Validator/NumericTest.php
deleted file mode 100755
index 88ea5030..00000000
--- a/tests/Validator/NumericTest.php
+++ /dev/null
@@ -1,24 +0,0 @@
-assertTrue($numeric->isValid('42'));
- $this->assertTrue($numeric->isValid(1337));
- $this->assertTrue($numeric->isValid(0x539));
- $this->assertTrue($numeric->isValid(02471));
- $this->assertTrue($numeric->isValid(1337e0));
- $this->assertTrue($numeric->isValid(9.1));
- $this->assertFalse($numeric->isValid('not numeric'));
- $this->assertFalse($numeric->isValid([]));
- $this->assertFalse($numeric->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_MIXED, $numeric->getType());
- }
-}
diff --git a/tests/Validator/RangeTest.php b/tests/Validator/RangeTest.php
deleted file mode 100755
index aafbab4a..00000000
--- a/tests/Validator/RangeTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-assertTrue($range->isValid(0));
- $this->assertTrue($range->isValid(1));
- $this->assertTrue($range->isValid(4));
- $this->assertTrue($range->isValid(5));
- $this->assertTrue($range->isValid('5'));
- $this->assertFalse($range->isValid('1.5'));
- $this->assertFalse($range->isValid(6));
- $this->assertFalse($range->isValid(-1));
- $this->assertEquals(0, $range->getMin());
- $this->assertEquals(5, $range->getMax());
- $this->assertFalse($range->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $range->getFormat());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_INTEGER, $range->getType());
- }
-
- public function testCanValidateFloatRange()
- {
- $range = new Range(0, 1, \Utopia\Http\Validator::TYPE_FLOAT);
-
- $this->assertTrue($range->isValid(0.0));
- $this->assertTrue($range->isValid(1.0));
- $this->assertTrue($range->isValid(0.5));
- $this->assertTrue($range->isValid('0.5'));
- $this->assertTrue($range->isValid('0.6'));
- $this->assertFalse($range->isValid(4));
- $this->assertFalse($range->isValid(1.5));
- $this->assertFalse($range->isValid(-1));
- $this->assertEquals(0, $range->getMin());
- $this->assertEquals(1, $range->getMax());
- $this->assertFalse($range->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $range->getFormat());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_FLOAT, $range->getType(), \Utopia\Http\Validator::TYPE_FLOAT);
- }
-
- public function canValidateInfinityRange()
- {
- $integer = new Range(5, INF, \Utopia\Http\Validator::TYPE_INTEGER);
- $float = new Range(-INF, 45.6, \Utopia\Http\Validator::TYPE_FLOAT);
-
- $this->assertTrue($integer->isValid(25));
- $this->assertFalse($integer->isValid(3));
- $this->assertTrue($integer->isValid(INF));
- $this->assertTrue($float->isValid(32.1));
- $this->assertFalse($float->isValid(97.6));
- $this->assertTrue($float->isValid(-INF));
- }
-}
diff --git a/tests/Validator/TextTest.php b/tests/Validator/TextTest.php
deleted file mode 100755
index 476cfd8a..00000000
--- a/tests/Validator/TextTest.php
+++ /dev/null
@@ -1,88 +0,0 @@
-assertTrue($validator->isValid('text'));
- $this->assertTrue($validator->isValid('7'));
- $this->assertTrue($validator->isValid('7.9'));
- $this->assertTrue($validator->isValid('["seven"]'));
- $this->assertFalse($validator->isValid(['seven']));
- $this->assertFalse($validator->isValid(['seven', 8, 9.0]));
- $this->assertFalse($validator->isValid(false));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType());
- }
-
- public function testCanValidateBoundaries(): void
- {
- $validator = new Text(5);
- $this->assertTrue($validator->isValid('hell'));
- $this->assertTrue($validator->isValid('hello'));
- $this->assertFalse($validator->isValid('hellow'));
- $this->assertFalse($validator->isValid(''));
-
- $validator = new Text(5, 3);
- $this->assertTrue($validator->isValid('hel'));
- $this->assertTrue($validator->isValid('hell'));
- $this->assertTrue($validator->isValid('hello'));
- $this->assertFalse($validator->isValid('hellow'));
- $this->assertFalse($validator->isValid('he'));
- $this->assertFalse($validator->isValid('h'));
- }
-
- public function testCanValidateTextWithAllowList(): void
- {
- // Test lowercase alphabet
- $validator = new Text(100, allowList: Text::ALPHABET_LOWER);
- $this->assertFalse($validator->isArray());
- $this->assertTrue($validator->isValid('qwertzuiopasdfghjklyxcvbnm'));
- $this->assertTrue($validator->isValid('hello'));
- $this->assertTrue($validator->isValid('world'));
- $this->assertFalse($validator->isValid('hello world'));
- $this->assertFalse($validator->isValid('Hello'));
- $this->assertFalse($validator->isValid('worlD'));
- $this->assertFalse($validator->isValid('hello123'));
-
- // Test uppercase alphabet
- $validator = new Text(100, allowList: Text::ALPHABET_UPPER);
- $this->assertFalse($validator->isArray());
- $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNM'));
- $this->assertTrue($validator->isValid('HELLO'));
- $this->assertTrue($validator->isValid('WORLD'));
- $this->assertFalse($validator->isValid('HELLO WORLD'));
- $this->assertFalse($validator->isValid('hELLO'));
- $this->assertFalse($validator->isValid('WORLd'));
- $this->assertFalse($validator->isValid('HELLO123'));
-
- // Test numbers
- $validator = new Text(100, allowList: Text::NUMBERS);
- $this->assertFalse($validator->isArray());
- $this->assertTrue($validator->isValid('1234567890'));
- $this->assertTrue($validator->isValid('123'));
- $this->assertFalse($validator->isValid('123 456'));
- $this->assertFalse($validator->isValid('hello123'));
-
- // Test combination of allowLists
- $validator = new Text(100, allowList: [
- ...Text::ALPHABET_LOWER,
- ...Text::ALPHABET_UPPER,
- ...Text::NUMBERS,
- ]);
-
- $this->assertFalse($validator->isArray());
- $this->assertTrue($validator->isValid('1234567890'));
- $this->assertTrue($validator->isValid('qwertzuiopasdfghjklyxcvbnm'));
- $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNM'));
- $this->assertTrue($validator->isValid('QWERTZUIOPASDFGHJKLYXCVBNMqwertzuiopasdfghjklyxcvbnm1234567890'));
- $this->assertFalse($validator->isValid('hello-world'));
- $this->assertFalse($validator->isValid('hello_world'));
- $this->assertFalse($validator->isValid('hello/world'));
- }
-}
diff --git a/tests/Validator/URLTest.php b/tests/Validator/URLTest.php
deleted file mode 100644
index f939eeb6..00000000
--- a/tests/Validator/URLTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-
- * @version 1.0 RC4
- * @license The MIT License (MIT)
- */
-
-namespace Utopia\Http\Validator;
-
-use PHPUnit\Framework\TestCase;
-
-class URLTest extends TestCase
-{
- protected ?URL $url;
-
- public function setUp(): void
- {
- $this->url = new URL();
- }
-
- public function tearDown(): void
- {
- $this->url = null;
- }
-
- public function testIsValid(): void
- {
- $this->assertEquals('Value must be a valid URL', $this->url->getDescription());
- $this->assertEquals(true, $this->url->isValid('http://example.com'));
- $this->assertEquals(true, $this->url->isValid('https://example.com'));
- $this->assertEquals(true, $this->url->isValid('htts://example.com')); // does not validate protocol
- $this->assertEquals(false, $this->url->isValid('example.com')); // though, requires some kind of protocol
- $this->assertEquals(false, $this->url->isValid('http:/example.com'));
- $this->assertEquals(true, $this->url->isValid('http://exa-mple.com'));
- $this->assertEquals(false, $this->url->isValid('htt@s://example.com'));
- $this->assertEquals(true, $this->url->isValid('http://www.example.com/foo%2\u00c2\u00a9zbar'));
- $this->assertEquals(true, $this->url->isValid('http://www.example.com/?q=%3Casdf%3E'));
- }
-
- public function testIsValidAllowedSchemes(): void
- {
- $this->url = new URL(['http', 'https']);
- $this->assertEquals('Value must be a valid URL with following schemes (http, https)', $this->url->getDescription());
- $this->assertEquals(true, $this->url->isValid('http://example.com'));
- $this->assertEquals(true, $this->url->isValid('https://example.com'));
- $this->assertEquals(false, $this->url->isValid('gopher://www.example.com'));
- }
-}
diff --git a/tests/Validator/WhiteListTest.php b/tests/Validator/WhiteListTest.php
deleted file mode 100755
index f024908c..00000000
--- a/tests/Validator/WhiteListTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-assertTrue($whiteList->isValid(3));
- $this->assertTrue($whiteList->isValid(4));
- $this->assertTrue($whiteList->isValid('string1'));
- $this->assertTrue($whiteList->isValid('string2'));
-
- $this->assertFalse($whiteList->isValid('string3'));
- $this->assertFalse($whiteList->isValid('STRING1'));
- $this->assertFalse($whiteList->isValid('strIng1'));
- $this->assertFalse($whiteList->isValid('3'));
- $this->assertFalse($whiteList->isValid(5));
- $this->assertFalse($whiteList->isArray());
- $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]);
- $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $whiteList->getType());
- }
-
- public function testCanValidateLoosely(): void
- {
- $whiteList = new WhiteList(['string1', 'string2', 3, 4]);
-
- $this->assertTrue($whiteList->isValid(3));
- $this->assertTrue($whiteList->isValid(4));
- $this->assertTrue($whiteList->isValid('string1'));
- $this->assertTrue($whiteList->isValid('string2'));
- $this->assertTrue($whiteList->isValid('STRING1'));
- $this->assertTrue($whiteList->isValid('strIng1'));
- $this->assertTrue($whiteList->isValid('3'));
- $this->assertTrue($whiteList->isValid('4'));
- $this->assertFalse($whiteList->isValid('string3'));
- $this->assertFalse($whiteList->isValid(5));
- $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]);
-
- $whiteList = new WhiteList(['STRING1', 'STRING2', 3, 4]);
-
- $this->assertTrue($whiteList->isValid(3));
- $this->assertTrue($whiteList->isValid(4));
- $this->assertTrue($whiteList->isValid('string1'));
- $this->assertTrue($whiteList->isValid('string2'));
- $this->assertTrue($whiteList->isValid('STRING1'));
- $this->assertTrue($whiteList->isValid('strIng1'));
- $this->assertTrue($whiteList->isValid('3'));
- $this->assertTrue($whiteList->isValid('4'));
- $this->assertFalse($whiteList->isValid('string3'));
- $this->assertFalse($whiteList->isValid(5));
- $this->assertEquals($whiteList->getList(), ['string1', 'string2', 3, 4]);
- }
-}
diff --git a/tests/Validator/WildcardTest.php b/tests/Validator/WildcardTest.php
deleted file mode 100644
index 4de71475..00000000
--- a/tests/Validator/WildcardTest.php
+++ /dev/null
@@ -1,21 +0,0 @@
-assertTrue($validator->isValid([0 => 'string', 1 => 'string']));
- $this->assertTrue($validator->isValid(''));
- $this->assertTrue($validator->isValid([]));
- $this->assertTrue($validator->isValid(1));
- $this->assertTrue($validator->isValid(true));
- $this->assertTrue($validator->isValid(false));
- $this->assertFalse($validator->isArray());
- $this->assertEquals(\Utopia\Http\Validator::TYPE_STRING, $validator->getType());
- }
-}
diff --git a/tests/e2e/init.php b/tests/e2e/init.php
index 003fb29c..333aa7eb 100644
--- a/tests/e2e/init.php
+++ b/tests/e2e/init.php
@@ -6,7 +6,7 @@
use Utopia\Http\Http;
use Utopia\Http\Request;
use Utopia\Http\Response;
-use Utopia\Http\Validator\Text;
+use Utopia\Validator\Text;
ini_set('memory_limit', '1024M');
ini_set('display_errors', '1');