$this->updateEntry($entry, 'entry_reloaded');
+ // if refreshing entry failed, don't save it
+ if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
+ $bag = $this->get('session')->getFlashBag();
+ $bag->clear();
+ $bag->add('notice', 'flashes.entry.notice.entry_reloaded_failed');
+
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
+ }
+
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
$em->flush();
$container->setParameter('wallabag_core.version', $config['version']);
$container->setParameter('wallabag_core.paypal_url', $config['paypal_url']);
$container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']);
+ $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$content = $em
->getRepository('WallabagCoreBundle:Entry')
- ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
+ ->find($content->getId());
$this->assertNotEmpty($content->getContent());
}
+ /**
+ * @depends testPostNewOk
+ *
+ * This test will require an internet connection.
+ */
+ public function testReloadWithFetchingFailed()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $em = $client->getContainer()
+ ->get('doctrine.orm.entity_manager');
+
+ $content = $em
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
+
+ // put a known failed url
+ $content->setUrl('http://0.0.0.0/failed.html');
+ $em->persist($content);
+ $em->flush();
+
+ $client->request('GET', '/reload/'.$content->getId());
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ // force EntityManager to clear previous entity
+ // otherwise, retrieve the same entity will retrieve change from the previous request :0
+ $em->clear();
+ $newContent = $em
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->find($content->getId());
+
+ $newContent->setUrl($this->url);
+ $em->persist($newContent);
+ $em->flush();
+
+ $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
+ }
+
public function testEdit()
{
$this->logInAs('admin');