public function testCanHaveCategories() { $badge = FactoryMuffin::create('DMA\\Friends\\Models\\Badge'); $category = FactoryMuffin::create('DMA\\Friends\\Models\\Category'); $this->assertInstanceOf('DMA\\Friends\\Models\\Category', $category); $badge->categories()->save($category); }
/** * @covers FireflyIII\Models\Category::firstOrCreateEncrypted */ public function testFirstOrCreateEncryptedNew() { $category = FactoryMuffin::create('FireflyIII\\Models\\Category'); $search = ['name' => 'Some category name', 'user_id' => $category->user_id]; $result = Category::firstOrCreateEncrypted($search); $this->assertNotEquals($result->id, $category->id); }
public function testRequirementSuccess() { $requirement = FactoryMuffin::create('Requirement'); $requirement->load('parameter'); $this->assertInstanceOf('Parameter', $requirement->parameter); $this->assertInstanceOf('Protocol', $requirement->protocol); }
/** * @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOutSummarized */ public function testYearInOutSummarizedShared() { $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); $this->call('GET', '/chart/report/in-out-sum/2015/shared'); $this->assertResponseOk(); }
public function testCombinationSuccess() { $combination = FactoryMuffin::create('Combination'); $combination->load('power_generator'); $this->assertInstanceOf('Needle', $combination->needle); $this->assertInstanceOf('PowerGenerator', $combination->power_generator); $this->assertInstanceOf('Protocol', $combination->protocol); }
public function testRelationships() { $object_types = [FactoryMuffin::create('DMA\\Friends\\Models\\Activity'), FactoryMuffin::create('DMA\\Friends\\Models\\Badge'), FactoryMuffin::create('DMA\\Friends\\Models\\Reward'), FactoryMuffin::create('DMA\\Friends\\Models\\Step')]; foreach ($object_types as $object) { $activityLog = FactoryMuffin::create('DMA\\Friends\\Models\\ActivityLog'); $object->activityLogs()->save($activityLog); } }
/** * @throws \WebservicesNl\Common\Exception\Client\InputException * @throws \InvalidArgumentException * @throws \WebservicesNl\Common\Exception\Server\NoServerAvailableException */ public function testInstance() { /** @var \WebservicesNl\Platform\Webservices\PlatformConfig $platFormConfig */ $platFormConfig = FactoryMuffin::create('WebservicesNl\\Platform\\Webservices\\PlatformConfig'); static::assertTrue(class_exists($platFormConfig->getClassName(true))); static::assertEquals($platFormConfig->getPlatformName(), $platFormConfig::PLATFORM_NAME); static::assertTrue(is_array($platFormConfig->toArray())); }
/** * @covers FireflyIII\Models\Tag::save */ public function testSave() { $tag = FactoryMuffin::create('FireflyIII\\Models\\Tag'); // connect some transaction journals to the tag: $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); $journal->tags()->save($tag); $tag->save(); $journal = TransactionJournal::find($journal->id); $this->assertEquals(1, $journal->tag_count); }
/** * No such route. * * @covers FireflyIII\Http\Controllers\HelpController::show */ public function testGetHelpTextNoRoute() { // login $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); // mock some stuff. $interface = $this->mock('FireflyIII\\Helpers\\Help\\HelpInterface'); $interface->shouldReceive('hasRoute')->once()->with('accounts.index')->andReturn(false); $this->call('GET', '/help/accounts.index'); $this->assertResponseOk(); }
public function testTimeRestrictionsAreSerialized() { $activity = FactoryMuffin::create('DMA\\Friends\\Models\\Activity'); $timeRestrictionData = ['start_time' => '11:00AM', 'end_time' => '12:00PM', 'days' => [1 => true, 2 => false, 3 => true, 4 => false, 5 => true, 6 => false]]; $activity->time_restriction_data = $timeRestrictionData; $activity->save(); // Load a new reference to the model $newActivity = Activity::find($activity->id); // Compare time_restriction_data to ensure that attributes are serialized/unserialized properly $this->assertEquals($newActivity->time_restriction_data, $timeRestrictionData); }
/** * @covers FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator::year */ public function testYear() { $budgets = new Collection(); $entries = new Collection(); // make some budgets: for ($i = 0; $i < 5; $i++) { $budgets->push(FactoryMuffin::create('FireflyIII\\Models\\Budget')); $entries->push([new Carbon(), 100, 100, 100]); } $data = $this->object->year($budgets, $entries); $this->assertCount(5, $data['rows']); $this->assertCount(6, $data['cols']); }
public function testPostIndex() { $user = FactoryMuffin::create('FireflyIII\\User'); $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency'); $account = FactoryMuffin::create('FireflyIII\\Models\\Account'); $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface'); $this->be($user); $data = ['_token' => 'replaceMe', 'bank_name' => 'Some Bank', 'bank_balance' => '100', 'balance_currency_id' => $currency->id, 'savings_balance' => '100', 'credit_card_limit' => '100']; $repository->shouldReceive('store')->andReturn($account); $this->call('POST', '/new-user/submit', $data); $this->assertResponseStatus(302); $this->assertRedirectedToRoute('index'); }
/** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::year */ public function testYearShared() { $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); $categories = new Collection([FactoryMuffin::create('FireflyIII\\Models\\Category')]); // mock! $repository = $this->mock('FireflyIII\\Repositories\\Category\\CategoryRepositoryInterface'); // fake! $repository->shouldReceive('getCategories')->andReturn($categories); $repository->shouldReceive('spentInPeriodCorrected')->andReturn(0); $this->call('GET', '/chart/category/year/2015/shared'); $this->assertResponseOk(); }
public function testEmptyInstance() { /** @var PlatformConfig $platFormConfig */ $platFormConfig = FactoryMuffin::create('WebservicesNl\\Platform\\Webservices\\PlatformConfig'); $soapConfig = new SoapConfig($platFormConfig); static::assertFalse($soapConfig->hasConverter()); static::assertEmpty($soapConfig->getSoapHeaders()); static::assertEquals($platFormConfig, $soapConfig->getPlatformConfig()); static::assertAttributeInstanceOf('WebservicesNl\\Platform\\Webservices\\PlatformConfig', 'platformConfig', $soapConfig); static::assertEquals($soapConfig::getEndPoints(), SoapConfig::getEndPoints()); static::assertCount(5, $soapConfig->toArray()); $static = SoapConfig::configure($platFormConfig); static::assertEquals($static, $soapConfig); }
/** * @covers FireflyIII\Http\Controllers\SearchController::index */ public function testSearch() { $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); $words = ['Something']; // mock! $repository = $this->mock('FireflyIII\\Support\\Search\\SearchInterface'); $repository->shouldReceive('searchTransactions')->with($words)->once()->andReturn([]); $repository->shouldReceive('searchAccounts')->with($words)->once()->andReturn([]); $repository->shouldReceive('searchCategories')->with($words)->once()->andReturn([]); $repository->shouldReceive('searchBudgets')->with($words)->once()->andReturn([]); $repository->shouldReceive('searchTags')->with($words)->once()->andReturn([]); $this->call('GET', '/search?q=Something'); $this->assertResponseOk(); }
/** * @covers FireflyIII\Generator\Chart\Bill\GoogleBillChartGenerator::single */ public function testSingle() { $bill = FactoryMuffin::create('FireflyIII\\Models\\Bill'); $entries = new Collection(); for ($i = 0; $i < 5; $i++) { $obj = new stdClass(); $obj->amount = 100; $obj->date = new Carbon(); $entries->push($obj); } $data = $this->object->single($bill, $entries); $this->assertCount(5, $data['rows']); $this->assertCount(4, $data['cols']); $this->assertEquals(100, $data['rows'][0]['c'][3]['v']); }
/** * @covers FireflyIII\Http\Controllers\Chart\PiggyBankController::history */ public function testHistory() { $piggy = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank'); $this->be($piggy->account->user); // data: $obj = new stdClass(); $obj->sum = 100; $obj->date = '2015-01-01'; $set = [$obj]; // mock! $repository = $this->mock('FireflyIII\\Repositories\\PiggyBank\\PiggyBankRepositoryInterface'); // fake! $repository->shouldReceive('getEventSummarySet')->andReturn($set); $this->call('GET', '/chart/piggyBank/' . $piggy->id); $this->assertResponseOk(); }
/** * FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator::yearInOut */ public function testYearInOut() { $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->data = 'en'; $preference->save(); // mock language preference: Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); // make set: $collection = new Collection(); for ($i = 0; $i < 5; $i++) { $collection->push([new Carbon(), 200, 100]); } $data = $this->object->yearInOut($collection); $this->assertEquals(200, $data['datasets'][0]['data'][0]); $this->assertEquals(100, $data['datasets'][1]['data'][0]); $this->assertCount(5, $data['labels']); }
/** * Checking getter and setter (might be a silly test). */ public function testMappingToArray() { /** @var \WebservicesNl\Protocol\Soap\Client\SoapSettings $settings */ $settings = FactoryMuffin::create('WebservicesNl\\Protocol\\Soap\\Client\\SoapSettings'); $array = $settings->toArray(); // accessing private properties ... array_walk($array, function ($value, $key) use($settings, $array) { $name = 'get' . ucfirst($key); if (!method_exists($settings, $name)) { $name = 'has' . ucfirst($key); } if (!method_exists($settings, $name)) { $name = 'is' . ucfirst($key); } static::assertEquals($settings->{$name}(), $value, "SoapSetting should have {$key} value"); }); }
/** * @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::year */ public function testYear() { $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->data = 'en'; $preference->save(); $budgets = new Collection(); $entries = new Collection(); // make some budgets: for ($i = 0; $i < 5; $i++) { $budgets->push(FactoryMuffin::create('FireflyIII\\Models\\Budget')); $entries->push([new Carbon(), 100, 100, 100]); } // mock language preference: Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); $data = $this->object->year($budgets, $entries); $this->assertCount(5, $data['labels']); $this->assertCount(5, $data['datasets']); $this->assertCount(3, $data['datasets'][0]['data']); }
public function testCanHaveAndRemovePoints() { $incrementVal = 10; $user = FactoryMuffin::create('RainLab\\User\\Models\\User'); $points = $user->points; $points_this_week = $user->points_this_week; $userExtend = new UserExtend($user); // Add points $userExtend->addPoints($incrementVal); $points += $incrementVal; $points_this_week += $incrementVal; $this->assertEquals($user->points, $points); $this->assertEquals($user->points_this_week, $points_this_week); // Remove Points $userExtend->removePoints($incrementVal); $points -= $incrementVal; $points_this_week -= $incrementVal; $this->assertEquals($user->points, $points); $this->assertEquals($user->points_this_week, $points_this_week); }
/** * @covers FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator::history */ public function testHistory() { $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->data = 'en'; $preference->save(); // mock language preference: Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); // create a set $set = new Collection(); for ($i = 0; $i < 5; $i++) { $obj = new stdClass(); $obj->date = new Carbon(); $obj->sum = 100; $set->push($obj); } $data = $this->object->history($set); $this->assertCount(5, $data['labels']); $this->assertCount(5, $data['datasets'][0]['data']); $this->assertEquals(100, $data['datasets'][0]['data'][0]); $this->assertEquals(500, $data['datasets'][0]['data'][4]); }
/** * @covers FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator::single */ public function testSingle() { $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->data = 'en'; $preference->save(); // mock language preference: Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); $bill = FactoryMuffin::create('FireflyIII\\Models\\Bill'); $entries = new Collection(); for ($i = 0; $i < 5; $i++) { $obj = new stdClass(); $obj->amount = 100; $obj->date = new Carbon(); $entries->push($obj); } $data = $this->object->single($bill, $entries); $this->assertCount(5, $data['labels']); $this->assertCount(5, $data['datasets'][1]['data']); $this->assertEquals(100, $data['datasets'][1]['data'][0]); // see if first is equal. }
/** * @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::single */ public function testSingle() { // be somebody $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->data = 'en'; $preference->save(); // mock language preference: Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference); // mock Steam::balance Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0); // data for call: $start = Carbon::createFromDate(2015, 1, 1); $end = Carbon::createFromDate(2015, 1, 15); $account = FactoryMuffin::create('FireflyIII\\Models\\Account'); // call $result = $this->object->single($account, $start, $end); // test $this->assertCount(15, $result['labels']); $this->assertEquals($account->name, $result['datasets'][0]['label']); $this->assertCount(15, $result['datasets'][0]['data']); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ public function setUp() { parent::setUp(); // if the database copy does not exist, call migrate. $copy = __DIR__ . '/../storage/database/testing-copy.db'; $original = __DIR__ . '/../storage/database/testing.db'; FactoryMuffin::loadFactories(__DIR__ . '/factories'); if (!file_exists($copy)) { touch($original); Artisan::call('migrate'); // create EUR currency /** @var TransactionCurrency $currency */ $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency'); $currency->code = 'EUR'; $currency->save(); copy($original, $copy); } else { if (file_exists($copy)) { copy($copy, $original); } } // if the database copy does exists, copy back as original. $this->session(['start' => Carbon::now()->startOfMonth(), 'end' => Carbon::now()->endOfMonth(), 'first' => Carbon::now()->startOfYear()]); }
/** * @covers FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator::single */ public function testSingle() { // be somebody $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); /** @var Account $account */ $account = FactoryMuffin::create('FireflyIII\\Models\\Account'); // data for call: $start = Carbon::createFromDate(2015, 1, 1); $end = Carbon::createFromDate(2015, 1, 15); // mock Steam::balance Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0); $data = $this->object->single($account, $start, $end); $this->assertCount(3, $data['cols']); // account, date, certainty // fifteen days, $this->assertCount(15, $data['rows']); // 15 days }
/** * When the tag has more than 2 transactions connected to it, it cannot become abalancing act. * * @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing */ public function testTagAllowBalancingManyJournals() { // create a tag $user = FactoryMuffin::create('FireflyIII\\User'); $tag = FactoryMuffin::create('FireflyIII\\Models\\Tag'); $tag->tagMode = 'nothing'; $tag->user_id = $user->id; $tag->save(); // create three journals and connect them: for ($i = 0; $i < 3; $i++) { $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); $journal->tags()->save($tag); } $result = $this->object->tagAllowBalancing($tag); $this->assertFalse($result); }
public function testCreateModelInstance() { $reward = FactoryMuffin::create('DMA\\Friends\\Models\\Reward'); $this->assertInstanceOf('DMA\\Friends\\Models\\Reward', $reward); }
/** * @covers FireflyIII\Http\Controllers\HomeController::index */ public function testIndexEmpty() { $user = FactoryMuffin::create('FireflyIII\\User'); $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface'); $this->be($user); // mock ALL THE THINGS! $repository->shouldReceive('countAccounts')->once()->andReturn(0); // language preference: $language = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); $this->call('GET', '/'); $this->assertResponseStatus(302); $this->assertRedirectedToRoute('new-user.index'); }
/** * @covers FireflyIII\Http\Controllers\PiggyBankController::update */ public function testUpdateReturnToEdit() { $piggyBank = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank'); $this->be($piggyBank->account->user); $piggyBankData = ['name' => 'Some name' . rand(1, 100), 'account_id' => $piggyBank->account_id, 'targetamount' => 200, 'targetdate' => '', 'return_to_edit' => 1, '_token' => 'replaceMe']; // mock! $piggyBanks = $this->mock('FireflyIII\\Repositories\\PiggyBank\\PiggyBankRepositoryInterface'); $piggyBanks->shouldReceive('update')->once()->andReturn($piggyBank); $this->call('POST', '/piggy-banks/update/' . $piggyBank->id, $piggyBankData); $this->assertResponseStatus(302); }