Began work on tests

This commit is contained in:
Dave Earley 2016-04-28 00:06:17 +01:00
parent f897bc66de
commit 6b10a05563
8 changed files with 130 additions and 31 deletions

8
app/Models/Country.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Country extends \Illuminate\Database\Eloquent\Model
{
}

View File

@ -44,7 +44,7 @@ $factory->define(App\Models\Timezone::class, function (Faker\Generator $faker) {
}); });
$factory->define(App\Models\Timezone::class, function (Faker\Generator $faker) { $factory->define(App\Models\DateFormat::class, function (Faker\Generator $faker) {
return [ return [
'format' => "Y-m-d", 'format' => "Y-m-d",
'picker_format' => "Y-m-d", 'picker_format' => "Y-m-d",
@ -81,9 +81,9 @@ $factory->define(App\Models\Account::class, function (Faker\Generator $faker) {
'last_name' => $faker->lastName, 'last_name' => $faker->lastName,
'email' => $faker->email, 'email' => $faker->email,
'timezone_id' => factory(App\Models\Timezone::class)->create()->id, 'timezone_id' => factory(App\Models\Timezone::class)->create()->id,
'date_format_id' => factory(App\Models\Timezone::class)->create()->id, 'date_format_id' => factory(App\Models\DateFormat::class)->create()->id,
'datetime_format_id' => factory(App\Models\DateTimeFormat::class)->create()->id, 'datetime_format_id' => factory(App\Models\DateTimeFormat::class)->create()->id,
'currency_id' => factory()->create()->id, 'currency_id' => factory(App\Models\Currency::class)->create()->id,
'name' => $faker->name, 'name' => $faker->name,
'last_ip' => "127.0.0.1", 'last_ip' => "127.0.0.1",
'last_login_date' => Carbon::now()->subDays(2), 'last_login_date' => Carbon::now()->subDays(2),
@ -92,7 +92,7 @@ $factory->define(App\Models\Account::class, function (Faker\Generator $faker) {
'city' => $faker->city, 'city' => $faker->city,
'state' => $faker->stateAbbr, 'state' => $faker->stateAbbr,
'postal_code' => $faker->postcode, 'postal_code' => $faker->postcode,
'country_id' => factory(App\Models\Country::class)->create()->id, // 'country_id' => factory(App\Models\Country::class)->create()->id,
'email_footer' => 'Email footer text', 'email_footer' => 'Email footer text',
'is_active' => false, 'is_active' => false,
'is_banned' => false, 'is_banned' => false,
@ -101,7 +101,6 @@ $factory->define(App\Models\Account::class, function (Faker\Generator $faker) {
'stripe_refresh_token' => str_random(10), 'stripe_refresh_token' => str_random(10),
'stripe_secret_key' => str_random(10), 'stripe_secret_key' => str_random(10),
'stripe_publishable_key' => str_random(10), 'stripe_publishable_key' => str_random(10),
'stripe_raw_data' => $faker->text,
]; ];
}); });

View File

@ -18,6 +18,7 @@
<env name="APP_ENV" value="testing"/> <env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/> <env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="log"/>
<env name="DB_HOST" value="176.58.123.120"/> <env name="DB_HOST" value="176.58.123.120"/>
<env name="DB_DATABASE" value="test"/> <env name="DB_DATABASE" value="test"/>
</php> </php>

View File

@ -22,7 +22,7 @@
<table style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6;width: 100%"> <table style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6;width: 100%">
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6"> <tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<td style="text-align: center;padding: 10px;margin: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6"> <td style="text-align: center;padding: 10px;margin: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">
<img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{$message->embed(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-email.png'))}}" /> <img style="max-width: 110px;margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6" src="{{url(asset(isset($email_logo) ? $email_logo : 'assets/images/logo-dark.png'))}}" />
</td> </td>
</tr> </tr>
<tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6"> <tr style="margin: 0;padding: 0;font-family: &quot;Helvetica Neue&quot;, &quot;Helvetica&quot;, Helvetica, Arial, sans-serif;font-size: 100%;line-height: 1.6">

18
tests/EventTest.php Normal file
View File

@ -0,0 +1,18 @@
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Models\Organiser;
class EventTest extends TestCase
{
public function testCreateEvent()
{
}
}

View File

@ -1,17 +0,0 @@
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$this->visit('/')
->see('Login');
}
}

45
tests/OrganiserTest.php Normal file
View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Models\Organiser;
class OrganiserTest extends TestCase
{
public function testCreateOrganiser()
{
$this->actingAs($this->test_user)
->visit(route('showCreateOrganiser'))
->type($this->faker->name, 'name')
->type($this->faker->email, 'email')
->type($this->faker->email, 'about')
->type($this->faker->word, 'facebook')
->type($this->faker->word, 'twitter')
->press('Create Organiser')
->seeJson([
'status' => 'success'
]);
}
public function testEditOrganiser()
{
$organiser = factory(App\Models\Organiser::class)->create();
$this->actingAs($this->test_user)
->visit(route('showEditOrganiser', ['organiser_id' => $organiser->id]))
->type($this->faker->name, 'name')
->type($this->faker->email, 'email')
->type($this->faker->email, 'about')
->type($this->faker->word, 'facebook')
->type($this->faker->word, 'twitter')
->press('Create Organiser')
->seeJson([
'status' => 'success'
]);
}
}

View File

@ -1,6 +1,7 @@
<?php <?php
use App\Models\Timezone; use App\Models\Timezone;
use App\Models\User;
class TestCase extends Illuminate\Foundation\Testing\TestCase class TestCase extends Illuminate\Foundation\Testing\TestCase
{ {
@ -9,7 +10,37 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
* *
* @var string * @var string
*/ */
protected $baseUrl = 'http://localhost'; protected $baseUrl = 'http://localhost/public';
/**
* Email for the test user
*
* @var string
*/
protected $test_user_email = 'test@test.test';
/**
* Password for the test user
*
* @var string
*/
protected $test_user_password = 'testtest';
/**
* Our test user
*
* @var
*/
protected $test_user;
/**
* Our faker instance
*
* @var
*/
protected $faker;
/** /**
* Creates the application. * Creates the application.
* *
@ -26,16 +57,30 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
public function setUp(){ public function setUp(){
parent::setUp(); parent::setUp();
\Artisan::call('migrate'); /*
* Set up faker
*/
$this->faker = Faker\Factory::create();
/*
* Migrate & Seed the DB
*/
Artisan::call('migrate');
if (Timezone::count() == 0) { if (Timezone::count() == 0) {
\Artisan::call('db:seed', ['--force' => true]); Artisan::call('db:seed', ['--force' => true]);
} }
factory(App\Models\User::class)->create([ /*
'email' => 'email@email.com', * Set up our test user
'password' => Hash::make('password'), */
]); if(User::where('email','=','test@test.test')->count() === 0) {
$this->test_user = factory(App\Models\User::class)->create([
'email' => $this->test_user_email,
'password' => Hash::make($this->test_user_password),
]);
} else {
$this->test_user = User::where('email','=','test@test.test')->first();
}
} }