parent
b2e7ce5f01
commit
8f1de50e79
@ -1,19 +1,20 @@ |
||||
Feature: Course User Relationship |
||||
In order to setup a course subscription |
||||
@course |
||||
Feature: Course user relationship |
||||
In order to setup add a user to a course |
||||
As a teacher |
||||
I need a working relationship |
||||
|
||||
Background: |
||||
Given there are following users: |
||||
| username | email | plain_password | enabled | |
||||
| student | student@example.com | student | yes | |
||||
| teacher | teacher@example.com | teacher | yes | |
||||
# Given there are following users: |
||||
# | username | email | plain_password | enabled | |
||||
# | student | student@example.com | student | yes | |
||||
# | teacher | teacher@example.com | teacher | yes | |
||||
Given I have a course "My course" |
||||
|
||||
Scenario: A course contains a user |
||||
Scenario: A course contains a student |
||||
When I add student "student" to course "My course" |
||||
Then I should find a user "student" in course "My course" |
||||
Then I should find a student "student" in course "My course" |
||||
|
||||
Scenario: A course contains a user |
||||
Scenario: A course contains a teacher |
||||
When I add teacher "teacher" to course "My course" |
||||
Then I should find a user "teacher" in course "My course" |
||||
Then I should find a teacher "teacher" in course "My course" |
||||
|
@ -0,0 +1,12 @@ |
||||
@user |
||||
Feature: Admin dashboard protection |
||||
In order to protect admin |
||||
As a user |
||||
I need to forbid access to admin from basic user |
||||
|
||||
Scenario: Try to access admin with simple account |
||||
Given I am logged in as Student |
||||
When I fill in "_username" with "<username>" |
||||
And I fill in "_password" with "<password>" |
||||
And I press "_submit" |
||||
Then I should see "<message>" |
@ -0,0 +1,23 @@ |
||||
@user |
||||
Feature: User login |
||||
In order to have access to a course |
||||
As a user |
||||
I need to be able to login |
||||
|
||||
Background: |
||||
Given there are following users: |
||||
| username | email |plain_password| enabled | group | |
||||
| student_behat | student_behat@example.com |student_behat| yes | students | |
||||
|
||||
@javascript |
||||
Scenario Outline: Existing user can login |
||||
Given I am on the login page |
||||
When I fill in "_username" with "<username>" |
||||
And I fill in "_password" with "<password>" |
||||
And I press "_submit" |
||||
Then I should see "<message>" |
||||
|
||||
Examples: |
||||
| username | password | message | |
||||
| student_behat | student_behat | Logout | |
||||
| pirate | pirate | Bad credentials | |
@ -0,0 +1,327 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Behat; |
||||
|
||||
use Behat\Behat\Context\Context; |
||||
use Behat\Behat\Hook\Scope\BeforeFeatureScope; |
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
||||
use Behat\MinkExtension\Context\RawMinkContext; |
||||
use Behat\Symfony2Extension\Context\KernelAwareContext; |
||||
use Behat\Testwork\Hook\Scope\BeforeSuiteScope; |
||||
use Doctrine\Common\Collections\ArrayCollection; |
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger; |
||||
use Doctrine\Common\Persistence\ObjectManager; |
||||
use Faker\Factory as FakerFactory; |
||||
use Faker\Generator; |
||||
use Sylius\Component\Resource\Repository\RepositoryInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerInterface; |
||||
use Symfony\Component\HttpKernel\KernelInterface; |
||||
use Symfony\Component\Security\Core\SecurityContextInterface; |
||||
use Symfony\Component\Security\Core\User\UserInterface; |
||||
use Sylius\Bundle\ResourceBundle\Behat\DefaultContext as BaseDefaultContext; |
||||
|
||||
/** |
||||
* Class DefaultContext |
||||
* @package Chamilo\CoreBundle\Behat |
||||
*/ |
||||
abstract class DefaultContext extends BaseDefaultContext |
||||
{ |
||||
/** |
||||
* Faker. |
||||
* |
||||
* @var Generator |
||||
*/ |
||||
protected $faker; |
||||
|
||||
/** |
||||
* Actions. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $actions = array( |
||||
'viewing' => 'show', |
||||
'creation' => 'create', |
||||
'editing' => 'update', |
||||
'building' => 'build', |
||||
); |
||||
|
||||
/** |
||||
* @var KernelInterface |
||||
*/ |
||||
protected $kernel; |
||||
|
||||
public function __construct() |
||||
{ |
||||
$this->faker = FakerFactory::create(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function setKernel(KernelInterface $kernel) |
||||
{ |
||||
$this->kernel = $kernel; |
||||
} |
||||
|
||||
/** |
||||
* @BeforeScenario |
||||
* |
||||
*/ |
||||
public function purgeDatabase(BeforeScenarioScope $scope) |
||||
{ |
||||
$entityManager = $this->getService('doctrine.orm.entity_manager'); |
||||
$entityManager->getConnection()->executeUpdate("SET foreign_key_checks = 0;"); |
||||
|
||||
$purger = new ORMPurger($entityManager); |
||||
$purger->purge(); |
||||
|
||||
$entityManager->getConnection()->executeUpdate("SET foreign_key_checks = 1;"); |
||||
} |
||||
|
||||
/** @BeforeFeature */ |
||||
public static function setupFeature(BeforeFeatureScope $event) |
||||
{ |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Find one resource by name. |
||||
* |
||||
* @param string $type |
||||
* @param string $name |
||||
* |
||||
* @return object |
||||
*/ |
||||
protected function findOneByName($type, $name) |
||||
{ |
||||
return $this->findOneBy($type, array('name' => trim($name))); |
||||
} |
||||
|
||||
/** |
||||
* Find one resource by criteria. |
||||
* |
||||
* @param string $type |
||||
* @param array $criteria |
||||
* |
||||
* @return object |
||||
* |
||||
* @throws \InvalidArgumentException |
||||
*/ |
||||
protected function findOneBy($type, array $criteria) |
||||
{ |
||||
$resource = $this |
||||
->getRepository($type) |
||||
->findOneBy($criteria) |
||||
; |
||||
|
||||
if (null === $resource) { |
||||
throw new \InvalidArgumentException( |
||||
sprintf('%s for criteria "%s" was not found.', str_replace('_', ' ', ucfirst($type)), serialize($criteria)) |
||||
); |
||||
} |
||||
|
||||
return $resource; |
||||
} |
||||
|
||||
/** |
||||
* Get repository by resource name. |
||||
* |
||||
* @param string $resource |
||||
* |
||||
* @return RepositoryInterface |
||||
*/ |
||||
protected function getRepository($resource) |
||||
{ |
||||
return $this->getService('sylius.repository.'.$resource); |
||||
} |
||||
|
||||
/** |
||||
* Get entity manager. |
||||
* |
||||
* @return ObjectManager |
||||
*/ |
||||
protected function getEntityManager() |
||||
{ |
||||
return $this->getService('doctrine')->getManager(); |
||||
} |
||||
|
||||
/** |
||||
* Returns Container instance. |
||||
* |
||||
* @return ContainerInterface |
||||
*/ |
||||
protected function getContainer() |
||||
{ |
||||
return $this->kernel->getContainer(); |
||||
} |
||||
|
||||
/** |
||||
* Get service by id. |
||||
* |
||||
* @param string $id |
||||
* |
||||
* @return object |
||||
*/ |
||||
protected function getService($id) |
||||
{ |
||||
return $this->getContainer()->get($id); |
||||
} |
||||
|
||||
/** |
||||
* Configuration converter. |
||||
* |
||||
* @param string $configurationString |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function getConfiguration($configurationString) |
||||
{ |
||||
$configuration = array(); |
||||
$list = explode(',', $configurationString); |
||||
|
||||
foreach ($list as $parameter) { |
||||
list($key, $value) = explode(':', $parameter); |
||||
$key = strtolower(trim(str_replace(' ', '_', $key))); |
||||
|
||||
switch ($key) { |
||||
case 'country': |
||||
$configuration[$key] = $this->getRepository('country')->findOneBy(array('name' => trim($value)))->getId(); |
||||
break; |
||||
|
||||
case 'taxons': |
||||
$configuration[$key] = new ArrayCollection(array($this->getRepository('taxon')->findOneBy(array('name' => trim($value)))->getId())); |
||||
break; |
||||
|
||||
case 'variant': |
||||
$configuration[$key] = $this->getRepository('product')->findOneBy(array('name' => trim($value)))->getMasterVariant()->getId(); |
||||
break; |
||||
|
||||
default: |
||||
$configuration[$key] = trim($value); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return $configuration; |
||||
} |
||||
|
||||
/** |
||||
* Generate page url. |
||||
* This method uses simple convention where page argument is prefixed |
||||
* with "sylius_" and used as route name passed to router generate method. |
||||
* |
||||
* @param object|string $page |
||||
* @param array $parameters |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function generatePageUrl($page, array $parameters = array()) |
||||
{ |
||||
if (is_object($page)) { |
||||
return $this->generateUrl($page, $parameters); |
||||
} |
||||
|
||||
$route = str_replace(' ', '_', trim($page)); |
||||
//$routes = $this->getContainer()->get('router')->getRouteCollection(); |
||||
|
||||
/*if (null === $routes->get($route)) { |
||||
$route = 'sylius_'.$route; |
||||
} |
||||
|
||||
if (null === $routes->get($route)) { |
||||
$route = str_replace('sylius_', 'sylius_backend_', $route); |
||||
} |
||||
|
||||
$route = str_replace(array_keys($this->actions), array_values($this->actions), $route); |
||||
$route = str_replace(' ', '_', $route);*/ |
||||
|
||||
return $this->generateUrl($route, $parameters); |
||||
} |
||||
|
||||
/** |
||||
* Get current user instance. |
||||
* |
||||
* @return null|UserInterface |
||||
* |
||||
* @throws \Exception |
||||
*/ |
||||
protected function getUser() |
||||
{ |
||||
$token = $this->getSecurityContext()->getToken(); |
||||
|
||||
if (null === $token) { |
||||
throw new \Exception('No token found in security context.'); |
||||
} |
||||
|
||||
return $token->getUser(); |
||||
} |
||||
|
||||
/** |
||||
* Get security context. |
||||
* |
||||
* @return SecurityContextInterface |
||||
*/ |
||||
protected function getSecurityContext() |
||||
{ |
||||
return $this->getContainer()->get('security.context'); |
||||
} |
||||
|
||||
/** |
||||
* Generate url. |
||||
* |
||||
* @param string $route |
||||
* @param array $parameters |
||||
* @param Boolean $absolute |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function generateUrl($route, array $parameters = array(), $absolute = false) |
||||
{ |
||||
return $this->locatePath($this->getService('router')->generate($route, $parameters, $absolute)); |
||||
} |
||||
|
||||
/** |
||||
* Presses button with specified id|name|title|alt|value. |
||||
*/ |
||||
protected function pressButton($button) |
||||
{ |
||||
$this->getSession()->getPage()->pressButton($this->fixStepArgument($button)); |
||||
} |
||||
|
||||
/** |
||||
* Clicks link with specified id|title|alt|text. |
||||
*/ |
||||
protected function clickLink($link) |
||||
{ |
||||
$this->getSession()->getPage()->clickLink($this->fixStepArgument($link)); |
||||
} |
||||
|
||||
/** |
||||
* Fills in form field with specified id|name|label|value. |
||||
*/ |
||||
protected function fillField($field, $value) |
||||
{ |
||||
$this->getSession()->getPage()->fillField($this->fixStepArgument($field), $this->fixStepArgument($value)); |
||||
} |
||||
|
||||
/** |
||||
* Selects option in select field with specified id|name|label|value. |
||||
*/ |
||||
public function selectOption($select, $option) |
||||
{ |
||||
$this->getSession()->getPage()->selectFieldOption($this->fixStepArgument($select), $this->fixStepArgument($option)); |
||||
} |
||||
|
||||
/** |
||||
* Returns fixed step argument (with \\" replaced back to "). |
||||
* |
||||
* @param string $argument |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function fixStepArgument($argument) |
||||
{ |
||||
return str_replace('\\"', '"', $argument); |
||||
} |
||||
} |
@ -0,0 +1,62 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Behat; |
||||
|
||||
use Behat\Behat\Context\Context; |
||||
use Behat\Behat\Context\SnippetAcceptingContext; |
||||
use Behat\Behat\Tester\Exception\PendingException; |
||||
use Behat\Gherkin\Node\PyStringNode; |
||||
use Behat\Gherkin\Node\TableNode; |
||||
use Behat\Symfony2Extension\Context\KernelDictionary; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\CourseRelUser; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CoreBundle\Entity\SessionRelCourse; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Doctrine\ORM\EntityRepository; |
||||
use PHPUnit_Framework_TestCase; |
||||
|
||||
|
||||
/** |
||||
* Class CourseContext |
||||
* Defines application features from the specific context. |
||||
* DefaultContext class drops the database automatically |
||||
* @package Chamilo\CoreBundle\Behat |
||||
*/ |
||||
class UserContext extends DefaultContext implements Context, SnippetAcceptingContext |
||||
{ |
||||
// only in php 5.4 to get access to $this->getContainer() |
||||
//use KernelDictionary; |
||||
|
||||
/** |
||||
* Initializes context. |
||||
* |
||||
* Every scenario gets its own context instance. |
||||
* You can also pass arbitrary arguments to the |
||||
* context constructor through behat.yml. |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* @return \Doctrine\Common\Persistence\ObjectManager|object |
||||
*/ |
||||
public function getEntityManager() |
||||
{ |
||||
return $this->getContainer()->get('doctrine')->getManager(); |
||||
} |
||||
|
||||
/** |
||||
* Returns the Doctrine repository manager for a given entity. |
||||
* |
||||
* @param string $entityName The name of the entity. |
||||
* |
||||
* @return EntityRepository |
||||
*/ |
||||
protected function getRepository($entityName) |
||||
{ |
||||
return $this->getEntityManager()->getRepository($entityName); |
||||
} |
||||
} |
@ -0,0 +1,830 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Behat; |
||||
|
||||
use Behat\Gherkin\Node\TableNode; |
||||
use Behat\Mink\Exception\ElementNotFoundException; |
||||
use Behat\Mink\Exception\UnsupportedDriverActionException; |
||||
use Symfony\Component\Intl\Intl; |
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
||||
|
||||
/** |
||||
* Web context. |
||||
* |
||||
* @author Paweł Jędrzejewski <pawel@sylius.org> |
||||
*/ |
||||
class WebContext extends DefaultContext |
||||
{ |
||||
/** |
||||
* @Given /^go to "([^""]*)" tab$/ |
||||
*/ |
||||
public function goToTab($tabLabel) |
||||
{ |
||||
$this->getSession()->getPage()->find('css', sprintf('.nav-tabs a:contains("%s")', $tabLabel))->click(); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^the page title should be "([^""]*)"$/ |
||||
*/ |
||||
public function thePageTitleShouldBe($title) |
||||
{ |
||||
$this->assertSession()->elementTextContains('css', 'title', $title); |
||||
} |
||||
|
||||
/** |
||||
* @When /^I go to the website root$/ |
||||
*/ |
||||
public function iGoToTheWebsiteRoot() |
||||
{ |
||||
$this->getSession()->visit('/'); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the (.+) (page|step)?$/ |
||||
* @When /^I go to the (.+) (page|step)?$/ |
||||
*/ |
||||
public function iAmOnThePage($page) |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl($page)); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the (.+) (page|step)$/ |
||||
* @Then /^I should be redirected to the (.+) (page|step)$/ |
||||
* @Then /^I should still be on the (.+) (page|step)$/ |
||||
*/ |
||||
public function iShouldBeOnThePage($page) |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generatePageUrl($page)); |
||||
|
||||
try { |
||||
$this->assertStatusCodeEquals(200); |
||||
} catch (UnsupportedDriverActionException $e) { |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be on the store homepage$/ |
||||
*/ |
||||
public function iShouldBeOnTheStoreHomepage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_homepage')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the store homepage$/ |
||||
*/ |
||||
public function iAmOnTheStoreHomepage() |
||||
{ |
||||
$this->getSession()->visit($this->generateUrl('sylius_homepage')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account homepage$/ |
||||
*/ |
||||
public function iAmOnMyAccountHomepage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('sylius_account_homepage')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be on my account homepage$/ |
||||
*/ |
||||
public function iShouldBeOnMyAccountHomepage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_account_homepage')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account password page$/ |
||||
*/ |
||||
public function iAmOnMyAccountPasswordPage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('fos_user_change_password')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be on my account password page$/ |
||||
*/ |
||||
public function iShouldBeOnMyAccountPasswordPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('fos_user_change_password')); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should still be on my account password page$/ |
||||
*/ |
||||
public function iShouldStillBeOnMyAccountPasswordPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('fos_user_change_password')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account profile edition page$/ |
||||
*/ |
||||
public function iAmOnMyAccountProfileEditionPage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('fos_user_profile_edit')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be on my account profile edition page$/ |
||||
*/ |
||||
public function iShouldBeOnMyProfileEditionPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('fos_user_profile_edit')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should still be on my account profile edition page$/ |
||||
*/ |
||||
public function iShouldStillBeOnMyProfileEditionPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('fos_user_profile_edit')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be on my account profile page$/ |
||||
*/ |
||||
public function iShouldBeOnMyProfilePage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('fos_user_profile_show')); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on my account orders page$/ |
||||
*/ |
||||
public function iShouldBeOnMyAccountOrdersPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_account_order_index')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account orders page$/ |
||||
*/ |
||||
public function iAmOnMyAccountOrdersPage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('sylius_account_order_index')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account addresses page$/ |
||||
*/ |
||||
public function iAmOnMyAccountAddressesPage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('sylius_account_address_index')); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on my account addresses page$/ |
||||
*/ |
||||
public function iShouldBeOnMyAccountAddressesPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_account_address_index')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should still be on my account addresses page$/ |
||||
*/ |
||||
public function iShouldStillBeOnMyAccountAddressesPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_account_address_index')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on my account address creation page$/ |
||||
*/ |
||||
public function iAmOnMyAccountAddressCreationPage() |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('sylius_account_address_create')); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on my account address creation page$/ |
||||
*/ |
||||
public function iShouldBeOnMyAccountAddressCreationPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generatePageUrl('sylius_account_address_create')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should still be on my account address creation page$/ |
||||
*/ |
||||
public function iShouldStillBeOnMyAccountAddressCreationPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generateUrl('sylius_account_address_create')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on login page$/ |
||||
*/ |
||||
public function iShouldBeOnLoginPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generatePageUrl('fos_user_security_login')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on registration page$/ |
||||
*/ |
||||
public function iShouldBeOnRegistrationPage() |
||||
{ |
||||
$this->assertSession()->addressEquals($this->generatePageUrl('fos_user_registration_register')); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the shipment page with method "([^""]*)"$/ |
||||
*/ |
||||
public function iAmOnTheShipmentPage($value) |
||||
{ |
||||
$shippingMethod = $this->findOneBy('shipping_method', array('name' => $value)); |
||||
$shipment = $this->findOneBy('shipment', array('method' => $shippingMethod)); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl('backend_shipment_show', array('id' => $shipment->getId()))); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the page of ([^""]*) with ([^""]*) "([^""]*)"$/ |
||||
* @Given /^I go to the page of ([^""]*) with ([^""]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iAmOnTheResourcePage($type, $property, $value) |
||||
{ |
||||
$type = str_replace(' ', '_', $type); |
||||
|
||||
$resource = $this->findOneBy($type, array($property => $value)); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl(sprintf('backend_%s_show', $type), array('id' => $resource->getId()))); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the page of ([^""(w)]*) "([^""]*)"$/ |
||||
* @Given /^I go to the page of ([^""(w)]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iAmOnTheResourcePageByName($type, $name) |
||||
{ |
||||
$this->iAmOnTheResourcePage($type, 'name', $name); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the shipment page with method "([^"]*)"$/ |
||||
*/ |
||||
public function iShouldBeOnTheShipmentPageWithMethod($value) |
||||
{ |
||||
$shippingMethod = $this->findOneBy('shipping_method', array('name' => $value)); |
||||
$shipment = $this->findOneBy('shipment', array('method' => $shippingMethod)); |
||||
|
||||
$this->assertSession()->addressEquals($this->generatePageUrl('backend_shipment_show', array('id' => $shipment->getId()))); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the page of ([^""]*) with ([^""]*) "([^""]*)"$/ |
||||
* @Then /^I should still be on the page of ([^""]*) with ([^""]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldBeOnTheResourcePage($type, $property, $value) |
||||
{ |
||||
$type = str_replace(' ', '_', $type); |
||||
$resource = $this->findOneBy($type, array($property => $value)); |
||||
|
||||
$this->assertSession()->addressEquals($this->generatePageUrl(sprintf('backend_%s_show', $type), array('id' => $resource->getId()))); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the page of ([^""(w)]*) "([^""]*)"$/ |
||||
* @Then /^I should still be on the page of ([^""(w)]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldBeOnTheResourcePageByName($type, $name) |
||||
{ |
||||
$this->iShouldBeOnTheResourcePage($type, 'name', $name); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am (building|viewing|editing) ([^""]*) with ([^""]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iAmDoingSomethingWithResource($action, $type, $property, $value) |
||||
{ |
||||
$type = str_replace(' ', '_', $type); |
||||
|
||||
$action = str_replace(array_keys($this->actions), array_values($this->actions), $action); |
||||
$resource = $this->findOneBy($type, array($property => $value)); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl(sprintf('backend_%s_%s', $type, $action), array('id' => $resource->getId()))); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am (building|viewing|editing) ([^""(w)]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iAmDoingSomethingWithResourceByName($action, $type, $name) |
||||
{ |
||||
$this->iAmDoingSomethingWithResource($action, $type, 'name', $name); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be (building|viewing|editing) ([^"]*) with ([^"]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldBeDoingSomethingWithResource($action, $type, $property, $value) |
||||
{ |
||||
$type = str_replace(' ', '_', $type); |
||||
|
||||
$action = str_replace(array_keys($this->actions), array_values($this->actions), $action); |
||||
$resource = $this->findOneBy($type, array($property => $value)); |
||||
|
||||
$this->assertSession()->addressEquals($this->generatePageUrl(sprintf('sylius_backend_%s_%s', $type, $action), array('id' => $resource->getId()))); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I remove property choice number (\d+)$/ |
||||
*/ |
||||
public function iRemovePropertyChoiceInput($number) |
||||
{ |
||||
$this |
||||
->getSession() |
||||
->getPage() |
||||
->find('css', sprintf('.sylius_property_choices_%d_delete', $number)) |
||||
->click() |
||||
; |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be (building|viewing|editing) ([^""(w)]*) "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldBeDoingSomethingWithResourceByName($action, $type, $name) |
||||
{ |
||||
$this->iShouldBeDoingSomethingWithResource($action, $type, 'name', $name); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am creating variant of "([^""]*)"$/ |
||||
*/ |
||||
public function iAmCreatingVariantOf($name) |
||||
{ |
||||
$product = $this->findOneByName('product', $name); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl('sylius_backend_product_variant_create', array('productId' => $product->getId()))); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should be creating variant of "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldBeCreatingVariantOf($name) |
||||
{ |
||||
$product = $this->findOneByName('product', $name); |
||||
|
||||
$this->assertSession()->addressEquals($this->generatePageUrl('sylius_backend_product_variant_create', array('productId' => $product->getId()))); |
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I added product "([^""]*)" to cart$/ |
||||
*/ |
||||
public function iAddedProductToCart($productName) |
||||
{ |
||||
$this->iAmOnTheProductPage($productName); |
||||
$this->pressButton('Add to cart'); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^(?:.* )?"([^"]*)" should appear on the page$/ |
||||
*/ |
||||
public function textShouldAppearOnThePage($text) |
||||
{ |
||||
$this->assertSession()->pageTextContains($text); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^(?:.* )?"([^"]*)" should not appear on the page$/ |
||||
*/ |
||||
public function textShouldNotAppearOnThePage($text) |
||||
{ |
||||
$this->assertSession()->pageTextNotContains($text); |
||||
} |
||||
|
||||
/** |
||||
* @When /^I click "([^"]+)"$/ |
||||
*/ |
||||
public function iClick($link) |
||||
{ |
||||
$this->clickLink($link); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I fill in province name with "([^"]*)"$/ |
||||
*/ |
||||
public function iFillInProvinceNameWith($value) |
||||
{ |
||||
$this->fillField('sylius_country[provinces][0][name]', $value); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I fill in the (billing|shipping) address to (.+)$/ |
||||
*/ |
||||
public function iFillInCheckoutAddress($type, $country) |
||||
{ |
||||
$base = sprintf('sylius_checkout_addressing[%sAddress]', $type); |
||||
|
||||
$this->iFillInAddressFields($base, $country); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I fill in the users (billing|shipping) address to (.+)$/ |
||||
*/ |
||||
public function iFillInUserAddress($type, $country) |
||||
{ |
||||
$base = sprintf('%s[%sAddress]', 'sylius_user', $type); |
||||
$this->iFillInAddressFields($base, $country); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I fill in the users account address to (.+)$/ |
||||
*/ |
||||
public function iFillInUserAccountAddress($country) |
||||
{ |
||||
$this->iFillInAddressFields('sylius_address', $country); |
||||
} |
||||
|
||||
protected function iFillInAddressFields($base, $country) |
||||
{ |
||||
$this->fillField($base.'[firstName]', 'John'); |
||||
$this->fillField($base.'[lastName]', 'Doe'); |
||||
$this->fillField($base.'[street]', 'Pvt. Street 15'); |
||||
$this->fillField($base.'[city]', 'Lodz'); |
||||
$this->fillField($base.'[postcode]', '95-253'); |
||||
$this->selectOption($base.'[country]', $country); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I select the "(?P<field>([^""]|\\")*)" radio button$/ |
||||
*/ |
||||
public function iSelectTheRadioButton($field) |
||||
{ |
||||
$field = str_replace('\\"', '"', $field); |
||||
$radio = $this->getSession()->getPage()->findField($field); |
||||
|
||||
if (null === $radio) { |
||||
throw new ElementNotFoundException( |
||||
$this->getSession(), 'form field', 'id|name|label|value', $field |
||||
); |
||||
} |
||||
|
||||
$this->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should see an? "(?P<element>[^"]*)" element near "([^"]*)"$/ |
||||
*/ |
||||
public function iShouldSeeAElementNear($element, $value) |
||||
{ |
||||
$tr = $this->assertSession()->elementExists('css', sprintf('table tbody tr:contains("%s")', $value)); |
||||
$this->assertSession()->elementExists('css', $element, $tr); |
||||
} |
||||
|
||||
/** |
||||
* @When /^I click "([^"]*)" near "([^"]*)"$/ |
||||
* @When /^I press "([^"]*)" near "([^"]*)"$/ |
||||
*/ |
||||
public function iClickNear($button, $value) |
||||
{ |
||||
$tr = $this->assertSession()->elementExists('css', sprintf('table tbody tr:contains("%s")', $value)); |
||||
|
||||
$locator = sprintf('button:contains("%s")', $button); |
||||
|
||||
if ($tr->has('css', $locator)) { |
||||
$tr->find('css', $locator)->press(); |
||||
} else { |
||||
$tr->clickLink($button); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should see "([^"]*)" field error$/ |
||||
*/ |
||||
public function iShouldSeeFieldError($field) |
||||
{ |
||||
$this->assertSession()->elementExists('xpath', sprintf( |
||||
"//div[contains(@class, 'error')]//label[text()[contains(., '%s')]]", ucfirst($field) |
||||
)); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I should see (\d+) validation errors$/ |
||||
*/ |
||||
public function iShouldSeeFieldsOnError($amount) |
||||
{ |
||||
$this->assertSession()->elementsCount('css', '.form-error', $amount); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should see product prices in "([^"]*)"$/ |
||||
*/ |
||||
public function iShouldSeeProductPricesIn($code) |
||||
{ |
||||
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol($code); |
||||
$this->assertSession()->pageTextContains($symbol); |
||||
} |
||||
|
||||
/** |
||||
* @Then I should see :count available currencies |
||||
*/ |
||||
public function iShouldSeeAvailableCurrencies($count) |
||||
{ |
||||
$this->assertSession()->elementsCount('css', '.currency-menu ul li', $count); |
||||
} |
||||
|
||||
/** |
||||
* @When I change the currency to :currency |
||||
*/ |
||||
public function iChangeTheCurrencyTo($code) |
||||
{ |
||||
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol($code); |
||||
$this->clickLink($symbol); |
||||
} |
||||
|
||||
/** |
||||
* @Then I should see :count available locales |
||||
*/ |
||||
public function iShouldSeeAvailableLocales($count) |
||||
{ |
||||
$this->assertSession()->elementsCount('css', '.locale-menu ul li', $count); |
||||
} |
||||
|
||||
/** |
||||
* @When I change the locale to :locale |
||||
*/ |
||||
public function iChangeTheLocaleTo($name) |
||||
{ |
||||
$this->clickLink($name); |
||||
} |
||||
|
||||
/** |
||||
* @Then I should browse the store in :locale |
||||
*/ |
||||
public function iShouldBrowseTheStoreInLocale($name) |
||||
{ |
||||
switch ($name) { |
||||
case 'English': |
||||
$text = 'Welcome to Sylius'; |
||||
break; |
||||
case 'Polish': |
||||
$text = 'Witaj w Sylius'; |
||||
break; |
||||
case 'German': |
||||
$text = 'Willkommen bei Sylius'; |
||||
break; |
||||
} |
||||
|
||||
$this->assertSession()->pageTextContains($text); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I leave "([^"]*)" empty$/ |
||||
* @Given /^I leave "([^"]*)" field blank/ |
||||
*/ |
||||
public function iLeaveFieldEmpty($field) |
||||
{ |
||||
$this->fillField($field, ''); |
||||
} |
||||
|
||||
/** |
||||
* For example: I should see product with name "Wine X" in that list. |
||||
* |
||||
* @Then /^I should see [\w\s]+ with [\w\s]+ "([^""]*)" in (that|the) list$/ |
||||
*/ |
||||
public function iShouldSeeResourceWithValueInThatList($value) |
||||
{ |
||||
$this->assertSession()->elementTextContains('css', 'table', $value); |
||||
} |
||||
|
||||
/** |
||||
* For example: I should not see product with name "Wine X" in that list. |
||||
* |
||||
* @Then /^I should not see [\w\s]+ with [\w\s]+ "([^""]*)" in (that|the) list$/ |
||||
*/ |
||||
public function iShouldNotSeeResourceWithValueInThatList($value) |
||||
{ |
||||
$this->assertSession()->elementTextNotContains('css', 'table', $value); |
||||
} |
||||
|
||||
/** |
||||
* For example: I should see 10 products in that list. |
||||
* |
||||
* @Then /^I should see (\d+) ([^""]*) in (that|the) list$/ |
||||
*/ |
||||
public function iShouldSeeThatMuchResourcesInTheList($amount, $type) |
||||
{ |
||||
if (1 === count($this->getSession()->getPage()->findAll('css', 'table'))) { |
||||
$this->assertSession()->elementsCount('css', 'table tbody > tr', $amount); |
||||
} else { |
||||
$this->assertSession()->elementsCount('css', sprintf('table#%s tbody > tr', str_replace(' ', '-', $type)), $amount); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* For example: I should see 10 products. |
||||
* |
||||
* @Then /^I should see there (\d+) products/ |
||||
*/ |
||||
public function iShouldSeeThatMuchProducts($amount) |
||||
{ |
||||
$this->assertSession()->elementsCount('css', '.product', $amount); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the product page for "([^"]*)"$/ |
||||
* @Given /^I go to the product page for "([^"]*)"$/ |
||||
*/ |
||||
public function iAmOnTheProductPage($name) |
||||
{ |
||||
$product = $this->findOneBy('product', array('name' => $name)); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl($product)); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the product page for "([^"]*)"$/ |
||||
* @Then /^I should still be on the product page for "([^"]*)"$/ |
||||
*/ |
||||
public function iShouldBeOnTheProductPage($name) |
||||
{ |
||||
$this->iAmOnTheProductPage($name); |
||||
|
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am on the order ([^""]*) page for (\d+)$/ |
||||
* @Given /^I go to the order ([^""]*) page for (\d+)$/ |
||||
*/ |
||||
public function iAmOnTheOrderPage($action, $number) |
||||
{ |
||||
$order = $this->findOneBy('order', array('number' => $number)); |
||||
|
||||
$this->getSession()->visit($this->generatePageUrl('sylius_account_order_'.$action, array('number' => $order->getNumber()))); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be on the order ([^""]*) page for (\d+)$/ |
||||
* @Then /^I should still be on the order ([^""]*) page for (\d+)$/ |
||||
*/ |
||||
public function iShouldBeOnTheOrderPage($action, $number) |
||||
{ |
||||
$this->iAmOnTheOrderPage($action, $number); |
||||
|
||||
$this->assertStatusCodeEquals(200); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I am not authenticated$/ |
||||
* @Given /^I am not logged in anymore$/ |
||||
*/ |
||||
public function iAmNotAuthenticated() |
||||
{ |
||||
$this->getSecurityContext()->setToken(null); |
||||
$this->getContainer()->get('session')->invalidate(); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I log in with "([^""]*)" and "([^""]*)"$/ |
||||
*/ |
||||
public function iLogInWith($email, $password) |
||||
{ |
||||
$this->getSession()->visit($this->generatePageUrl('fos_user_security_login')); |
||||
|
||||
$this->fillField('Email', $email); |
||||
$this->fillField('Password', $password); |
||||
$this->pressButton('login'); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should be logged in$/ |
||||
*/ |
||||
public function iShouldBeLoggedIn() |
||||
{ |
||||
if (!$this->getSecurityContext()->isGranted('ROLE_USER')) { |
||||
throw new AuthenticationException('User is not authenticated.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should not be logged in$/ |
||||
*/ |
||||
public function iShouldNotBeLoggedIn() |
||||
{ |
||||
if ($this->getSecurityContext()->isGranted('ROLE_USER')) { |
||||
throw new AuthenticationException('User was not expected to be logged in, but he is.'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I add following option values:$/ |
||||
*/ |
||||
public function iAddFollowingOptionValues(TableNode $table) |
||||
{ |
||||
$count = count($this->getSession()->getPage()->findAll('css', 'div.collection-container div.control-group')); |
||||
|
||||
foreach ($table->getRows() as $i => $value) { |
||||
$this->getSession()->getPage()->find('css', 'a:contains("Add value")')->click(); |
||||
$this->fillField(sprintf('sylius_option[values][%d][value]', $i+$count), $value[0]); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @When /^I click the login with (.+) button$/ |
||||
* @When /^I press the login with (.+) button$/ |
||||
*/ |
||||
public function iClickTheLoginWithButton($provider) |
||||
{ |
||||
$loginButton = $this->getSession()->getPage()->find('css', sprintf('a.oauth-login-%s', strtolower($provider))); |
||||
$loginButton->click(); |
||||
|
||||
// Re-set default session |
||||
$currentUrl = $this->getSession()->getCurrentUrl(); |
||||
$this->getMink()->setDefaultSessionName('goutte'); |
||||
$this->getSession()->visit($currentUrl); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I added product "([^""]*)" to cart, with quantity "([^""]*)"$/ |
||||
* @When /^I add product "([^""]*)" to cart, with quantity "([^""]*)"$/ |
||||
*/ |
||||
public function iAddedProductToCartWithQuantity($productName, $quantity) |
||||
{ |
||||
$this->iAmOnTheProductPage($productName); |
||||
$this->fillField('Quantity', $quantity); |
||||
$this->pressButton('Add to cart'); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I finish the checkout process$/ |
||||
*/ |
||||
public function iFinishTheCheckoutProcess() |
||||
{ |
||||
$this->iFillInCheckoutAddress('shipping', 'United Kingdom'); |
||||
$this->pressButton('Continue'); |
||||
$this->iSelectTheRadioButton('DHL Express'); |
||||
$this->pressButton('Continue'); |
||||
$this->iSelectTheRadioButton('Credit Card'); |
||||
$this->pressButton('Continue'); |
||||
$this->iClick('Place order'); |
||||
$this->assertSession()->pageTextContains('Thank you for your order!'); |
||||
} |
||||
|
||||
/** |
||||
* @Then /^I should see ([^""]*) "([^""]*)" for "([^""]*)"$/ |
||||
*/ |
||||
public function iShouldSeeQuantityFor($property, $expectedValue, $item) |
||||
{ |
||||
$tr = $this->assertSession()->elementExists('css', sprintf('table tbody tr:contains("%s")', $item)); |
||||
$rows = $this->getSession()->getPage()->findAll('css', 'table thead tr th'); |
||||
|
||||
$column = null; |
||||
foreach ($rows as $key => $row) { |
||||
if ($row->getText() === $property) { |
||||
$column = $key; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
$cols = $tr->findAll('css', 'td'); |
||||
|
||||
\PHPUnit_Framework_Assert::assertEquals($expectedValue, $cols[$column]->getText()); |
||||
} |
||||
|
||||
/** |
||||
* @Given /^I click "([^"]*)" from the confirmation modal$/ |
||||
*/ |
||||
public function iClickOnConfirmationModal($button) |
||||
{ |
||||
$this->assertSession()->elementExists('css', '#confirmation-modal'); |
||||
|
||||
$modalContainer = $this->getSession()->getPage()->find('css', '#confirmation-modal'); |
||||
$primaryButton = $modalContainer->find('css', sprintf('a:contains("%s")' ,$button)); |
||||
|
||||
$this->getSession()->wait(100); |
||||
|
||||
if (!preg_match('/in/', $modalContainer->getAttribute('class'))) { |
||||
throw new \Exception('The confirmation modal was not opened...'); |
||||
} |
||||
|
||||
$this->getSession()->wait(100); |
||||
|
||||
$primaryButton->press(); |
||||
} |
||||
|
||||
/** |
||||
* Assert that given code equals the current one. |
||||
* |
||||
* @param integer $code |
||||
*/ |
||||
protected function assertStatusCodeEquals($code) |
||||
{ |
||||
$this->assertSession()->statusCodeEquals($code); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
<?php |
||||
|
||||
if (!in_array(@$_SERVER['REMOTE_ADDR'], array( |
||||
'127.0.0.1', |
||||
'172.33.33.1', |
||||
'::1', |
||||
'10.0.0.1' |
||||
))) { |
||||
header('HTTP/1.0 403 Forbidden'); |
||||
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); |
||||
} |
||||
|
||||
$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; |
||||
|
||||
// Require kernel. |
||||
require_once __DIR__.'/../app/AppKernel.php'; |
||||
require_once __DIR__.'/legacy.php'; |
||||
|
||||
// Initialize kernel and run the application. |
||||
$kernel = new AppKernel('test', true); |
||||
|
||||
/*$request = Request::createFromGlobals(); |
||||
Request::enableHttpMethodParameterOverride();*/ |
||||
use Sonata\PageBundle\Request\RequestFactory; |
||||
$request = RequestFactory::createFromGlobals('host_with_path_by_locale'); |
||||
$request->enableHttpMethodParameterOverride(); |
||||
|
||||
$response = $kernel->handle($request); |
||||
$response->send(); |
||||
|
||||
$kernel->terminate($request, $response); |
Loading…
Reference in new issue