mirror of
https://github.com/Chouchen/ShikiryuRSS.git
synced 2024-05-19 06:11:32 +02:00
parent
58e0866b46
commit
cae3c6f2dc
|
@ -31,7 +31,7 @@ class Validator
|
|||
}
|
||||
$propertyAnnotations = $this->_getPropertyAnnotations($property);
|
||||
|
||||
if (empty($value) && !in_array('required', $propertyAnnotations, true)) {
|
||||
if (empty($value) && count(array_filter($property['rules'], static fn($rule) => str_starts_with($rule, 'required'))) === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,9 @@ class Validator
|
|||
*/
|
||||
public function isObjectValid($object): bool
|
||||
{
|
||||
if (!$object->validated) {
|
||||
// if (!$object->validated) {
|
||||
$object = $this->validateObject($object);
|
||||
}
|
||||
// }
|
||||
|
||||
return !in_array(false, $object->validated, true);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class Validator
|
|||
foreach ($properties as $property) {
|
||||
$propertyValue = $object->{$property['name']};
|
||||
|
||||
if (empty($propertyValue) && !in_array('required', $property['rules'], true)) {
|
||||
if (empty($propertyValue) && count(array_filter($property['rules'], static fn($rule) => str_starts_with($rule, 'required'))) === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ class Validator
|
|||
|
||||
$args_annotation = array_splice($annotation, 1);
|
||||
|
||||
return $this->{sprintf('_validate%s', ucfirst($annotation[0]))}($property, ...$args_annotation);
|
||||
return $this->{sprintf('_validate%s', ucfirst($annotation[0]))}($property, $args_annotation);
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,7 +199,6 @@ class Validator
|
|||
{
|
||||
$options = [
|
||||
'options' => [
|
||||
'default' => 0,
|
||||
'min_range' => 0,
|
||||
'max_range' => 23
|
||||
]
|
||||
|
|
114
tests/FailingTest.php
Normal file
114
tests/FailingTest.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shikiryu\SRSS\SRSS;
|
||||
|
||||
class FailingTest extends TestCase
|
||||
{
|
||||
private ?SRSS $srss;
|
||||
|
||||
public function testInvalidChannel()
|
||||
{
|
||||
$this->srss = SRSS::create();
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->title = 'title'; // mandatory
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->description = 'desc'; // mandatory
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->link = 'desc'; // mandatory but should be a url
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->link = 'https://example.org';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->language = 'en-en'; // should be a valid language
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->language = 'en-us'; // should be a valid
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->copyright = '<strong>test</strong>'; // should not have html element
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->copyright = 'shikiryu';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->managingEditor = '<strong>test</strong>'; // should not have html element
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->managingEditor = 'shikiryu';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->webMaster = '<strong>test</strong>'; // should not have html element
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->webMaster = 'shikiryu';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->pubDate = 'test'; // should be a valid date
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->pubDate = (new DateTime())->format(DATE_RSS);
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->lastBuildDate = 'test'; // should be a valid date
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->lastBuildDate = (new DateTime())->format(DATE_RSS);
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->generator = '<strong>test</strong>'; // should not have html element
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->generator = 'shikiryuRSS';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->docs = 'desc'; //should be a url
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->docs = 'https://example.org';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->ttl = 'desc'; // should be an int
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->ttl = '85';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
// rating and textInput not tested because there's no validation
|
||||
|
||||
$this->srss->skipHours = 'desc'; // should be an hour
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->skipHours = '12';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
|
||||
$this->srss->skipDays = 'desc'; // should be a day
|
||||
self::assertFalse($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
$this->srss->skipDays = 'monday';
|
||||
self::assertTrue($this->srss->isValid(), var_export($this->srss->validated, true));
|
||||
}
|
||||
|
||||
public function testItem()
|
||||
{
|
||||
$item = new Shikiryu\SRSS\Entity\Item();
|
||||
|
||||
self::assertFalse($item->isValid(), var_export($item->validated, true));
|
||||
$item->title = 'title';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
|
||||
$item->link = 'test';
|
||||
self::assertFalse($item->isValid(), var_export($item->validated, true));
|
||||
$item->link = 'https://example.org/link1';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
|
||||
$item->title = null;
|
||||
self::assertFalse($item->isValid(), var_export($item->validated, true));
|
||||
$item->description = 'desc';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
$item->title = 'title';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
|
||||
$item->author = 'test';
|
||||
self::assertFalse($item->isValid(), var_export($item->validated, true));
|
||||
$item->author = 'email@example.org';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
|
||||
$item->comments = 'test';
|
||||
self::assertFalse($item->isValid(), var_export($item->validated, true));
|
||||
$item->comments = 'https://example.org/link1';
|
||||
self::assertTrue($item->isValid(), var_export($item->validated, true));
|
||||
|
||||
// guid is not validated and, so, not tested
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user