test: add feed item test (#3709)

* test: add feed item test

also some refactor

* yup

* yup
This commit is contained in:
Dag 2023-09-25 22:32:15 +02:00 committed by GitHub
parent cd30c25b08
commit f421c45b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 98 additions and 81 deletions

View file

@ -4,6 +4,38 @@ class SfeedFormat extends FormatAbstract
{
const MIME_TYPE = 'text/plain';
public function stringify()
{
$text = '';
foreach ($this->getItems() as $item) {
$text .= sprintf(
"%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n",
$item->toArray()['timestamp'],
preg_replace('/\s/', ' ', $item->toArray()['title']),
$item->toArray()['uri'],
$this->escape($item->toArray()['content']),
$item->toArray()['author'],
$this->getFirstEnclosure(
$item->toArray()['enclosures']
),
$this->escape(
$this->getCategories(
$item->toArray()['categories']
)
)
);
}
// Remove invalid non-UTF8 characters
ini_set('mbstring.substitute_character', 'none');
$text = mb_convert_encoding(
$text,
$this->getCharset(),
'UTF-8'
);
return $text;
}
private function escape(string $str)
{
$str = str_replace('\\', '\\\\', $str);
@ -31,39 +63,4 @@ class SfeedFormat extends FormatAbstract
}
return $toReturn;
}
public function stringify()
{
$items = $this->getItems();
$toReturn = '';
foreach ($items as $item) {
$toReturn .= sprintf(
"%s\t%s\t%s\t%s\thtml\t\t%s\t%s\t%s\n",
$item->toArray()['timestamp'],
preg_replace('/\s/', ' ', $item->toArray()['title']),
$item->toArray()['uri'],
$this->escape($item->toArray()['content']),
$item->toArray()['author'],
$this->getFirstEnclosure(
$item->toArray()['enclosures']
),
$this->escape(
$this->getCategories(
$item->toArray()['categories']
)
)
);
}
// Remove invalid non-UTF8 characters
ini_set('mbstring.substitute_character', 'none');
$toReturn = mb_convert_encoding(
$toReturn,
$this->getCharset(),
'UTF-8'
);
return $toReturn;
}
}
// vi: expandtab