Skip to content

Instantly share code, notes, and snippets.

@benoitMariaux
Created November 21, 2013 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitMariaux/7581619 to your computer and use it in GitHub Desktop.
Save benoitMariaux/7581619 to your computer and use it in GitHub Desktop.
<?php
namespace Ylly\Extension\YllyEcommerceBundle\Tests\Controller;
use Ylly\CmsBundle\Test\SiteWebTestCase;
use Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer;
use Ylly\Extension\YllyEcommerceBundle\DataInitializer\DataInitializer;
/**
* @group site
*/
class SiteController_orderTest extends SiteWebTestCase
{
protected $fixturesClasses;
protected $site;
protected $urlParams;
public function __construct()
{
$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\YllyEcommerceBundle\Tests\Fixtures\ORM\LoadBaseData',
'Ylly\Extension\YllyEcommerceBundle\Tests\Fixtures\ORM\LoadProductData',
);
$this->urlParams = array(
'site_id' => 2,
'_locale' => 'fr',
);
}
public function setUp()
{
$this->loadFixtures($this->fixturesClasses);
}
// public function testSiteIndex()
// {
// $url = $this->getUrl('ecommerce_store_index', $this->getUrlParams());
// $client = $this->makeClient();
// $client->request('GET', $url);
//
// $this->assertTrue($client->getResponse()->isRedirect());
//
// $redirectedUrl = $this->getUrl('ecommerce_store_root_categories', array('_locale' => 'fr'));
// $this->assertTrue($client->getResponse()->isRedirect($redirectedUrl));
// }
//
// public function testShowProduct()
// {
// $url = $this->getUrl('ecommerce_store_root_categories', $this->getUrlParams());
//
// $content = $this->fetchContent($url);
// $this->assertContains('Chocolats', $content);
//
// $cat = $this->getCategoryRepo()->findOneByName('Chocolats');
//
// $url = $this->getUrl('ecommerce_store_category', array_merge($this->getUrlParams(), array(
// 'category_id' => $cat->getId(),
// 'slug' => $cat->getSlug(),
// )));
//
// $content = $this->fetchContent($url);
//
// $this->assertContains('Noir intense', $content);
//
// $product = $this->getProductRepo()->findOneByTitle('Noir intense');
//
// $url = $this->getUrl('ecommerce_store_product', array_merge($this->getUrlParams(), array(
// 'product_id' => $product->getId(),
// 'slug' => $product->getSlug(),
// )));
//
// $content = $this->fetchContent($url);
//
// $this->assertContains('Ajouter au panier', $content);
// }
// public function testAddProductToCart()
// {
// $product = $this->getProductRepo()->findOneByTitle('Noir intense');
//
// $url = $this->getUrl('ecommerce_add_to_cart', array_merge($this->getUrlParams(), array(
// 'product_id' => $product->getId(),
// )));
//
// $client = $this->makeClient();
// $client->request('GET', $url);
//
// $redirectUrl = $this->getUrl('ecommerce_store_product', array(
// '_locale' => 'fr',
// 'product_id' => $product->getId(),
// 'slug' => $product->getSlug(),
// ));
//
// $this->assertTrue($client->getResponse()->isRedirect($redirectUrl));
// }
public function testRegistration()
{
$userCases = array(
array(
'siteId' => 2,
'email' => 'aaa@aaa.aa',
'countryId' => '1',
'mustBeOk' => true,
),
// array(
// 'siteId' => 3,
// 'email' => 'aaa@aaa.aa', // same email in 2 different sites
// 'countryId' => '2',
// 'mustBeOk' => true
// ),
// array(
// 'siteId' => 2,
// 'email' => 'aaa@aaa.aa',
// 'countryId' => '1',
// 'mustBeOk' => false,
// ),
// array(
// 'siteId' => 3,
// 'email' => 'aaa@aaa.aa',
// 'countryId' => '2',
// 'mustBeOk' => false,
// ),
);
foreach ($userCases as $c) {
$url = $this->getUrl('ecommerce_user_register', array(
'site_id' => $c['siteId'],
'_locale' => 'fr'), true);
$client = $this->makeClient();
$client->followRedirects();
$crawler = $client->request('GET', $url);
$form = $crawler->filter('input[type=submit]')->form();
$form['ecommerce_customer_register[user][email]'] = $c['email'];
$form['ecommerce_customer_register[user][plainPassword][first]'] = "aaa";
$form['ecommerce_customer_register[user][plainPassword][second]'] = "aaa";
$form['ecommerce_customer_register[user][firstName]'] = "Sergei";
$form['ecommerce_customer_register[user][lastName]'] = "Rachmaninov";
$form['ecommerce_customer_register[user][phone]'] = "0987654321";
$form['ecommerce_customer_register[user][delivery_postal_code]'] = "75005";
$form['ecommerce_customer_register[user][delivery_town]'] = "Paris";
$form['ecommerce_customer_register[user][delivery_country]']->select($c['countryId']);
$form['ecommerce_customer_register[user][delivery_address]'] = "123, rue du soleil levant";
// $form['ecommerce_customer_register[user][billing_postal_code]'] = "75005";
// $form['ecommerce_customer_register[user][billing_town]'] = "Paris";
// $form['ecommerce_customer_register[user][billing_country]']->select($c['countryId']);
// $form['ecommerce_customer_register[user][billing_address]'] = "123, rue du soleil levant";
$crawler = $client->submit($form);
$content = $client->getResponse()->getContent();
/// DANIEL => Cannot set session ID after the session has started.
file_put_contents('testcontent.html',$content);
/// DANIEL => 500
die(var_dump($client->getResponse()->getStatusCode()));
$params = array("ecommerce_customer_register" => array(
"user" => array(
"email" => $c['email'],
"plainPassword" => array(
"first" => "aaa",
"second" => "aaa"
),
"firstName" => "aaa",
"lastName" => "aaa",
"phone" => "0987654321",
"delivery_postal_code" => "75005",
"delivery_town" => "Paris",
"delivery_country" => "1",
"delivery_address" => "123, rue du soleil levant",
)
));
$crawler = $client->request('POST', $url, $params);
$res = $client->getResponse();
// $this->assertTrue($client->getResponse()->isRedirect());
// $url = $this->getUrl('ecommerce_check_details', array(
// 'site_id' => $c['siteId'],
// '_locale' => 'fr'));
//
// $crawler = $client->request('GET', $url);
// $res = $client->getResponse();
// $content = $res->getContent();
if ($c['mustBeOk']) {
// $this->assertTrue($client->getContainer()->get('security.context')->isGranted(SiteCustomer::ROLE_SITE_CUSTOMER));
// $this->assertTrue(strstr($content,"Vous êtes aaa aaa, si ce n'est pas le cas,") ? true : false);
// $this->assertTrue(strstr($content,"Poursuivre ma commande >") ? true : false);
// } else {
// $this->assertFalse($client->getContainer()->get('security.context')->isGranted(SiteCustomer::ROLE_SITE_CUSTOMER));
// $this->assertFalse(strstr($content,"Vous êtes aaa aaa, si ce n'est pas le cas,") ? true : false);
// $this->assertFalse(strstr($content,"Poursuivre ma commande >") ? true : false);
// $this->assertTrue(strstr($content, "Cet email est déjà utilisé") ? true : false);
}
}
}
public function setUrlParams($urlParams)
{
$this->urlParams = $urlParams;
}
public function getUrlParams()
{
return $this->urlParams;
}
protected function getCategoryRepo()
{
return $this->getEm()->getRepository('Ylly\Extension\YllyEcommerceBundle\Entity\Category');
}
protected function getProductRepo()
{
return $this->getEm()->getRepository('Ylly\Extension\YllyEcommerceBundle\Entity\Product');
}
protected function getSiteCustomerRepo()
{
return $this->getEm()->getRepository('Ylly\Extension\SiteCustomerBundle\Entity\SiteCustomer');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment