1
0
mirror of https://github.com/Chouchen/ShikiryuRSS.git synced 2024-05-19 06:11:32 +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 * @validate hour
* @format hour * @format hour
*/ */
protected ?string $skipHours = null; protected ?array $skipHours = null;
/** /**
* @validate day * @validate day
* @format day * @format day
*/ */
protected ?string $skipDays = null; protected ?array $skipDays = null;
/** /**
* @return bool * @return bool

View File

@ -110,6 +110,18 @@ class SRSSParser extends DomDocument
} }
$category->value = $child->nodeValue; $category->value = $child->nodeValue;
$this->doc->channel->category = $category; $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 { } else {
$this->doc->channel->{$child->nodeName} = $child->nodeValue; $this->doc->channel->{$child->nodeName} = $child->nodeValue;
} }

View File

@ -143,7 +143,7 @@ class Formator
return $check; 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 private function _validateHour($value): bool
{ {
if (is_array($value)) {
foreach ($value as $val) {
if ($this->_validateHour($val) === false) {
return false;
}
}
return true;
}
$options = [ $options = [
'options' => [ 'options' => [
'min_range' => 0, 'min_range' => 0,
'max_range' => 23 'max_range' => 23
] ]
]; ];
return filter_var($value, FILTER_VALIDATE_INT, $options) !== false; return filter_var($value, FILTER_VALIDATE_INT, $options) !== false;
} }
private function _validateDay($value): bool 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( return in_array(
strtolower($value), strtolower($value),
['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']

View File

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