2015-07-02 02:44:56 -05:00
|
|
|
<?php
|
2016-05-20 01:57:45 -05:00
|
|
|
|
2017-02-05 08:42:00 -06:00
|
|
|
namespace Tests;
|
|
|
|
|
2017-02-12 04:25:17 -06:00
|
|
|
use FireflyIII\User;
|
2017-02-05 08:42:00 -06:00
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
2017-02-12 04:25:17 -06:00
|
|
|
use Log;
|
|
|
|
use Mockery;
|
|
|
|
use FireflyIII\Models\Preference;
|
|
|
|
use Carbon\Carbon;
|
2016-10-09 00:58:27 -05:00
|
|
|
/**
|
|
|
|
* Class TestCase
|
2017-02-05 08:42:00 -06:00
|
|
|
*
|
|
|
|
* @package Tests
|
2016-10-09 00:58:27 -05:00
|
|
|
*/
|
2017-02-05 08:42:00 -06:00
|
|
|
abstract class TestCase extends BaseTestCase
|
2015-07-02 02:44:56 -05:00
|
|
|
{
|
2017-02-05 08:42:00 -06:00
|
|
|
use CreatesApplication;
|
2017-02-12 04:25:17 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return User
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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(),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $class
|
|
|
|
*
|
|
|
|
* @return \Mockery\MockInterface
|
|
|
|
*/
|
|
|
|
protected function mock($class)
|
|
|
|
{
|
|
|
|
Log::debug(sprintf('Will now mock %s', $class));
|
|
|
|
$object = Mockery::mock($class);
|
|
|
|
$this->app->instance($class, $object);
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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-02-05 12:51:58 -06:00
|
|
|
}
|