use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Form\Type\NewEntryType;
use Wallabag\CoreBundle\Form\Type\EditEntryType;
}
/**
- * Deletes entry and redirect to the homepage.
+ * Deletes entry and redirect to the homepage or the last viewed page.
*
* @param Entry $entry
*
{
$this->checkUserAction($entry);
+ // generates the view url for this entry to check for redirection later
+ // to avoid redirecting to the deleted entry. Ugh.
+ $url = $this->generateUrl(
+ 'view',
+ array('id' => $entry->getId()),
+ UrlGeneratorInterface::ABSOLUTE_URL
+ );
+
$em = $this->getDoctrine()->getManager();
$em->remove($entry);
$em->flush();
'Entry deleted'
);
- return $this->redirect($request->headers->get('referer'));
+ // don't redirect user to the deleted entry
+ return $this->redirect($url !== $request->headers->get('referer') ?: $this->generateUrl('homepage'));
}
/**
namespace Wallabag\CoreBundle\Tests\Controller;
use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
+use Wallabag\CoreBundle\Entity\Entry;
class EntryControllerTest extends WallabagCoreTestCase
{
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}
+ /**
+ * It will create a new entry.
+ * Browse to it.
+ * Then remove it.
+ *
+ * And it'll check that user won't be redirected to the view page of the content when it had been removed
+ */
+ public function testViewAndDelete()
+ {
+ $this->logInAs('admin');
+ $client = $this->getClient();
+
+ // add a new content to be removed later
+ $user = $client->getContainer()
+ ->get('doctrine.orm.entity_manager')
+ ->getRepository('WallabagUserBundle:User')
+ ->findOneByUserName('admin');
+
+ $content = new Entry($user);
+ $content->setUrl('http://1.1.1.1/entry');
+ $content->setReadingTime(12);
+ $content->setDomainName('domain.io');
+ $content->setMimetype('text/html');
+ $content->setTitle('test title entry');
+ $content->setContent('This is my content /o/');
+ $content->setArchived(true);
+ $content->setLanguage('fr');
+
+ $client->getContainer()
+ ->get('doctrine.orm.entity_manager')
+ ->persist($content);
+ $client->getContainer()
+ ->get('doctrine.orm.entity_manager')
+ ->flush();
+
+ $client->request('GET', '/view/'.$content->getId());
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+
+ $client->request('GET', '/delete/'.$content->getId());
+ $this->assertEquals(302, $client->getResponse()->getStatusCode());
+
+ $client->followRedirect();
+ $this->assertEquals(200, $client->getResponse()->getStatusCode());
+ }
+
public function testViewOtherUserEntry()
{
$this->logInAs('admin');