+
+ public function testNewEntryWithDownloadImagesEnabled()
+ {
+ $this->downloadImagesEnabled = true;
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
+ $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
+
+ $crawler = $client->request('GET', '/new');
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+ $form = $crawler->filter('form[name=entry]')->form();
+
+ $data = [
+ 'entry[url]' => $url,
+ ];
+
+ $client->submit($form, $data);
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $em = $client->getContainer()
+ ->get('doctrine.orm.entity_manager');
+
+ $entry = $em
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+ $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
+ $this->assertEquals($url, $entry->getUrl());
+ $this->assertContains('Perpignan', $entry->getTitle());
+ // instead of checking for the filename (which might change) check that the image is now local
+ $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent());
+
+ $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
+ }
+
+ /**
+ * @depends testNewEntryWithDownloadImagesEnabled
+ */
+ public function testRemoveEntryWithDownloadImagesEnabled()
+ {
+ $this->downloadImagesEnabled = true;
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
+ $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
+
+ $crawler = $client->request('GET', '/new');
+
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+ $form = $crawler->filter('form[name=entry]')->form();
+
+ $data = [
+ 'entry[url]' => $url,
+ ];
+
+ $client->submit($form, $data);
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $content = $client->getContainer()
+ ->get('doctrine.orm.entity_manager')
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->findByUrlAndUserId($url, $this->getLoggedInUserId());
+
+ $client->request('GET', '/delete/'.$content->getId());
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
+ }
+
+ public function testRedirectToHomepage()
+ {
+ $this->logInAs('empty');
+ $client = $this->getClient();
+
+ // Redirect to homepage
+ $config = $this->getLoggedInUser()->getConfig();
+ $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
+ $this->getEntityManager()->persist($config);
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl($this->url);
+ $this->getEntityManager()->persist($entry);
+
+ $this->getEntityManager()->flush();
+
+ $client->request('GET', '/view/'.$entry->getId());
+ $client->request('GET', '/archive/'.$entry->getId());
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+ $this->assertEquals('/', $client->getResponse()->headers->get('location'));
+ }
+
+ public function testRedirectToCurrentPage()
+ {
+ $this->logInAs('empty');
+ $client = $this->getClient();
+
+ // Redirect to current page
+ $config = $this->getLoggedInUser()->getConfig();
+ $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
+ $this->getEntityManager()->persist($config);
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl($this->url);
+ $this->getEntityManager()->persist($entry);
+
+ $this->getEntityManager()->flush();
+
+ $client->request('GET', '/view/'.$entry->getId());
+ $client->request('GET', '/archive/'.$entry->getId());
+
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+ $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location'));
+ }
+
+ public function testFilterOnHttpStatus()
+ {
+ $this->logInAs('admin');
+ $this->useTheme('baggy');
+ $client = $this->getClient();
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
+ $entry->setHttpStatus(404);
+ $this->getEntityManager()->persist($entry);
+
+ $this->getEntityManager()->flush();
+
+ $crawler = $client->request('GET', '/all/list');
+ $form = $crawler->filter('button[id=submit-filter]')->form();
+
+ $data = [
+ 'entry_filter[httpStatus]' => 404,
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl($this->url);
+ $entry->setHttpStatus(200);
+ $this->getEntityManager()->persist($entry);
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
+ $entry->setHttpStatus(200);
+ $this->getEntityManager()->persist($entry);
+
+ $this->getEntityManager()->flush();
+
+ $crawler = $client->request('GET', '/all/list');
+ $form = $crawler->filter('button[id=submit-filter]')->form();
+
+ $data = [
+ 'entry_filter[httpStatus]' => 200,
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(2, $crawler->filter('div[class=entry]'));
+
+ $crawler = $client->request('GET', '/all/list');
+ $form = $crawler->filter('button[id=submit-filter]')->form();
+
+ $data = [
+ 'entry_filter[httpStatus]' => 1024,
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(8, $crawler->filter('div[class=entry]'));
+ }
+
+ public function testSearch()
+ {
+ $this->logInAs('admin');
+ $this->useTheme('baggy');
+ $client = $this->getClient();
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl($this->url);
+ $entry->setTitle('test');
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+
+ // Search on unread list
+ $crawler = $client->request('GET', '/unread/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'title',
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(4, $crawler->filter('div[class=entry]'));
+
+ // Search on starred list
+ $crawler = $client->request('GET', '/starred/list');
+
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://localhost/foo/bar');
+ $entry->setTitle('testeur');
+ $entry->setStarred(true);
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'testeur',
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+
+ $crawler = $client->request('GET', '/archive/list');
+
+ // Added new article to test on archive list
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://0.0.0.0/foo/baz/qux');
+ $entry->setTitle('Le manège');
+ $entry->setArchived(true);
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'manège',
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+ $client->request('GET', '/delete/'.$entry->getId());
+
+ // test on list of all articles
+ $crawler = $client->request('GET', '/all/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(0, $crawler->filter('div[class=entry]'));
+
+ // test url search on list of all articles
+ $entry = new Entry($this->getLoggedInUser());
+ $entry->setUrl('http://domain/qux');
+ $entry->setTitle('Le manège');
+ $entry->setArchived(true);
+ $this->getEntityManager()->persist($entry);
+ $this->getEntityManager()->flush();
+
+ $crawler = $client->request('GET', '/all/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+
+ // same as previous test but for case-sensitivity
+ $crawler = $client->request('GET', '/all/list');
+
+ $form = $crawler->filter('form[name=search]')->form();
+ $data = [
+ 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
+ ];
+
+ $crawler = $client->submit($form, $data);
+
+ $this->assertCount(1, $crawler->filter('div[class=entry]'));
+ }