Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Oct 21, 2011
1 parent e28717e commit 2a59b54
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
20 changes: 20 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stopOnIncomplete="false"
stopOnSkipped="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

// Autoload
require_once __DIR__.'/../src/autoload.php';
72 changes: 72 additions & 0 deletions tests/functional/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\SessionStorage\FilesystemSessionStorage;
use Silex\Provider\DoctrineServiceProvider;

class ApplicationTest extends WebTestCase
{
public function createApplication()
{
// Silex
$this->app = require __DIR__.'/../../src/app.php';

// Tests mode
$this->app['debug'] = true;
unset($this->app['exception_handler']);
$app['translator.messages'] = array();

// Use FilesystemSessionStorage to store session
$this->app['session.storage'] = $this->app->share(function() {
return new FilesystemSessionStorage(sys_get_temp_dir());
});

// Controllers
require __DIR__ . '/../../src/controllers.php';

return $app;
}

public function test404()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/give-me-a-404');

$this->assertTrue($client->getResponse()->isNotFound());
}

public function testLogin()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/login');

$this->assertTrue($client->getResponse()->isOk());

$form = $crawler->selectButton('Send')->form(array());
$crawler = $client->submit($form);
$this->assertEquals(2, $crawler->filter('.error')->count());

$form = $crawler->selectButton('Send')->form();
$crawler = $client->submit($form, array(
'form[email]' => 'not an email',
'form[password]' => 'wrong password',
));
$this->assertEquals(1, $crawler->filter('.error')->count());

$form = $crawler->selectButton('Send')->form();
$crawler = $client->submit($form, array(
'form[email]' => 'email@example.com',
'form[password]' => 'wrong password',
));
$this->assertEquals(1, $crawler->filter('.error')->count());

$form = $crawler->selectButton('Send')->form();
$crawler = $client->submit($form, array(
'form[email]' => 'email@example.com',
'form[password]' => 'password',
));
$this->assertEquals(0, $crawler->filter('.error')->count());
$crawler = $client->followRedirect();
$this->assertEquals(1, $crawler->filter('a[href="/logout"]')->count());
}
}

0 comments on commit 2a59b54

Please sign in to comment.