diff --git a/phpunit.coverage.xml b/phpunit.coverage.xml
index 75e3afd143..d643a5d6ec 100755
--- a/phpunit.coverage.xml
+++ b/phpunit.coverage.xml
@@ -10,11 +10,12 @@
beStrictAboutOutputDuringTests="true"
stopOnFailure="true">
-
- ./tests/acceptance
+
+ ./tests/Feature
-
- ./tests/unit
+
+
+ ./tests/Unit
diff --git a/phpunit.xml b/phpunit.xml
index c096c7a945..b0e315533c 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -10,11 +10,12 @@
beStrictAboutOutputDuringTests="true"
stopOnFailure="true">
-
- ./tests/acceptance
+
+ ./tests/Feature
-
- ./tests/unit
+
+
+ ./tests/Unit
diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.php
new file mode 100644
index 0000000000..37c9b79740
--- /dev/null
+++ b/tests/Feature/Controllers/AccountControllerTest.php
@@ -0,0 +1,213 @@
+be($this->user());
+ $response = $this->get(route('accounts.create', ['asset']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::delete
+ */
+ public function testDelete()
+ {
+ $this->be($this->user());
+ $response = $this->get(route('accounts.delete', [1]));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::destroy
+ */
+ public function testDestroy()
+ {
+ $this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']);
+
+ $repository = $this->mock(AccountRepositoryInterface::class);
+ $repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account);
+ $repository->shouldReceive('destroy')->andReturn(true);
+
+ $this->be($this->user());
+ $response = $this->post(route('accounts.destroy', [1]));
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::edit
+ */
+ public function testEdit()
+ {
+ $this->be($this->user());
+ $response = $this->get(route('accounts.edit', [1]));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::index
+ * @covers \FireflyIII\Http\Controllers\AccountController::isInArray
+ * @dataProvider dateRangeProvider
+ *
+ * @param string $range
+ */
+ public function testIndex(string $range)
+ {
+ $this->be($this->user());
+ $this->changeDateRange($this->user(), $range);
+ $response = $this->get(route('accounts.index', ['asset']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::show
+ * @covers \FireflyIII\Http\Controllers\AccountController::periodEntries
+ * @dataProvider dateRangeProvider
+ *
+ * @param string $range
+ */
+ public function testShow(string $range)
+ {
+ $date = new Carbon;
+ $this->session(['start' => $date, 'end' => clone $date]);
+
+ $tasker = $this->mock(AccountTaskerInterface::class);
+ $tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
+ $tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
+
+ // mock repository:
+ $repository = $this->mock(AccountRepositoryInterface::class);
+ $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date);
+ $repository->shouldReceive('getAccountsByType')->andReturn(new Collection);
+
+
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $collector->shouldReceive('setAccounts')->andReturnSelf();
+ $collector->shouldReceive('setRange')->andReturnSelf();
+ $collector->shouldReceive('setLimit')->andReturnSelf();
+ $collector->shouldReceive('setPage')->andReturnSelf();
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+
+
+ $this->be($this->user());
+ $this->changeDateRange($this->user(), $range);
+ $response = $this->get(route('accounts.show', [1]));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::showAll
+ * @dataProvider dateRangeProvider
+ *
+ * @param string $range
+ */
+ public function testShowAll(string $range)
+ {
+ $this->be($this->user());
+ $this->changeDateRange($this->user(), $range);
+ $response = $this->get(route('accounts.show.all', [1]));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::showByDate
+ * @dataProvider dateRangeProvider
+ *
+ * @param string $range
+ */
+ public function testShowByDate(string $range)
+ {
+ $this->be($this->user());
+ $this->changeDateRange($this->user(), $range);
+ $response = $this->get(route('accounts.show.date', [1, '2016-01-01']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::store
+ */
+ public function testStore()
+ {
+ $this->session(['accounts.create.url' => 'http://localhost']);
+ $this->be($this->user());
+ $data = [
+ 'name' => 'new account ' . rand(1000, 9999),
+ 'what' => 'asset',
+ ];
+
+ $response = $this->post(route('accounts.store', ['asset']), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+
+ // list should have this new account.
+ $response = $this->get(route('accounts.index', ['asset']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ $response->assertSee($data['name']);
+ }
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\AccountController::update
+ */
+ public function testUpdate()
+ {
+ $this->session(['accounts.edit.url' => 'http://localhost']);
+ $this->be($this->user());
+ $data = [
+ 'name' => 'updated account ' . rand(1000, 9999),
+ 'active' => 1,
+ 'what' => 'asset',
+ ];
+
+ $response = $this->post(route('accounts.update', [1]), $data);
+ $response->assertStatus(302);
+ $response->assertSessionHas('success');
+
+ // list should have this new account.
+ $response = $this->get(route('accounts.index', ['asset']));
+ $response->assertStatus(200);
+ // has bread crumb
+ $response->assertSee('');
+ $response->assertSee($data['name']);
+ }
+}
\ No newline at end of file
diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php
index 486dc271a3..a8a339029f 100644
--- a/tests/Feature/ExampleTest.php
+++ b/tests/Feature/ExampleTest.php
@@ -1,4 +1,11 @@
get('/');
+ $response = $this->get('/login');
$response->assertStatus(200);
}
+
+ /**
+ * A basic test example.
+ *
+ * @return void
+ */
+ public function testAnotherBasicTest()
+ {
+ $response = $this->get('/');
+
+ $response->assertStatus(302);
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 51b7cf0735..83bc278de8 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,8 +2,12 @@
namespace Tests;
+use FireflyIII\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
-
+use Log;
+use Mockery;
+use FireflyIII\Models\Preference;
+use Carbon\Carbon;
/**
* Class TestCase
*
@@ -12,4 +16,75 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
+
+ /**
+ * @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'],
+ ];
+ }
+
}