mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add test for complete activity crud (without errors)
+ fix some errors in controller (discovered with tests)
This commit is contained in:
parent
fa5da95bf1
commit
e79ca23f2c
@ -44,6 +44,12 @@ class ActivityController extends Controller
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachableScopes = $this->get('chill.main.security.authorization.helper')
|
||||
->getReachableScopes($this->getUser(), new Role('CHILL_ACTIVITY_SEE'),
|
||||
$person->getCenter());
|
||||
|
@ -67,6 +67,7 @@ security:
|
||||
intention: authenticate
|
||||
csrf_provider: form.csrf_provider
|
||||
logout: ~
|
||||
http_basic:
|
||||
access_control:
|
||||
#disable authentication for tests
|
||||
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||
|
@ -6,55 +6,113 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class ActivityControllerTest extends WebTestCase
|
||||
{
|
||||
public function testToWrite()
|
||||
|
||||
public function testAccessIsDeniedForUnauthenticated()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$client = $this->createClient();
|
||||
|
||||
$crawler = $client->request('GET', sprintf('fr/person/%d/activity/',
|
||||
$this->getPersonFromFixtures()->getId()));
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect('http://localhost/login'),
|
||||
'the page does not redirect to http://localhost/login');
|
||||
}
|
||||
|
||||
/*
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
// Create a new client to browse the application
|
||||
$client = static::createClient();
|
||||
$client = $this->getAuthenticatedClient();
|
||||
$person = $this->getPersonFromFixtures();
|
||||
|
||||
// Create a new entry in the database
|
||||
$crawler = $client->request('GET', '/activity/');
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /activity/");
|
||||
$crawler = $client->click($crawler->selectLink('Create a new entry')->link());
|
||||
$crawler = $client->request('GET', sprintf('en/person/%d/activity/',
|
||||
$person->getId()));
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /activity/");
|
||||
$crawler = $client->click($crawler->selectLink('Ajouter une nouvelle activité')
|
||||
->link());
|
||||
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Create')->form(array(
|
||||
'chill_activitybundle_activity[field_name]' => 'Test',
|
||||
// ... other fields to fill
|
||||
$form = $crawler->selectButton('Ajouter une nouvelle activité')->form(array(
|
||||
'chill_activitybundle_activity'=> array(
|
||||
'date' => '15-01-2015',
|
||||
'durationTime' => array(
|
||||
'hour' => '1',
|
||||
'minute' => '30'
|
||||
),
|
||||
'remark' => 'blabla',
|
||||
'scope' => 1,
|
||||
'reason' => 2,
|
||||
'type' => 3
|
||||
)
|
||||
));
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect());
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")');
|
||||
$this->assertGreaterThan(0, $crawler->filter('dd:contains("January 15, 2015")')->count(),
|
||||
'Missing element dd:contains("January 15, 2015")');
|
||||
|
||||
// Edit the entity
|
||||
$crawler = $client->click($crawler->selectLink('Edit')->link());
|
||||
|
||||
$form = $crawler->selectButton('Update')->form(array(
|
||||
'chill_activitybundle_activity[field_name]' => 'Foo',
|
||||
// ... other fields to fill
|
||||
$crawler = $client->click($crawler->selectLink("Modifier l'activité")->link());
|
||||
|
||||
$form = $crawler->selectButton("Sauver l'activité")->form(array(
|
||||
'chill_activitybundle_activity' => array(
|
||||
'date' => '25-01-2015',
|
||||
'remark' => 'Foo'
|
||||
)
|
||||
));
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect());
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]');
|
||||
|
||||
// Delete the entity
|
||||
$client->submit($crawler->selectButton('Delete')->form());
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check the entity has been delete on the list
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
|
||||
// check that new data are present
|
||||
$this->assertGreaterThan(0,
|
||||
$crawler->filter('dd:contains("January 25, 2015")')->count(),
|
||||
'Missing element dd:contains("January 25, 2015")');
|
||||
$this->assertGreaterThan(0,
|
||||
$crawler->filter('dd:contains("Foo")')->count(),
|
||||
'Missing element dd:contains("Foo")');
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\BrowserKit\Client
|
||||
*/
|
||||
private function getAuthenticatedClient()
|
||||
{
|
||||
return static::createClient(array(), array(
|
||||
'PHP_AUTH_USER' => 'center a_social',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Chill\PersonBundle\Entity\Person
|
||||
*/
|
||||
private function getPersonFromFixtures()
|
||||
{
|
||||
$em = static::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')
|
||||
->findOneBy(array(
|
||||
'firstName' => 'Depardieu',
|
||||
'lastName' => 'Gérard'
|
||||
));
|
||||
|
||||
if ($person === NULL) {
|
||||
throw new \RuntimeException("We need a person with firstname Gérard and"
|
||||
. " lastname Depardieu. Did you add fixtures ?");
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user