Files
wallabag-mirror/tests/unit/Entity/EntryTest.php
Jeremy Benoist c2dccb4727 Avoid empty array to be saved in published_by field
Looks like a kind of empty `authors` given from the API can lead to an array of an empty value to be saved in the database.
Also, the default value for the `authors` field in the API can generate that problem too.
2026-11-09 16:54:19 +01:00

47 lines
1.2 KiB
PHP

<?php
namespace Wallabag\Tests\Unit\Entity;
use PHPUnit\Framework\TestCase;
use Wallabag\Entity\Entry;
use Wallabag\Entity\User;
class EntryTest extends TestCase
{
public function testGetLanguage(): void
{
$entry = new Entry(new User());
$languages = [
'en_GB' => 'en-GB',
'en_US' => 'en-US',
'en-gb' => 'en-GB',
'en-US' => 'en-US',
'fr' => 'fr',
'fr_FR' => 'fr-FR',
'ja' => 'ja',
];
foreach ($languages as $entryLang => $lang) {
$entry->setLanguage($entryLang);
$this->assertSame($lang, $entry->getHTMLLanguage());
}
}
public function testSetPublishedByFiltersEmptyAuthors(): void
{
$entry = new Entry(new User());
$entry->setPublishedBy(['', ' bob ', ' ', 'helen']);
$this->assertSame(['bob', 'helen'], $entry->getPublishedBy());
}
public function testSetPublishedByStoresNullWhenOnlyEmptyAuthorsAreProvided(): void
{
$entry = new Entry(new User());
$entry->setPublishedBy(['', ' ']);
$this->assertNull($entry->getPublishedBy());
}
}