Skip to content

Commit

Permalink
[#WEB-68] - Ajax controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgallego committed Aug 3, 2013
1 parent 8c05e51 commit 718a1c6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/MGP/ImageBundle/Controller/ImageController.php
Expand Up @@ -90,9 +90,6 @@ public function deleteAction($id)
if (!$this->isOwner($image)) {
return $this->redirect($this->generateUrl('home'));
}

$this->checkOwner($image);

$image->setStatus(2);
$em->persist($image);
$em->flush();
Expand Down
17 changes: 17 additions & 0 deletions src/MGP/ImageBundle/Tests/Controller/AjaxControllerTest.php
@@ -0,0 +1,17 @@
<?php

namespace MGP\ImageBundle\Tests\Controller;

use MGP\MainBundle\Tests\Controller\AbstractControllerTest;
use Liip\FunctionalTestBundle\Test\WebTestCase;

class AjaxControllerTest extends AbstractControllerTest
{

public function testUploadWithAnonUser()
{
$this->client->request('GET', '/ajax/images/get_more');
$this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Status 200");
}

}
25 changes: 25 additions & 0 deletions src/MGP/ImageBundle/Tests/Controller/ImageControllerTest.php
Expand Up @@ -101,5 +101,30 @@ public function testEditImageWithCorrectUserAndInvalidData()
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Status 302");
}

public function testDeleteImageWhithAnonUser()
{
$this->client->request('GET', '/img/delete/1');
$this->assertEquals(302, $this->client->getResponse()->getStatusCode(), "Status 302");
}

public function testDeleteImageWithDifferentUser()
{
$client = $this->getLoggedClient('userTest2', 'passwordTest2');
$client->request('GET', '/img/delete/1');
$this->assertEquals(302, $client->getResponse()->getStatusCode(), "Status 302");
$this->assertContains('Redirecting to /', $client->getResponse()->getContent());
}

public function testDeleteImageWithCorrectUser()
{
$client = $this->getLoggedClient();
$crawler = $client->request('GET', '/img/delete/1');
$this->assertEquals(302, $client->getResponse()->getStatusCode(), "Status 200");
$this->assertContains('Redirecting to /', $client->getResponse()->getContent());

$em = $this->getContainer()->get('doctrine')->getManager();
$image = $em->getRepository('MGPImageBundle:Image')->findOneBySlug('title-1');
$this->assertEquals('2', $image->getStatus());
}

}

0 comments on commit 718a1c6

Please sign in to comment.