2015-07-02 02:44:56 -05:00
|
|
|
<?php
|
2016-12-05 14:58:23 -06:00
|
|
|
/**
|
|
|
|
* TestCase.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.
|
|
|
|
*/
|
2016-05-20 01:57:45 -05:00
|
|
|
|
2016-11-19 08:55:49 -06:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Models\Preference;
|
|
|
|
use FireflyIII\User;
|
|
|
|
|
2016-10-09 00:58:27 -05:00
|
|
|
/**
|
|
|
|
* Class TestCase
|
|
|
|
*/
|
2016-09-15 23:19:40 -05:00
|
|
|
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
2015-07-02 02:44:56 -05:00
|
|
|
{
|
2016-01-08 07:30:19 -06:00
|
|
|
/**
|
|
|
|
* The base URL to use while testing the application.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-07-02 02:44:56 -05:00
|
|
|
protected $baseUrl = 'http://localhost';
|
|
|
|
|
2016-11-19 08:55:49 -06:00
|
|
|
/**
|
|
|
|
* @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(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 02:44:56 -05:00
|
|
|
/**
|
|
|
|
* Creates the application.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Foundation\Application
|
|
|
|
*/
|
|
|
|
public function createApplication()
|
|
|
|
{
|
2016-11-19 08:55:49 -06:00
|
|
|
$app = require __DIR__ . '/../bootstrap/app.php';
|
2015-07-02 02:44:56 -05:00
|
|
|
|
2016-01-08 07:30:19 -06:00
|
|
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
2015-07-02 02:44:56 -05:00
|
|
|
|
|
|
|
return $app;
|
|
|
|
}
|
2016-11-19 08:55:49 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 13:10:47 -06:00
|
|
|
* @return User
|
2016-11-19 08:55:49 -06:00
|
|
|
*/
|
2017-01-16 13:10:47 -06:00
|
|
|
public function emptyUser()
|
2016-11-19 08:55:49 -06:00
|
|
|
{
|
2017-01-16 13:10:47 -06:00
|
|
|
$user = User::find(2);
|
2016-11-19 08:55:49 -06:00
|
|
|
|
2017-01-16 13:10:47 -06:00
|
|
|
return $user;
|
2016-11-19 08:55:49 -06:00
|
|
|
}
|
|
|
|
|
2016-12-18 10:54:11 -06:00
|
|
|
/**
|
2017-01-16 13:10:47 -06:00
|
|
|
* @return array
|
2016-12-18 10:54:11 -06:00
|
|
|
*/
|
2017-01-16 13:10:47 -06:00
|
|
|
public function naughtyStringProvider()
|
2016-12-18 10:54:11 -06:00
|
|
|
{
|
2017-01-20 09:22:19 -06:00
|
|
|
/*
|
|
|
|
* If on Travis, return very small set.
|
|
|
|
*/
|
2017-01-20 09:27:30 -06:00
|
|
|
if (getenv('TRAVIS') == 'true') {
|
2017-01-20 09:22:19 -06:00
|
|
|
return [['Default value']];
|
2016-12-18 10:54:11 -06:00
|
|
|
|
2017-01-20 09:22:19 -06:00
|
|
|
}
|
2017-01-16 13:10:47 -06:00
|
|
|
$path = realpath(__DIR__ . '/../resources/tests/blns.base64.json');
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
$array = json_decode($content);
|
|
|
|
$return = [];
|
|
|
|
foreach ($array as $entry) {
|
|
|
|
$return[] = [base64_decode($entry)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
* This method is called before a test is executed.
|
|
|
|
*/
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-12-18 10:54:11 -06:00
|
|
|
}
|
2016-11-19 08:55:49 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $class
|
|
|
|
*
|
|
|
|
* @return \Mockery\MockInterface
|
|
|
|
*/
|
|
|
|
protected function mock($class)
|
|
|
|
{
|
2016-11-20 01:46:02 -06:00
|
|
|
Log::debug(sprintf('Will now mock %s', $class));
|
2016-11-19 08:55:49 -06:00
|
|
|
$object = Mockery::mock($class);
|
|
|
|
$this->app->instance($class, $object);
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
2015-07-02 02:44:56 -05:00
|
|
|
}
|