1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-05-07 14:41:31 +02:00

🧪 Failing tests makes somes rules pop better

This commit is contained in:
Clement Desmidt 2023-04-19 16:50:44 +02:00
parent 0935c343ea
commit e51ee110a3
5 changed files with 38 additions and 5 deletions

View File

@ -96,12 +96,12 @@ class Channel extends HasValidator implements SRSSElement
* @validate hour
* @format hour
*/
protected ?string $skipHours = null;
protected ?array $skipHours = null;
/**
* @validate day
* @format day
*/
protected ?string $skipDays = null;
protected ?array $skipDays = null;
/**
* @return bool

View File

@ -110,6 +110,18 @@ class SRSSParser extends DomDocument
}
$category->value = $child->nodeValue;
$this->doc->channel->category = $category;
} elseif ($child->nodeName === 'skipHours') {
foreach ($child->childNodes as $hour) {
if ($hour->nodeType === XML_ELEMENT_NODE) {
$this->doc->channel->skipHours = $hour->nodeValue;
}
}
} elseif ($child->nodeName === 'skipDays') {
foreach ($child->childNodes as $day) {
if ($day->nodeType === XML_ELEMENT_NODE) {
$this->doc->channel->skipDays = $day->nodeValue;
}
}
} else {
$this->doc->channel->{$child->nodeName} = $child->nodeValue;
}

View File

@ -143,7 +143,7 @@ class Formator
return $check;
}
return sprintf('<![CDATA[ %s ]]>', htmlspecialchars($check));
return sprintf('<![CDATA[ %s ]]>', $check);
}
/**

View File

@ -201,17 +201,38 @@ class Validator
private function _validateHour($value): bool
{
if (is_array($value)) {
foreach ($value as $val) {
if ($this->_validateHour($val) === false) {
return false;
}
}
return true;
}
$options = [
'options' => [
'min_range' => 0,
'max_range' => 23
]
];
return filter_var($value, FILTER_VALIDATE_INT, $options) !== false;
}
private function _validateDay($value): bool
{
if (is_array($value)) {
foreach ($value as $val) {
if ($this->_validateDay($val) === false) {
return false;
}
}
return true;
}
return in_array(
strtolower($value),
['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']

View File

@ -37,8 +37,8 @@ class CompleteBuilderTest extends TestCase
$image->title = 'title of image';
$rating = 'yes';
$textInput = 'ignore';
$skipDays = 'monday';
$skipHours = '8';
$skipDays = ['monday'];
$skipHours = ['8', '9'];
$srss = SRSS::create();
$srss->title = $title;