Created
November 21, 2013 13:51
-
-
Save benoitMariaux/7581865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ylly\Extension\ReminderBundle\Tests\Controller; | |
use Ylly\CmsBundle\Test\SiteWebTestCase; | |
use Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer; | |
/** | |
* @group site | |
*/ | |
class SiteController_subscribeVetTest extends SiteWebTestCase | |
{ | |
protected $fixturesClasses; | |
protected $em; | |
protected $siteCustomerRepo; | |
public function setUp() | |
{ | |
$this->fixturesClasses = array( | |
'Ylly\CmsBundle\Tests\Fixtures\ORM\LoadSiteData', | |
'Ylly\CrmBundle\Tests\Fixtures\ORM\LoadUserData', | |
'Ylly\Extension\LocationBundle\Tests\Fixtures\ORM\LoadLocationData', | |
'Ylly\ThemeBundle\Tests\Fixtures\ORM\LoadThemeData', | |
'Ylly\Extension\ThemeBundle\Tests\Fixtures\ORM\LoadThemeData', | |
'Ylly\Extension\ContactFormBundle\Tests\Fixtures\ORM\LoadContactFormData', | |
'Ylly\Extension\TeamBundle\Tests\Fixtures\ORM\LoadTeamData', | |
); | |
$this->loadFixtures($this->fixturesClasses); | |
$this->em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); | |
$this->siteCustomerRepo = $this->em->getRepository('Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer'); | |
} | |
public function testValid() | |
{ | |
$userCases = array( | |
array( | |
'siteId' => 2, | |
'email' => 'aaa@aaa.aa', | |
'mustBeOk' => true, | |
), | |
array( | |
'siteId' => 3, | |
'email' => 'aaa@aaa.aa', // same email in 2 different sites | |
'mustBeOk' => true | |
), | |
array( | |
'siteId' => 2, | |
'email' => 'aaa@aaa.aa', | |
'mustBeOk' => false, | |
), | |
array( | |
'siteId' => 3, | |
'email' => 'aaa@aaa.aa', | |
'mustBeOk' => false, | |
), | |
); | |
foreach ($userCases as $c) { | |
$url = $this->getUrl('customer_reminder_index_vet', array( | |
'site_id' => $c['siteId'], | |
'_locale' => 'fr')); | |
$client = $this->makeClient(); | |
$client->followRedirects(); | |
$params = array ( | |
'vet_reminder' => array ( | |
'siteCustomer' => array ( | |
'email' => $c['email'], | |
'plainPassword' => array ( | |
'first' => 'aaa', | |
'second' => 'aaa', | |
), | |
'firstName' => 'aaaa', | |
'lastName' => 'aaaa', | |
'phone' => 'aaa', | |
), | |
'yourPetIsA' => 'Chien', | |
'yourPetsName' => 'aaaa', | |
'lastVaccineDate' => array ( | |
'day' => '10', | |
'month' => '6', | |
'year' => '2009', | |
), | |
'externalAntiparasiticTreatmentDate' => array ( | |
'day' => '5', | |
'month' => '5', | |
'year' => '2011', | |
), | |
'internalAntiparasiticTreatmentDate' => array ( | |
'day' => '16', | |
'month' => '4', | |
'year' => '2010', | |
), | |
'lastCheckUpHealthDate' => array ( | |
'day' => '14', | |
'month' => '5', | |
'year' => '2010', | |
), | |
'lastCheckUpHealthFrequency' => '6 months', | |
'wantNewsletter' => '1', | |
), | |
); | |
$crawler = $client->request('POST', $url, $params); | |
$res = $client->getResponse(); | |
$content = $res->getContent(); | |
$customer = $this->siteCustomerRepo->findOneBy(array( | |
'site' => $c['siteId'], | |
'email' => $c['email'] | |
)); | |
$this->assertEquals(200, $res->getStatusCode()); | |
$this->assertNotNull($customer); | |
if ($c['mustBeOk']) { | |
$this->assertTrue($client->getContainer()->get('security.context')->isGranted(SiteCustomer::ROLE_SITE_CUSTOMER)); | |
$this->assertTrue(strstr($content,'Vos demandes de rappel ont bien été prises en compte') ? true : false); | |
} else { | |
$this->assertFalse($client->getContainer()->get('security.context')->isGranted(SiteCustomer::ROLE_SITE_CUSTOMER)); | |
$this->assertFalse(strstr($content, 'Vos demandes de rappel ont bien été prises en compte') ? true : false); | |
$this->assertTrue(strstr($content, "Ce nom d'utilisateur est déjà utilisé") ? true : false); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment