mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 19:11:07 +00:00
Add a test for updatePublishedAt
To avoid error when a content is re-submitted and it previously add a published date. Also, fix the `testPostSameEntry`
This commit is contained in:
parent
b236d3f627
commit
ff9f89fd23
2 changed files with 43 additions and 3 deletions
|
@ -122,15 +122,21 @@ class ContentProxy
|
||||||
*/
|
*/
|
||||||
public function updatePublishedAt(Entry $entry, $value)
|
public function updatePublishedAt(Entry $entry, $value)
|
||||||
{
|
{
|
||||||
$date = $value instanceof \DateTime ? $value->date : $value;
|
$date = $value;
|
||||||
|
|
||||||
// is it a timestamp?
|
// is it a timestamp?
|
||||||
if (filter_var($date, FILTER_VALIDATE_INT) !== false) {
|
if (filter_var($date, FILTER_VALIDATE_INT) !== false) {
|
||||||
$date = '@' . $value;
|
$date = '@' . $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$entry->setPublishedAt(new \DateTime($date));
|
// is it already a DateTime?
|
||||||
|
// (it's inside the try/catch in case of fail to be parse time string)
|
||||||
|
if (!$date instanceof \DateTime) {
|
||||||
|
$date = new \DateTime($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry->setPublishedAt($date);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]);
|
$this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,6 +421,16 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
||||||
|
|
||||||
public function testPostSameEntry()
|
public function testPostSameEntry()
|
||||||
{
|
{
|
||||||
|
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||||
|
$entry = new Entry($em->getReference(User::class, 1));
|
||||||
|
$entry->setUrl('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html');
|
||||||
|
$entry->setArchived(true);
|
||||||
|
$entry->addTag((new Tag())->setLabel('google'));
|
||||||
|
$entry->addTag((new Tag())->setLabel('apple'));
|
||||||
|
$em->persist($entry);
|
||||||
|
$em->flush();
|
||||||
|
$em->clear();
|
||||||
|
|
||||||
$this->client->request('POST', '/api/entries.json', [
|
$this->client->request('POST', '/api/entries.json', [
|
||||||
'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html',
|
'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html',
|
||||||
'archive' => '1',
|
'archive' => '1',
|
||||||
|
@ -1046,4 +1056,28 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
||||||
$this->assertSame(400, $this->client->getResponse()->getStatusCode());
|
$this->assertSame(400, $this->client->getResponse()->getStatusCode());
|
||||||
$this->assertContains('API limit reached', $this->client->getResponse()->getContent());
|
$this->assertContains('API limit reached', $this->client->getResponse()->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRePostEntryAndReUsePublishedAt()
|
||||||
|
{
|
||||||
|
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||||
|
$entry = new Entry($em->getReference(User::class, 1));
|
||||||
|
$entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
|
||||||
|
$entry->setContent('hihi');
|
||||||
|
$entry->setUrl('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html');
|
||||||
|
$entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
|
||||||
|
$em->persist($entry);
|
||||||
|
$em->flush();
|
||||||
|
$em->clear();
|
||||||
|
|
||||||
|
$this->client->request('POST', '/api/entries.json', [
|
||||||
|
'url' => 'http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||||
|
|
||||||
|
$this->assertGreaterThan(0, $content['id']);
|
||||||
|
$this->assertSame('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html', $content['url']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue