mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Restored some tests.
This commit is contained in:
parent
23925a0076
commit
240f3c126b
45
.env.testing
Executable file
45
.env.testing
Executable file
@ -0,0 +1,45 @@
|
||||
APP_ENV=testing
|
||||
APP_DEBUG=true
|
||||
APP_FORCE_SSL=false
|
||||
APP_FORCE_ROOT=
|
||||
APP_KEY=TestTestTestTestTestTestTestTest
|
||||
APP_LOG_LEVEL=debug
|
||||
APP_URL=http://localhost
|
||||
|
||||
DB_CONNECTION=sqlite
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
SESSION_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
|
||||
COOKIE_PATH="/"
|
||||
COOKIE_DOMAIN=
|
||||
COOKIE_SECURE=false
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_FROM=changeme@example.com
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
SEND_REGISTRATION_MAIL=true
|
||||
SEND_ERROR_MESSAGE=true
|
||||
SHOW_INCOMPLETE_TRANSLATIONS=false
|
||||
|
||||
ANALYTICS_ID=
|
||||
SITE_OWNER=mail@example.com
|
||||
|
||||
PUSHER_KEY=
|
||||
PUSHER_SECRET=
|
||||
PUSHER_APP_ID=
|
@ -11,120 +11,51 @@
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| PDO Fetch Style
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default, database results will be returned as instances of the PHP
|
||||
| stdClass object; however, you may desire to retrieve records in an
|
||||
| array format for simplicity. Here you can tweak the fetch style.
|
||||
|
|
||||
*/
|
||||
|
||||
'fetch' => PDO::FETCH_OBJ,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'fetch' => PDO::FETCH_OBJ,
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'driver' => 'sqlite',
|
||||
'database' => env('DB_DATABASE', storage_path('database/database.sqlite')),
|
||||
'prefix' => '',
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'prefix' => '',
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'driver' => 'pgsql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'schema' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'schema' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer set of commands than a typical key-value systems
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'migrations' => 'migrations',
|
||||
'redis' => [
|
||||
'cluster' => false,
|
||||
|
||||
'default' => [
|
||||
'host' => env('REDIS_HOST', 'localhost'),
|
||||
'host' => env('REDIS_HOST', 'localhost'),
|
||||
'password' => env('REDIS_PASSWORD', null),
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
'database' => 0,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -37,7 +37,7 @@ class ChangesFor3101 extends Migration
|
||||
{
|
||||
Schema::table(
|
||||
'import_jobs', function (Blueprint $table) {
|
||||
$table->text('extended_status');
|
||||
$table->text('extended_status')->nullable();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
41
test.sh
Executable file
41
test.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
DATABASE=storage/database/database.sqlite
|
||||
DATABASECOPY=storage/database/databasecopy.sqlite
|
||||
|
||||
|
||||
# backup current config:
|
||||
mv .env .env.current
|
||||
|
||||
# enable testing config
|
||||
cp .env.testing .env
|
||||
|
||||
# clear cache:
|
||||
php artisan cache:clear
|
||||
|
||||
if [ "$1" == "--reset" ]; then
|
||||
echo "Must reset database"
|
||||
|
||||
# touch files to make sure they exist.
|
||||
touch $DATABASE
|
||||
touch $DATABASECOPY
|
||||
|
||||
# truncate original database file
|
||||
truncate $DATABASE --size 0
|
||||
|
||||
# run migration
|
||||
php artisan migrate:refresh --seed
|
||||
|
||||
# copy new database over backup (resets backup)
|
||||
cp $DATABASE $DATABASECOPY
|
||||
fi
|
||||
|
||||
# take database from copy:
|
||||
cp $DATABASECOPY $DATABASE
|
||||
|
||||
# run PHPUnit
|
||||
|
||||
phpunit
|
||||
|
||||
# restore current config:
|
||||
mv .env.current .env
|
@ -1,9 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* Class ExampleTest
|
||||
*/
|
||||
@ -17,6 +13,6 @@ class ExampleTest extends TestCase
|
||||
public function testBasicExample()
|
||||
{
|
||||
$this->visit('/')
|
||||
->see('Laravel');
|
||||
->see('Firefly');
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
* Class TestCase
|
||||
*/
|
||||
@ -12,6 +16,35 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
*/
|
||||
protected $baseUrl = 'http://localhost';
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $range
|
||||
*/
|
||||
public function changeDateRange(User $user, $range)
|
||||
{
|
||||
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'];
|
||||
if (in_array($range, $valid)) {
|
||||
Preference::where('user_id', $user->id)->where('name', 'viewRange')->delete();
|
||||
Preference::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'name' => 'viewRange',
|
||||
'data' => $range,
|
||||
]
|
||||
);
|
||||
// set period to match?
|
||||
|
||||
}
|
||||
if ($range === 'custom') {
|
||||
$this->session(
|
||||
[
|
||||
'start' => Carbon::now()->subDays(20),
|
||||
'end' => Carbon::now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
@ -19,10 +52,62 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dateRangeProvider()
|
||||
{
|
||||
return [
|
||||
'one day' => ['1D'],
|
||||
'one week' => ['1W'],
|
||||
'one month' => ['1M'],
|
||||
'three months' => ['3M'],
|
||||
'six months' => ['6M'],
|
||||
'one year' => ['1Y'],
|
||||
'custom range' => ['custom'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return \Mockery\MockInterface
|
||||
*/
|
||||
protected function mock($class)
|
||||
{
|
||||
$object = Mockery::mock($class);
|
||||
|
||||
|
||||
$this->app->instance($class, $object);
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
63
tests/acceptance/Controllers/HomeControllerTest.php
Executable file
63
tests/acceptance/Controllers/HomeControllerTest.php
Executable file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* HomeControllerTest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
class HomeControllerTest extends TestCase
|
||||
{
|
||||
public function displayError()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::__construct
|
||||
*/
|
||||
public function testDateRange()
|
||||
{
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
$args = [
|
||||
'start' => '2012-01-01',
|
||||
'end' => '2012-04-01',
|
||||
];
|
||||
|
||||
// if date range is > 50, should have flash.
|
||||
$this->call('POST', '/daterange', $args);
|
||||
$this->assertResponseStatus(200);
|
||||
$this->assertSessionHas('warning', '91 days of data may take a while to load.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::flush
|
||||
*/
|
||||
public function testFlush()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$this->call('GET', '/flush');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Http\Controllers\HomeController::index
|
||||
* @covers FireflyIII\Http\Controllers\Controller::__construct
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param $range
|
||||
*/
|
||||
public function testIndex($range)
|
||||
{
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$this->call('GET', '/');
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
}
|
43
tests/unit/Models/TransactionTypeTest.php
Executable file
43
tests/unit/Models/TransactionTypeTest.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* TransactionTypeTest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
||||
|
||||
/**
|
||||
* Class TransactionTypeTest
|
||||
*/
|
||||
class TransactionTypeTest extends TestCase
|
||||
{
|
||||
public function testIsDeposit()
|
||||
{
|
||||
$transactionType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
|
||||
$this->assertTrue($transactionType->isDeposit());
|
||||
}
|
||||
|
||||
public function testIsOpeningBalance()
|
||||
{
|
||||
$transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
|
||||
$this->assertTrue($transactionType->isOpeningBalance());
|
||||
}
|
||||
|
||||
public function testIsTransfer()
|
||||
{
|
||||
$transactionType = TransactionType::whereType(TransactionType::TRANSFER)->first();
|
||||
$this->assertTrue($transactionType->isTransfer());
|
||||
}
|
||||
|
||||
public function testIsWithdrawal()
|
||||
{
|
||||
$transactionType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
|
||||
$this->assertTrue($transactionType->isWithdrawal());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user