diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index 4b5b22582..268964bf4 100644 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -153,7 +153,7 @@ final class FileCache extends ConnectionAbstract return; } - $path = Directory::sanitize($key, self::SANITIZE); + $path = Directory::sanitize((string) $key, self::SANITIZE); $fp = \fopen($this->con . '/' . \trim($path, '/') . '.cache', 'w+'); if (\flock($fp, \LOCK_EX)) { @@ -462,10 +462,6 @@ final class FileCache extends ConnectionAbstract $created = File::created($path)->getTimestamp(); $now = \time(); - if ($expire >= 0 && $created + $expire < $now) { - return; - } - $raw = \file_get_contents($path); if ($raw === false) { return; @@ -499,10 +495,6 @@ final class FileCache extends ConnectionAbstract $created = File::created($path)->getTimestamp(); $now = \time(); - if ($expire >= 0 && $created + $expire < $now) { - return; - } - $raw = \file_get_contents($path); if ($raw === false) { return; @@ -632,7 +624,7 @@ final class FileCache extends ConnectionAbstract */ public function updateExpire(int|string $key, int $expire = -1) : bool { - $value = $this->get($key); + $value = $this->get($key, $expire); $this->delete($key); $this->set($key, $value, $expire); @@ -703,7 +695,7 @@ final class FileCache extends ConnectionAbstract */ private function getPath(int|string $key) : string { - $path = Directory::sanitize($key, self::SANITIZE); + $path = Directory::sanitize((string) $key, self::SANITIZE); return $this->con . '/' . \trim($path, '/') . '.cache'; } } diff --git a/DataStorage/Cache/Connection/MemCached.php b/DataStorage/Cache/Connection/MemCached.php index 7d3a54e33..724cdb853 100644 --- a/DataStorage/Cache/Connection/MemCached.php +++ b/DataStorage/Cache/Connection/MemCached.php @@ -190,7 +190,7 @@ final class MemCached extends ConnectionAbstract $values = []; foreach ($keys as $key) { - if (\preg_match($key, $key) === 1) { + if (\preg_match('/' . $pattern . '/', $key) === 1) { $result = $this->con->get($key); if (\is_string($result)) { $type = (int) $result[0]; @@ -216,7 +216,7 @@ final class MemCached extends ConnectionAbstract $keys = $this->con->getAllKeys(); foreach ($keys as $key) { - if (\preg_match($key, $key) === 1) { + if (\preg_match('/' . $pattern . '/', $key) === 1) { $this->con->delete($key); } } diff --git a/DataStorage/Cache/Connection/NullCache.php b/DataStorage/Cache/Connection/NullCache.php index 595a8e09c..86250ba68 100644 --- a/DataStorage/Cache/Connection/NullCache.php +++ b/DataStorage/Cache/Connection/NullCache.php @@ -121,7 +121,7 @@ final class NullCache extends ConnectionAbstract */ public function exists(int|string $key, int $expire = -1) : bool { - return true; + return false; } /** diff --git a/DataStorage/Cache/Connection/RedisCache.php b/DataStorage/Cache/Connection/RedisCache.php index fe0a35be3..4899574f2 100644 --- a/DataStorage/Cache/Connection/RedisCache.php +++ b/DataStorage/Cache/Connection/RedisCache.php @@ -220,7 +220,7 @@ final class RedisCache extends ConnectionAbstract $values = []; foreach ($keys as $key) { - if (\preg_match($key, $key) === 1) { + if (\preg_match('/' . $pattern . '/', $key) === 1) { $result = $this->con->get($key); if (\is_string($result)) { $type = (int) $result[0]; @@ -246,7 +246,7 @@ final class RedisCache extends ConnectionAbstract $keys = $this->con->keys('*'); foreach ($keys as $key) { - if (\preg_match($key, $key) === 1) { + if (\preg_match('/' . $pattern . '/', $key) === 1) { $this->con->del($key); } } diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 73fa88b3c..84aaec997 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -114,7 +114,7 @@ final class Dispatcher implements DispatcherInterface $views = []; $dispatch = \explode(':', $controller); - if (!Autoloader::exists($dispatch[0])) { + if (!Autoloader::exists($dispatch[0]) && !isset($this->controllers[$dispatch[0]])) { throw new PathException($dispatch[0]); } diff --git a/tests/AutoloaderTest.php b/tests/AutoloaderTest.php index d38326740..2107bbcf1 100644 --- a/tests/AutoloaderTest.php +++ b/tests/AutoloaderTest.php @@ -60,6 +60,11 @@ class AutoloaderTest extends \PHPUnit\Framework\TestCase self::assertTrue(\in_array(\realpath(__DIR__ . '/TestLoad2.php'), $includes)); } + public function testPathFinding() : void + { + self::assertCount(1, Autoloader::findPaths('\phpOMS\Autoloader')); + } + /** * @covers phpOMS\Autoloader * @group framework diff --git a/tests/DataStorage/Cache/Connection/FileCacheTest.php b/tests/DataStorage/Cache/Connection/FileCacheTest.php index d28e607a5..14bac8ccc 100644 --- a/tests/DataStorage/Cache/Connection/FileCacheTest.php +++ b/tests/DataStorage/Cache/Connection/FileCacheTest.php @@ -124,6 +124,52 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase self::assertEquals('testValAdd', $this->cache->get('addKey')); } + public function testGetLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertEquals([], \array_diff(['testVal1', 'testVal2'], $this->cache->getLike('key\d'))); + } + + public function testIncrement() : void + { + $this->cache->set(1, 1); + $this->cache->increment(1, 2); + self::assertEquals(3, $this->cache->get(1)); + } + + public function testDecrement() : void + { + $this->cache->set(1, 3); + $this->cache->decrement(1, 2); + self::assertEquals(1, $this->cache->get(1)); + } + + public function testRename() : void + { + $this->cache->set('a', 'testVal1'); + $this->cache->rename('a', 'b'); + self::assertEquals('testVal1', $this->cache->get('b')); + } + + public function testDeleteLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertTrue($this->cache->deleteLike('key\d')); + self::assertEquals([], $this->cache->getLike('key\d')); + } + + public function testUpdateExpire() : void + { + $this->cache->set('key2', 'testVal2', 1); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + \sleep(2); + self::assertNull($this->cache->get('key2', 1)); + self::assertTrue($this->cache->updateExpire(10000)); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + } + /** * @testdox Cache data cannot be added if it already exists * @covers phpOMS\DataStorage\Cache\Connection\FileCache @@ -338,7 +384,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase { $this->expectException(\phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException::class); - $cache = new FileCache("/root/etc/invalidPathOrPermission^$:?><"); + $this->cache = new FileCache("/root/etc/invalidPathOrPermission^$:?><"); } /** diff --git a/tests/DataStorage/Cache/Connection/MemCachedTest.php b/tests/DataStorage/Cache/Connection/MemCachedTest.php index ade1a50a8..eeee79572 100644 --- a/tests/DataStorage/Cache/Connection/MemCachedTest.php +++ b/tests/DataStorage/Cache/Connection/MemCachedTest.php @@ -125,6 +125,52 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase self::assertEquals('testValAdd', $this->cache->get('addKey')); } + public function testGetLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertEquals(['testVal1', 'testVal2'], $this->cache->getLike('key\d')); + } + + public function testIncrement() : void + { + $this->cache->set(1, 1); + $this->cache->increment(1, 2); + self::assertEquals(3, $this->cache->get(1)); + } + + public function testDecrement() : void + { + $this->cache->set(1, 3); + $this->cache->decrement(1, 2); + self::assertEquals(1, $this->cache->get(1)); + } + + public function testRename() : void + { + $this->cache->set('a', 'testVal1'); + $this->cache->rename('a', 'b'); + self::assertEquals('testVal1', $this->cache->get('b')); + } + + public function testDeleteLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertTrue($this->cache->deleteLike('key\d')); + self::assertEquals([], $this->cache->getLike('key\d')); + } + + public function testUpdateExpire() : void + { + $this->cache->set('key2', 'testVal2', 1); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + \sleep(2); + self::assertNull($this->cache->get('key2', 1)); + self::assertTrue($this->cache->updateExpire(10000)); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + } + /** * @testdox Cache data cannot be added if it already exists * @covers phpOMS\DataStorage\Cache\Connection\MemCached diff --git a/tests/DataStorage/Cache/Connection/NullCacheTest.php b/tests/DataStorage/Cache/Connection/NullCacheTest.php index b954f8adb..536bf86b0 100644 --- a/tests/DataStorage/Cache/Connection/NullCacheTest.php +++ b/tests/DataStorage/Cache/Connection/NullCacheTest.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace phpOMS\tests\DataStorage\Cache\Connection; use phpOMS\DataStorage\Cache\CacheType; +use phpOMS\DataStorage\Cache\CacheStatus; use phpOMS\DataStorage\Cache\Connection\NullCache; /** @@ -24,27 +25,107 @@ use phpOMS\DataStorage\Cache\Connection\NullCache; */ final class NullCacheTest extends \PHPUnit\Framework\TestCase { + protected NullCache $cache; + + protected function setUp() : void + { + $this->cache = new NullCache([]); + } + /** * @testdox The default cache has the expected default values after initialization * @covers phpOMS\DataStorage\Cache\Connection\NullCache * @group framework */ - public function testCache() : void + public function testDefault() : void { - $cache = new NullCache(); - $cache->connect([]); + self::assertEquals(CacheType::UNDEFINED, $this->cache->getType()); + self::assertEquals([], $this->cache->stats()); + self::assertEquals(0, $this->cache->getThreshold()); + } - self::assertEquals(CacheType::UNDEFINED, $cache->getType()); - self::assertTrue($cache->add(1, 1)); + public function testConnect() : void + { + $this->cache->connect([]); + self::assertEquals(CacheStatus::CLOSED, $this->cache->getStatus()); + } - $cache->set(1, 1); - self::assertNull($cache->get(1)); + public function testSetInputOutput() : void + { + $this->cache->set(1, 1); + self::assertNull($this->cache->get(1)); + } - self::assertTrue($cache->delete(1)); - self::assertTrue($cache->flush(1)); - self::assertTrue($cache->flushAll()); - self::assertTrue($cache->replace(1, 1)); - self::assertEquals([], $cache->stats()); - self::assertEquals(0, $cache->getThreshold()); + public function testAddInputOutput() : void + { + self::assertTrue($this->cache->add(1, 1)); + self::assertNull($this->cache->get(1)); + } + + public function testGetLike() : void + { + self::assertEquals([], $this->cache->getLike('')); + } + + public function testIncrement() : void + { + $this->cache->increment(1, 1); + self::assertNull($this->cache->get(1)); + } + + public function testDecrement() : void + { + $this->cache->increment(1, 1); + self::assertNull($this->cache->get(1)); + } + + public function testReplace() : void + { + self::assertTrue($this->cache->replace(1, 1)); + } + + public function testRename() : void + { + $this->cache->set(1, 1); + $this->cache->rename(1, 2); + self::assertNull($this->cache->get(2)); + } + + public function testDelete() : void + { + self::assertTrue($this->cache->delete(1)); + } + + public function testDeleteLike() : void + { + self::assertTrue($this->cache->deleteLike('')); + } + + public function testFlush() : void + { + self::assertTrue($this->cache->flush(1)); + } + + public function testFlushAll() : void + { + self::assertTrue($this->cache->flushAll()); + } + + public function testExists() : void + { + $this->cache->set(1, 1); + self::assertFalse($this->cache->exists(1)); + } + + public function testUpdateExpire() : void + { + self::assertTrue($this->cache->updateExpire(1)); + } + + public function testStats() : void + { + $this->cache->set(1, 1); + $this->cache->add(2, 2); + self::assertEquals([], $this->cache->stats()); } } diff --git a/tests/DataStorage/Cache/Connection/RedisCacheTest.php b/tests/DataStorage/Cache/Connection/RedisCacheTest.php index eeffd4536..38d45f5ee 100644 --- a/tests/DataStorage/Cache/Connection/RedisCacheTest.php +++ b/tests/DataStorage/Cache/Connection/RedisCacheTest.php @@ -121,6 +121,52 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase self::assertEquals('testValAdd', $this->cache->get('addKey')); } + public function testGetLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertEquals(['testVal1', 'testVal2'], $this->cache->getLike('key\d')); + } + + public function testIncrement() : void + { + $this->cache->set(1, 1); + $this->cache->increment(1, 2); + self::assertEquals(3, $this->cache->get(1)); + } + + public function testDecrement() : void + { + $this->cache->set(1, 3); + $this->cache->decrement(1, 2); + self::assertEquals(1, $this->cache->get(1)); + } + + public function testRename() : void + { + $this->cache->set('a', 'testVal1'); + $this->cache->rename('a', 'b'); + self::assertEquals('testVal1', $this->cache->get('b')); + } + + public function testDeleteLike() : void + { + $this->cache->set('key1', 'testVal1'); + $this->cache->set('key2', 'testVal2'); + self::assertTrue($this->cache->deleteLike('key\d')); + self::assertEquals([], $this->cache->getLike('key\d')); + } + + public function testUpdateExpire() : void + { + $this->cache->set('key2', 'testVal2', 1); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + \sleep(2); + self::assertNull($this->cache->get('key2', 1)); + self::assertTrue($this->cache->updateExpire(10000)); + self::assertEquals('testVal2', $this->cache->get('key2', 1)); + } + /** * @testdox Cache data cannot be added if it already exists * @covers phpOMS\DataStorage\Cache\Connection\RedisCache diff --git a/tests/DataStorage/Database/Schema/BuilderTest.php b/tests/DataStorage/Database/Schema/BuilderTest.php index c7d5bd3a5..c1fbcf5f7 100644 --- a/tests/DataStorage/Database/Schema/BuilderTest.php +++ b/tests/DataStorage/Database/Schema/BuilderTest.php @@ -91,4 +91,37 @@ class BuilderTest extends \PHPUnit\Framework\TestCase ->toSql() ); } + + public function testMysqlAlter() : void + {/* + $query = new Builder($this->con); + $sql = 'CREATE TABLE `user_roles` (`user_id` INT NOT NULL AUTO_INCREMENT, `role_id` VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY (`user_id`), FOREIGN KEY (`user_id`) REFERENCES `users` (`ext1_id`), FOREIGN KEY (`role_id`) REFERENCES `roles` (`ext2_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;'; + self::assertEquals( + $sql, + $query->createTable('user_roles') + ->field('user_id', 'INT', null, false, true, false, true, 'users', 'ext1_id') + ->field('role_id', 'VARCHAR(10)', '1', true, false, false, false, 'roles', 'ext2_id') + ->toSql() + );*/ + } + + + public function testMysqlCreateFromSchema() : void + { + Builder::createFromSchema( + \json_decode( + \file_get_contents(__DIR__ . '/Grammar/testSchema.json'), true + )['test'], + $this->con + ); + + $table = new Builder($this->con); + $tables = $table->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN); + self::assertContains('test', $tables); + self::assertContains('test_foreign', $tables); + + $delete = new Builder($this->con); + $delete->dropTable('test')->execute(); + $delete->dropTable('test_foreign')->execute(); + } } diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index 06f819c84..a8a224d3e 100644 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -21,6 +21,7 @@ use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Router\WebRouter; use phpOMS\Uri\HttpUri; +use phpOMS\Module\ModuleAbstract; require_once __DIR__ . '/../Autoloader.php'; @@ -35,9 +36,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase protected function setUp() : void { - $this->app = new class() extends ApplicationAbstract { - protected string $appName = 'Api'; - }; + $this->app = new class() extends ApplicationAbstract { + protected string $appName = 'Api'; + }; + $this->app->router = new WebRouter(); $this->app->dispatcher = new Dispatcher($this->app); } @@ -52,6 +54,23 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase self::assertObjectHasAttribute('controllers', $this->app->dispatcher); } + public function testControllerInputOutput() : void + { + $this->app->dispatcher->set(new class extends ModuleAbstract { public string $name = 'test'; public function testFunction() { return $this->name; } }, 'test'); + + $localization = new Localization(); + + self::assertTrue( + !empty( + $this->app->dispatcher->dispatch( + 'test:testFunction', + new HttpRequest(new HttpUri(''), $localization), + new HttpResponse($localization) + ) + ) + ); + } + /** * @testdox The dispatcher can dispatch a function/closure * @covers phpOMS\Dispatcher\Dispatcher diff --git a/tests/Message/Mail/EmailTest.php b/tests/Message/Mail/EmailTest.php new file mode 100644 index 000000000..a2b3410b9 --- /dev/null +++ b/tests/Message/Mail/EmailTest.php @@ -0,0 +1,40 @@ + 'Test Name', 'address' => 'test@orange-management.org']], + Email::parseAddresses('Test Name ') + ); + + self::assertEquals( + [['name' => 'Test Name', 'address' => 'test@orange-management.org']], + Email::parseAddresses('Test Name ', false) + ); + } +} diff --git a/tests/Message/Mail/MailHandlerTest.php b/tests/Message/Mail/MailHandlerTest.php index 47c56d350..983215e9c 100644 --- a/tests/Message/Mail/MailHandlerTest.php +++ b/tests/Message/Mail/MailHandlerTest.php @@ -30,13 +30,20 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase { public function testSendTextWithMail() : void { + if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) { + self::markTestSkipped(); + } + $mailer = new MailHandler(); $mailer->setMailer(SubmitType::MAIL); $mail = new Email(); - $mail->setFrom('dennis.eichhorn@orange-management.org', 'Dennis Eichhorn'); - $mail->addTo('info@orange-management.org', 'Dennis Eichhorn'); - $mail->subject = 'Test email'; + $mail->setFrom('info@orange-management.org', 'Dennis Eichhorn'); + $mail->addTo('test@orange-management.email', 'Dennis Eichhorn'); + $mail->addCC('test2@orange-management.email', 'Dennis Eichhorn'); + $mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn'); + $mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn'); + $mail->subject = 'testSendTextWithMail'; $mail->body = 'This is some content'; self::assertTrue($mailer->send($mail)); @@ -44,13 +51,20 @@ class MailHandlerTest extends \PHPUnit\Framework\TestCase public function testSendTextWithSendmail() : void { + if (!\file_exists('/usr/sbin/sendmail') && empty(\ini_get('sendmail_path'))) { + self::markTestSkipped(); + } + $mailer = new MailHandler(); $mailer->setMailer(SubmitType::SENDMAIL); $mail = new Email(); - $mail->setFrom('dennis.eichhorn@orange-management.org', 'Dennis Eichhorn'); - $mail->addTo('info@orange-management.org', 'Dennis Eichhorn'); - $mail->subject = 'Test email'; + $mail->setFrom('info@orange-management.org', 'Dennis Eichhorn'); + $mail->addTo('test@orange-management.email', 'Dennis Eichhorn'); + $mail->addCC('test2@orange-management.email', 'Dennis Eichhorn'); + $mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn'); + $mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn'); + $mail->subject = 'testSendTextWithSendmail'; $mail->body = 'This is some content'; self::assertTrue($mailer->send($mail)); diff --git a/tests/Message/Mail/MailTest.php b/tests/Message/Mail/MailTest.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/Utils/ArrayUtilsTest.php b/tests/Utils/ArrayUtilsTest.php index 5487b534b..d817f3302 100644 --- a/tests/Utils/ArrayUtilsTest.php +++ b/tests/Utils/ArrayUtilsTest.php @@ -313,4 +313,22 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase { self::assertEquals([1, 3, 4], ArrayUtils::abs([-1, 3, -4])); } + + public function testArrayDiffAssocResursive() : void + { + self::assertEquals( + ['a' => 1, 'b' => ['c' => 2]], + ArrayUtils::array_diff_assoc_recursive(['a' => 1, 'b' => ['c' => 2]], []) + ); + + self::assertEquals( + ['b' => ['d' => 3]], + ArrayUtils::array_diff_assoc_recursive(['a' => 1, 'b' => ['c' => 2, 'd' => 3]], ['a' => 1, 'b' => ['c' => 2]]) + ); + + self::assertEquals( + [], + ArrayUtils::array_diff_assoc_recursive([], ['a' => 1, 'b' => ['c' => 2]]) + ); + } } diff --git a/tests/Utils/IO/Csv/CsvSettingsTest.php b/tests/Utils/IO/Csv/CsvSettingsTest.php index 884973094..3f7f5afe2 100644 --- a/tests/Utils/IO/Csv/CsvSettingsTest.php +++ b/tests/Utils/IO/Csv/CsvSettingsTest.php @@ -28,11 +28,19 @@ class CsvSettingsTest extends \PHPUnit\Framework\TestCase * @covers phpOMS\Utils\IO\Csv\CsvSettings * @group framework */ - public function testDelimiter() : void + public function testFileDelimiter() : void { self::assertEquals(':', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/colon.csv', 'r'))); self::assertEquals(',', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/comma.csv', 'r'))); self::assertEquals('|', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/pipe.csv', 'r'))); self::assertEquals(';', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/semicolon.csv', 'r'))); } + + public function testStringDelimiter() : void + { + self::assertEquals(':', CsvSettings::getStringDelimiter(\file_get_contents(__DIR__ . '/colon.csv'))); + self::assertEquals(',', CsvSettings::getStringDelimiter(\file_get_contents(__DIR__ . '/comma.csv'))); + self::assertEquals('|', CsvSettings::getStringDelimiter(\file_get_contents(__DIR__ . '/pipe.csv'))); + self::assertEquals(';', CsvSettings::getStringDelimiter(\file_get_contents(__DIR__ . '/semicolon.csv'))); + } } diff --git a/tests/Validation/Network/HostnameTest.php b/tests/Validation/Network/HostnameTest.php index f065c0fd5..d7fb25650 100644 --- a/tests/Validation/Network/HostnameTest.php +++ b/tests/Validation/Network/HostnameTest.php @@ -28,11 +28,18 @@ class HostnameTest extends \PHPUnit\Framework\TestCase * @covers phpOMS\Validation\Network\Hostname * @group framework */ - public function testHostname() : void + public function testHostnameDomain() : void { self::assertTrue(Hostname::isValid('test.com')); self::assertFalse(Hostname::isValid('http://test.com')); self::assertFalse(Hostname::isValid('test.com/test?something=a')); self::assertFalse(Hostname::isValid('//somethign/wrong')); } + + public function testHostnameIp() : void + { + self::assertTrue(Hostname::isValid('127.0.0.1')); + self::assertTrue(Hostname::isValid('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')); + self::assertFalse(Hostname::isValid('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); + } }