Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelrandy committed Oct 7, 2015
1 parent 0ae1128 commit bd59cb1
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/config_behat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require_once __DIR__.'/config_test.php';
4 changes: 2 additions & 2 deletions behat.local.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default:
context:
parameters:
base_url: http://aperophp.local
base_url: http://www.aperophp.dev
extensions:
Behat\MinkExtension\Extension:
base_url: http://aperophp.local
base_url: http://www.aperophp.dev
2 changes: 1 addition & 1 deletion src/Aperophp/Provider/Controller/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function connect(Application $app)
$app['db']->rollback();
} catch (\Exception $e) {
}
$app->abort(500, 'Impossible de vous inscrire. Merci de réessayer plus tard.');
$app->abort(500, 'Impossible de vous inscrire. Merci de réessayer plus tard. ['.$e->getMessage().']');
}

$app['session']->getFlashBag()->add('success', 'Votre compte a été créé avec succès.');
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/member/signup.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h3>Inscription</h3>
</div> <!-- /widget-header -->
<div class="widget-content">
<form method="post" action="{{ url('_signupmember') }}" class="form-horizontal" {{ form_enctype(form) }}>
<form id="signup" method="post" action="{{ url('_signupmember') }}" class="form-horizontal" {{ form_enctype(form) }}>
<fieldset>
<div class="control-group {% if form.user.lastname.vars.errors|length %}error{% endif %}">
{{ form_label(form.user.lastname, null, { 'label_attr': {'class': 'control-label'} }) }}
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/0010-account.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# language: fr

Fonctionnalité: La gestion des comptes est fonctionnelle

Scénario: Il est possible de s'inscrire
Quand je vais sur la page d'inscription
Alors la page d'inscription s'affiche correctement
Quand je me créé un compte "test_behat"/"password"/"[email protected]"
Alors imprimer la dernière réponse
Alors la page de connexion s'affiche correctement
Et le message de succès "Votre compte a été créé avec succès." s'affiche

# Scénario: Il est possible de se connecter
# Quand je vais sur la page de connexion
# Alors la page de connexion s'affiche correctement
# Quand je me connecte avec les identifiants "test_behat"/"password"
# Alors je suis sur la page d'accueil
# Et je suis connecté en tant que "test_behat"
24 changes: 24 additions & 0 deletions tests/functional/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Pré-requis

* DONE Reprendre le process de création de schéma de bdd pour être plus indépendant de la ligne de commande
* DONE Créer un controler Behat qui se connecte sur une BDD de dev
* DONE Monter la volée une base de données SQLite avant chaque test Behat

Tests Behat

* Compte
* S'incrire
* Se connecter
* Se déconnecter

* Apéro
* Liste des apéros
* Consulter un apéro
* S'inscrire à un apéro
* Déposer un commentaire
* Créer un apéro
* Modifier un apéro

MEP

* Modifier Capistrano pour ne pas déployer le controler Behat
36 changes: 36 additions & 0 deletions tests/functional/bootstrap/Context/SigninContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Aperophp\Test\Functional\Context;

use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;
use Behat\Behat\Exception\PendingException;
use Behat\Behat\Context\Step;

class SigninContext extends PageObjectContext
{
/**
* @Given /^je vais sur la page de connexion$/
*/
public function jeVaisSurLaPageDeConnexion()
{
$this->getPage('Signin')->open();
}

/**
* @Given /^la page de connexion s\'affiche correctement$/
*/
public function laPageDeConnexionSAfficheCorrectement()
{
return array(
new Step\Then(sprintf('la page "%s" s\'affiche correctement', $this->getPage('Signin')->path)),
);
}

/**
* @Given /^je me connecte avec les identifiants "([^"]*)"\/"([^"]*)"$/
*/
public function jeMeConnecteAvecLesIdentifiants($login, $password)
{

}
}
36 changes: 36 additions & 0 deletions tests/functional/bootstrap/Context/SignupContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Aperophp\Test\Functional\Context;

use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;
use Behat\Behat\Exception\PendingException;
use Behat\Behat\Context\Step;

class SignupContext extends PageObjectContext
{
/**
* @Given /^je vais sur la page d\'inscription$/
*/
public function jeVaisSurLaPageDInscription()
{
$this->getPage('Signup')->open();
}

/**
* @Given /^la page d\'inscription s\'affiche correctement$/
*/
public function laPageDInscriptionSAfficheCorrectement()
{
return array(
new Step\Then(sprintf('la page "%s" s\'affiche correctement', $this->getPage('Signup')->path)),
);
}

/**
* @Given /^je me créé un compte "([^"]*)"\/"([^"]*)"\/"([^"]*)"$/
*/
public function jeMeCreeUnCompte($login, $password, $email)
{
$this->getPage('Signup')->createAccount($login, $password, $email);
}
}
2 changes: 1 addition & 1 deletion tests/functional/bootstrap/Context/WebContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function getMink()
public function laPageSAfficheCorrectement($url)
{
return array(
new Step\Then("je suis sur \"$url\""),
new Step\Then("je devrais être sur \"$url\""),
new Step\Then("le code de status de la réponse devrait être 200"),
);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Behat\MinkExtension\Context\MinkContext;

use Aperophp\Test\Functional\Context;
use Aperophp\Database\Tool as DatabaseTool;

/**
* Features context.
Expand All @@ -20,6 +21,25 @@ public function __construct(array $parameters)
{
$this->useContext('view', new Context\WebContext($parameters));
$this->useContext('homepage', new Context\HomepageContext($parameters));
$this->useContext('signup', new Context\SignupContext($parameters));
$this->useContext('signin', new Context\SigninContext($parameters));
$this->useContext('mink', new MinkContext($parameters));
}

/**
* Reset database for testing on fresh fixtures import
*
* @BeforeFeature
*/
public static function resetDatabase()
{
// Load application to have db connection
$app = require __DIR__.'/../../../app/bootstrap.php';
require __DIR__.'/../../../app/config_behat.php';

// Reseting database
$databaseTool = new DatabaseTool($app['db']);
$databaseTool->createSchema(__DIR__.'/../../../data/sql/schema.mysql.sql');
$databaseTool->loadFixtures(__DIR__.'/../../../data/sql/fixtures.sql');
}
}
15 changes: 15 additions & 0 deletions tests/functional/bootstrap/Page/Signin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Aperophp\Test\Functional\Page;

use SensioLabs\Behat\PageObjectExtension\PageObject;

class Signin extends PageObject\Page
{
/**
* Page url
*
* @var string
*/
public $path = '/member/signin.html';
}
48 changes: 48 additions & 0 deletions tests/functional/bootstrap/Page/Signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Aperophp\Test\Functional\Page;

use SensioLabs\Behat\PageObjectExtension\PageObject;

class Signup extends PageObject\Page
{
/**
* Page url
*
* @var string
*/
public $path = '/member/signup.html';

/**
* Page elements
*
* @var array
*/
protected $elements = array(
'form' => array('css' => 'form#signup')
);

/**
* Create an account
*
* @param string $username
* @param string $password
* @param string $email
* @param string $firstname
* @param string $lastname
*
* @return void
*/
public function createAccount($username, $password, $email, $firstname=null, $lastname=null)
{
$signupForm = $this->getElement('form');

$signupForm->fillField('signup_member_username', $username);
$signupForm->fillField('signup_member_password', $password);
$signupForm->fillField('signup_user_email', $email);
$signupForm->fillField('signup_user_lastname', $lastname);
$signupForm->fillField('signup_user_firstname', $firstname);

return $signupForm->pressButton('S\'inscrire');
}
}
2 changes: 1 addition & 1 deletion web/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

$app = require_once __DIR__.'/../app/app.php';
$app->run();
$app->run();
5 changes: 5 additions & 0 deletions web/index_behat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$app = require_once __DIR__.'/../app/app.php';
require_once __DIR__.'/../app/config_behat.php';
$app->run();

0 comments on commit bd59cb1

Please sign in to comment.