Skip to content

Instantly share code, notes, and snippets.

@Taluu
Created October 22, 2012 12:29
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 Taluu/5a1857bb5a76c9765f87 to your computer and use it in GitHub Desktop.
Save Taluu/5a1857bb5a76c9765f87 to your computer and use it in GitHub Desktop.
Feature: Handles the logging in and logging out of the user.
Scenario: Log an user in
Given I am on homepage
When I fill in "username" with "user@wisembly.com"
And I fill in "password" with "pass"
And I press "Login"
And I reload the page
Then I should see "Root"
Scenario: Log an user out
Given I am connected with "user@wisembly.com" and "pass" on homepage
When I follow "user_logout"
And I reload the page
Then I follow "user_signup"
<?php
use Symfony\Component\HttpFoundation\Request;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::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_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
<?php
use Symfony\Component\HttpFoundation\Request;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::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_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('test', false);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
default:
context:
class : 'features\bootstrap\Context\FeatureContext'
parameters:
reset_database : false
environment : prod
extensions:
Behat\MinkExtension\Extension:
base_url : 'http://localhost/'
goutte : ~
zombie : ~
test:
context:
parameters:
reset_database : true
environment : test
extensions:
Behat\MinkExtension\Extension:
base_url : 'http://localhost/app_test.php'
dev:
context:
parameters:
reset_database : true
environment : dev
extensions:
Behat\MinkExtension\Extension:
base_url : 'http://localhost/app_dev.php'
imports:
- { resource: config_dev.yml }
security:
acl:
connection: test
framework:
test: ~
session:
storage_id: session.storage.filesystem
doctrine:
dbal:
default_connection: test
connections:
default:
dbname: %database_test%
orm:
default_entity_manager: default
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
<?php
use \Behat\MinkExtension\Context\MinkContext,
\Behat\Behat\Exception\PendingException,
\Behat\Behat\Event\SuiteEvent;
use \Symfony\Component\Process\Process;
/**
* Features context.
*/
class FeatureContext extends MinkContext
{
/**
* Connects the user
*
* @Given /^I am connected with "(?P<user>(?:[^"]|\\")*)" and "(?P<pass>(?:[^"]|\\")*)"$/
*
* @param string $user username to log in
* @param string $pass username's password
*/
public function iAmConnectedWithAnd($user, $pass)
{
$this->fillField('username', $user);
$this->fillField('password', $pass);
$this->pressButton('Login');
}
/**
* Connects the user on an url
*
* @Given /^I am connected with "(?P<user>(?:[^"]|\\")*)" and "(?P<pass>(?:[^"]|\\")*)" on "(?P<url>.+)"/
*
* @param string $user username to log in
* @param string $pass username's password
* @param string $url url to visit
*/
public function iAmConnectedWithAndOn($user, $pass, $url)
{
$this->visit($url);
$this->iAmConnectedWithAnd($user, $pass);
$this->visit($url);
}
/**
* Connects the user on the homepage
*
* @Given /^I am connected with "(?P<user>(?:[^"]|\\")*)" and "(?P<pass>(?:[^"]|\\")*)" on homepage$/
*
* @param string $user username to log in
* @param string $pass username's password
*/
public function iAmConnectedWithAndOnHomepage($user, $pass)
{
$this->iAmConnectedWithAndOn($user, $pass, '/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment