Skip to content

Commit

Permalink
tests HJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Asterodeia committed Nov 12, 2016
1 parent 3bfa713 commit e7a8599
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 49 deletions.
10 changes: 0 additions & 10 deletions .env.travis

This file was deleted.

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ php:
- 5.6

before_script:
- cp .env.travis .env
- mysql -e 'create database homestead_test;'
- composer self-update
- composer install --no-interaction
Expand Down
2 changes: 1 addition & 1 deletion database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class DatabaseSeeder extends Seeder
public function run()
{
$this->call(UsersTableSeeder::class);
$this->call(LieuxTableSeeder::class);
$this->call(PersosTableSeeder::class);
$this->call(LieuxTableSeeder::class);

}
}
69 changes: 58 additions & 11 deletions database/seeds/LieuxTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,64 @@ class LieuxTableSeeder extends Seeder
*/
public function run()
{
DB::table('lieux')->insert([
'nom' => 'Grand place',
'description' => 'La plus grande place de la ville.'
]);
DB::table('lieux')->insert([
'nom' => 'La forêt',
'description' => 'Une forêt à l\'extérieur de la ville.'
]);
DB::table('lieux')->insert([
'nom' => 'La plage',
'description' => 'Au bord de l\'océan.'
$now = date('Y-m-d H:i:s');
$lieux = [['Grand place', 'La plus grande place de la ville.'],
['La forêt', 'Une forêt à l\'extérieur de la ville.'],
['La plage', 'Au bord de la mer']];
for ($i = 0; $i < count($lieux); $i++) {
DB::table('lieux')->insert(
array(
'nom' => $lieux[$i][0],
'description' => $lieux[$i][1],
'created_at' => $now,
'updated_at' => $now
)
);
}
$plage = DB::table('lieux')
->where('nom', '=', 'La plage')
->select('id')->first();
for ($i = 0; $i < 2; $i++) {
DB::table('chapitres')->insert([
'titre' => 'Chapitre ' . $i,
'lieu_id' => $plage->id,
'created_at' => $now,
'updated_at' => $now
]);
}
$chapitre1 = DB::table('chapitres')
->where('titre', '=', 'Chapitre 1')
->select('id')->first();
$kheldom = DB::table('persos')
->where('nom', '=', 'Kheldom')
->select('id')->first();
for ($i = 0; $i < 2; $i++) {
DB::table('posts')->insert([
'titre' => 'Message ' . $i . 'dans chapitre 1',
'chapitre_id' => $chapitre1->id,
'auteur_id' => $kheldom->id,
'texte' => '** Trankil, jme dis, voilou le marlou pépère, tu vas t\'en jeter une pard\'ssus le coude dans la forêt. **
« Fulululuuu... »
** J\'sifflote comme une bigote, héhé pouf pouf ça veut rien dire. **',
'created_at' => $now,
'updated_at' => $now
]);
}
$chapitre0 = DB::table('chapitres')
->where('titre', '=', 'Chapitre 0')
->select('id')->first();
$emile = DB::table('persos')
->where('nom', '=', 'Hémihéli')
->select('id')->first();
DB::table('posts')->insert([
'titre' => 'Message ' . $i . 'dans chapitre 0',
'chapitre_id' => $chapitre0->id,
'auteur_id' => $emile->id,
'texte' => '** Trankil, jme dis, voilou le marlou pépère, tu vas t\'en jeter une pard\'ssus le coude dans la forêt. **
« Fulululuuu... »
** J\'sifflote comme une bigote, héhé pouf pouf ça veut rien dire. **',
'created_at' => $now,
'updated_at' => $now
]);
}
}
19 changes: 16 additions & 3 deletions database/seeds/PersosTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ class PersosTableSeeder extends Seeder
*/
public function run()
{
$user1 = DB::table('users')
->where('email', '=', '[email protected]')
->select('id')->first();
$user2 = DB::table('users')
->where('email', '=', '[email protected]')
->select('id')->first();
$now = date('Y-m-d H:i:s');
DB::table('persos')->insert([
'nom' => 'Hémihéli',
'race' => 'Humain',
'user_id' => '1'
'user_id' => $user1->id,
'created_at' => $now,
'updated_at' => $now
]);

DB::table('persos')->insert([
'nom' => 'Kheldom',
'race' => 'Fée',
'user_id' => '1'
'user_id' => $user1->id,
'created_at' => $now,
'updated_at' => $now
]);

DB::table('persos')->insert([
'nom' => 'Pluhm',
'race' => 'Elfe',
'user_id' => '2'
'user_id' => $user2->id,
'created_at' => $now,
'updated_at' => $now
]);
}
}
4 changes: 2 additions & 2 deletions database/seeds/UsersTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class UsersTableSeeder extends Seeder
public function run()
{
DB::table('users')->insert([
'name' => 'User '.str_random(10),
'name' => 'User 1',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);

DB::table('users')->insert([
'name' => 'User '.str_random(10),
'name' => 'User 2',
'email' => '[email protected]',
'password' => bcrypt('secret'),
]);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<input id="password" name="password" type="password" placeholder="amortleselfes" required>
<p class="error-field {{ $errors->has('password') ? 'error' : '' }}">{{ $errors->has('password') ? $errors->first('password') : 'Mot de passe faux' }}</p>

<label for="password_confirm" Confirmation du mot de passe</label>
<label for="password_confirmation" Confirmation du mot de passe</label>
<input id="password_confirmation" name="password_confirmation" type="password" placeholder="amortleselfes">
<p class="error-field {{ $errors->has('password_confirmation') ? 'error' : '' }}">{{ $errors->has('password_confirmation') ? $errors->first('password_confirmation') : 'Mot de passe faux' }}</p>

Expand Down
18 changes: 0 additions & 18 deletions tests/ExampleTest.php

This file was deleted.

100 changes: 100 additions & 0 deletions tests/HJTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class HJTest extends TestCase
{
use DatabaseMigrations;

public function setUp()
{
parent::setUp();
$this->artisan('migrate:refresh', [
'--seed' => '1'
]);
}

public function testCreateAccount()
{
$this->visit('/')
->see('Utopya')
->see('Créer un compte')
->click('Créer un compte')
->seePageIs('/register')
->type('Taylor', 'name')
->type('[email protected]', 'email')
->type('secret', 'password')
->type('secret', 'password_confirmation')
->press('Se connecter')
->seePageIs('/home')
->see('Taylor')
->seeInDatabase('users', [
'email' => '[email protected]'
]);
}

public function testLogIn()
{
$this->visit('/')
->seeInDatabase('users', [
'email' => '[email protected]'
])
->see('Utopya')
->see('Login')
->click('Login')
->seePageIs('/login')
->type('[email protected]', 'email')
->type('secret', 'password')
->check('remember');
$this->press('Se connecter')
->seePageIs('/home')
->see('User 1');
}

public function testLogInWithUnknownUser()
{
$this->visit('/')
->see('Utopya')
->see('Login')
->click('Login')
->seePageIs('/login')
->type('[email protected]', 'email')
->type('secret', 'password')
->check('remember');
$this->press('Se connecter')
->seePageIs('/login')
->see('Ces identifiants ne correspondent pas à nos enregistrements');
}

public function testCreatePerso()
{
$user = factory(App\User::class)->create();
$this->actingAs($user)
->visit('/home')
->see($user->name)
->click('Nouveau personnage')
->seePageIs('persos/create')
->type('Elfe chadiv', 'nom')
->select('Elfe', 'race')
->press('Créer')
->seePageIs('home')
->see('Elfe chadiv');
}

public function testCreateExistingPerso()
{
$user = factory(App\User::class)->create();
$this->actingAs($user)
->visit('/home')
->see($user->name)
->click('Nouveau personnage')
->seePageIs('persos/create')
->type('Kheldom', 'nom')
->select('Elfe', 'race')
->press('Créer')
->seePageIs('persos/create')
->see('La valeur du champ nom est déjà utilisée.');
}
}
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';

putenv('DB_DEFAULT=testing');
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

return $app;
}
}

0 comments on commit e7a8599

Please sign in to comment.