mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 10:47:00 +00:00 
			
		
		
		
	More new tests.
This commit is contained in:
		| @@ -12,6 +12,7 @@ install: | |||||||
|   - mv -v .env.testing .env |   - mv -v .env.testing .env | ||||||
|   - php artisan env |   - php artisan env | ||||||
|   - touch storage/upload/at-1.data |   - touch storage/upload/at-1.data | ||||||
|  |   - touch storage/upload/at-2.data | ||||||
|   - touch storage/database/testing.db |   - touch storage/database/testing.db | ||||||
|   - php artisan migrate --seed |   - php artisan migrate --seed | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ use FireflyIII\Models\Attachment; | |||||||
| use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; | use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; | ||||||
| use Input; | use Input; | ||||||
| use Preferences; | use Preferences; | ||||||
|  | use Request; | ||||||
| use Response; | use Response; | ||||||
| use Session; | use Session; | ||||||
| use URL; | use URL; | ||||||
| @@ -100,17 +101,17 @@ class AttachmentController extends Controller | |||||||
|  |  | ||||||
|             $quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\')); |             $quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\')); | ||||||
|  |  | ||||||
|             header('Content-Description: File Transfer'); |             Request::header('Content-Description: File Transfer'); | ||||||
|             header('Content-Type: application/octet-stream'); |             Request::header('Content-Type: application/octet-stream'); | ||||||
|             header('Content-Disposition: attachment; filename=' . $quoted); |             Request::header('Content-Disposition: attachment; filename=' . $quoted); | ||||||
|             header('Content-Transfer-Encoding: binary'); |             Request::header('Content-Transfer-Encoding: binary'); | ||||||
|             header('Connection: Keep-Alive'); |             Request::header('Connection: Keep-Alive'); | ||||||
|             header('Expires: 0'); |             Request::header('Expires: 0'); | ||||||
|             header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |             Request::header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | ||||||
|             header('Pragma: public'); |             Request::header('Pragma: public'); | ||||||
|             header('Content-Length: ' . $attachment->size); |             Request::header('Content-Length: ' . $attachment->size); | ||||||
|  |  | ||||||
|             echo Crypt::decrypt(file_get_contents($file)); |             return Crypt::decrypt(file_get_contents($file)); | ||||||
|  |  | ||||||
|         } else { |         } else { | ||||||
|             abort(404); |             abort(404); | ||||||
|   | |||||||
| @@ -3,12 +3,15 @@ | |||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use FireflyIII\Models\Account; | use FireflyIII\Models\Account; | ||||||
| use FireflyIII\Models\AccountMeta; | use FireflyIII\Models\AccountMeta; | ||||||
|  | use FireflyIII\Models\Attachment; | ||||||
| use FireflyIII\Models\Bill; | use FireflyIII\Models\Bill; | ||||||
| use FireflyIII\Models\Budget; | use FireflyIII\Models\Budget; | ||||||
| use FireflyIII\Models\BudgetLimit; | use FireflyIII\Models\BudgetLimit; | ||||||
| use FireflyIII\Models\Category; | use FireflyIII\Models\Category; | ||||||
| use FireflyIII\Models\PiggyBank; | use FireflyIII\Models\PiggyBank; | ||||||
| use FireflyIII\Models\PiggyBankEvent; | use FireflyIII\Models\PiggyBankEvent; | ||||||
|  | use FireflyIII\Models\Transaction; | ||||||
|  | use FireflyIII\Models\TransactionJournal; | ||||||
| use FireflyIII\User; | use FireflyIII\User; | ||||||
| use Illuminate\Database\Seeder; | use Illuminate\Database\Seeder; | ||||||
|  |  | ||||||
| @@ -41,6 +44,15 @@ class TestDataSeeder extends Seeder | |||||||
|  |  | ||||||
|         // create some piggy banks for user #1 |         // create some piggy banks for user #1 | ||||||
|         $this->createPiggybanks($user); |         $this->createPiggybanks($user); | ||||||
|  |  | ||||||
|  |         // create some expense accounts for user #1 | ||||||
|  |         $this->createExpenseAccounts($user); | ||||||
|  |  | ||||||
|  |         // create some revenue accounts for user #1 | ||||||
|  |         $this->createRevenueAccounts($user); | ||||||
|  |  | ||||||
|  |         // create journal + attachment: | ||||||
|  |         $this->createAttachments($user); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -153,12 +165,11 @@ class TestDataSeeder extends Seeder | |||||||
|         Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); |         Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||||
|      * @param User $user |      * @param User $user | ||||||
|      */ |      */ | ||||||
|     protected function createPiggybanks(User $user) |     private function createPiggybanks(User $user) | ||||||
|     { |     { | ||||||
|         $account = $this->findAccount($user, 'TestData Savings'); |         $account = $this->findAccount($user, 'TestData Savings'); | ||||||
|  |  | ||||||
| @@ -298,11 +309,11 @@ class TestDataSeeder extends Seeder | |||||||
|      * |      * | ||||||
|      * @return Account|null |      * @return Account|null | ||||||
|      */ |      */ | ||||||
|     protected function findAccount(User $user, $name) |     private function findAccount(User $user, $name) | ||||||
|     { |     { | ||||||
|         /** @var Account $account */ |         /** @var Account $account */ | ||||||
|         foreach (Account::get() as $account) { |         foreach ($user->accounts()->get() as $account) { | ||||||
|             if ($account->name == $name && $user->id == $account->user_id) { |             if ($account->name == $name) { | ||||||
|                 return $account; |                 return $account; | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
| @@ -310,4 +321,125 @@ class TestDataSeeder extends Seeder | |||||||
|  |  | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param User $user | ||||||
|  |      */ | ||||||
|  |     private function createExpenseAccounts(User $user) | ||||||
|  |     { | ||||||
|  |         $expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl', | ||||||
|  |                      'coolblue', 'Shell', | ||||||
|  |                      'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord']; | ||||||
|  |         foreach ($expenses as $name) { | ||||||
|  |             // create account: | ||||||
|  |             Account::create( | ||||||
|  |                 [ | ||||||
|  |                     'user_id'         => $user->id, | ||||||
|  |                     'account_type_id' => 4, | ||||||
|  |                     'name'            => $name, | ||||||
|  |                     'active'          => 1, | ||||||
|  |                     'encrypted'       => 1, | ||||||
|  |                 ] | ||||||
|  |             ); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param User $user | ||||||
|  |      */ | ||||||
|  |     private function createRevenueAccounts(User $user) | ||||||
|  |     { | ||||||
|  |         $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google']; | ||||||
|  |         foreach ($revenues as $name) { | ||||||
|  |             // create account: | ||||||
|  |             Account::create( | ||||||
|  |                 [ | ||||||
|  |                     'user_id'         => $user->id, | ||||||
|  |                     'account_type_id' => 5, | ||||||
|  |                     'name'            => $name, | ||||||
|  |                     'active'          => 1, | ||||||
|  |                     'encrypted'       => 1, | ||||||
|  |                 ] | ||||||
|  |             ); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @param User $user | ||||||
|  |      */ | ||||||
|  |     private function createAttachments(User $user) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $toAccount   = $this->findAccount($user, 'TestData Checking Account'); | ||||||
|  |         $fromAccount = $this->findAccount($user, 'Job'); | ||||||
|  |  | ||||||
|  |         $journal = TransactionJournal::create( | ||||||
|  |             [ | ||||||
|  |                 'user_id'                 => $user->id, | ||||||
|  |                 'transaction_type_id'     => 2, | ||||||
|  |                 'transaction_currency_id' => 1, | ||||||
|  |                 'description'             => 'Some journal for attachment', | ||||||
|  |                 'completed'               => 1, | ||||||
|  |                 'date'                    => new Carbon, | ||||||
|  |             ] | ||||||
|  |         ); | ||||||
|  |         Transaction::create( | ||||||
|  |             [ | ||||||
|  |                 'account_id'             => $fromAccount->id, | ||||||
|  |                 'transaction_journal_id' => $journal->id, | ||||||
|  |                 'amount'                 => -100, | ||||||
|  |  | ||||||
|  |             ] | ||||||
|  |         ); | ||||||
|  |         Transaction::create( | ||||||
|  |             [ | ||||||
|  |                 'account_id'             => $toAccount->id, | ||||||
|  |                 'transaction_journal_id' => $journal->id, | ||||||
|  |                 'amount'                 => 100, | ||||||
|  |  | ||||||
|  |             ] | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |         // and now attachments | ||||||
|  |         $encrypted  = Crypt::encrypt('I are secret'); | ||||||
|  |         Attachment::create( | ||||||
|  |             [ | ||||||
|  |                 'attachable_id'   => $journal->id, | ||||||
|  |                 'attachable_type' => 'FireflyIII\Models\TransactionJournal', | ||||||
|  |                 'user_id'         => $user->id, | ||||||
|  |                 'md5'             => md5('Hallo'), | ||||||
|  |                 'filename'        => 'empty-file.txt', | ||||||
|  |                 'title'           => 'Empty file', | ||||||
|  |                 'description'     => 'This file is empty', | ||||||
|  |                 'notes'           => 'What notes', | ||||||
|  |                 'mime'            => 'text/plain', | ||||||
|  |                 'size'            => strlen($encrypted), | ||||||
|  |                 'uploaded'        => 1, | ||||||
|  |             ] | ||||||
|  |         ); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         // and now attachment. | ||||||
|  |         Attachment::create( | ||||||
|  |             [ | ||||||
|  |                 'attachable_id'   => $journal->id, | ||||||
|  |                 'attachable_type' => 'FireflyIII\Models\TransactionJournal', | ||||||
|  |                 'user_id'         => $user->id, | ||||||
|  |                 'md5'             => md5('Ook hallo'), | ||||||
|  |                 'filename'        => 'empty-file-2.txt', | ||||||
|  |                 'title'           => 'Empty file 2', | ||||||
|  |                 'description'     => 'This file is empty too', | ||||||
|  |                 'notes'           => 'What notes do', | ||||||
|  |                 'mime'            => 'text/plain', | ||||||
|  |                 'size'            => strlen($encrypted), | ||||||
|  |                 'uploaded'        => 1, | ||||||
|  |             ] | ||||||
|  |         ); | ||||||
|  |         // echo crypted data to the file. | ||||||
|  |         file_put_contents(storage_path('upload/at-1.data'), $encrypted); | ||||||
|  |         file_put_contents(storage_path('upload/at-2.data'), $encrypted); | ||||||
|  |  | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								pu.sh
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								pu.sh
									
									
									
									
									
								
							| @@ -6,6 +6,11 @@ cp .env.testing .env | |||||||
| # set default phpunit. | # set default phpunit. | ||||||
| cp phpunit.default.xml phpunit.xml | cp phpunit.default.xml phpunit.xml | ||||||
|  |  | ||||||
|  | # "create" default attachment: | ||||||
|  | touch storage/upload/at-1.data | ||||||
|  | touch storage/upload/at-2.data | ||||||
|  |  | ||||||
|  |  | ||||||
| # delete test databases: | # delete test databases: | ||||||
| if [ -f storage/database/testing.db ] | if [ -f storage/database/testing.db ] | ||||||
| then | then | ||||||
|   | |||||||
| @@ -15,73 +15,78 @@ class AttachmentControllerTest extends TestCase | |||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::delete |      * @covers FireflyIII\Http\Controllers\AttachmentController::delete | ||||||
|      * @todo   Implement testDelete(). |  | ||||||
|      */ |      */ | ||||||
|     public function testDelete() |     public function testDelete() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->be($this->user()); | ||||||
|         $this->markTestIncomplete( |         $response = $this->call('GET', '/attachment/delete/1'); | ||||||
|             'This test has not been implemented yet.' |         $this->assertEquals(200, $response->status()); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::destroy |      * @covers FireflyIII\Http\Controllers\AttachmentController::destroy | ||||||
|      * @todo   Implement testDestroy(). |  | ||||||
|      */ |      */ | ||||||
|     public function testDestroy() |     public function testDestroy() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->be($this->user()); | ||||||
|         $this->markTestIncomplete( |  | ||||||
|             'This test has not been implemented yet.' |         $args = [ | ||||||
|         ); |             '_token' => Session::token(), | ||||||
|  |         ]; | ||||||
|  |  | ||||||
|  |         $this->session(['attachments.delete.url' => 'http://localhost']); | ||||||
|  |  | ||||||
|  |         $response = $this->call('POST', '/attachment/destroy/2', $args); | ||||||
|  |         $this->assertEquals(302, $response->status()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::download |      * @covers FireflyIII\Http\Controllers\AttachmentController::download | ||||||
|      * @todo   Implement testDownload(). |  | ||||||
|      */ |      */ | ||||||
|     public function testDownload() |     public function testDownload() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->be($this->user()); | ||||||
|         $this->markTestIncomplete( |         $response = $this->call('GET', '/attachment/download/1'); | ||||||
|             'This test has not been implemented yet.' |         $this->assertEquals(200, $response->status()); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::edit |      * @covers FireflyIII\Http\Controllers\AttachmentController::edit | ||||||
|      * @todo   Implement testEdit(). |  | ||||||
|      */ |      */ | ||||||
|     public function testEdit() |     public function testEdit() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->be($this->user()); | ||||||
|         $this->markTestIncomplete( |         $response = $this->call('GET', '/attachment/edit/1'); | ||||||
|             'This test has not been implemented yet.' |         $this->assertEquals(200, $response->status()); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::preview |      * @covers FireflyIII\Http\Controllers\AttachmentController::preview | ||||||
|      * @todo   Implement testPreview(). |  | ||||||
|      */ |      */ | ||||||
|     public function testPreview() |     public function testPreview() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->be($this->user()); | ||||||
|         $this->markTestIncomplete( |         $response = $this->call('GET', '/attachment/preview/1'); | ||||||
|             'This test has not been implemented yet.' |         $this->assertEquals(200, $response->status()); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @covers FireflyIII\Http\Controllers\AttachmentController::update |      * @covers FireflyIII\Http\Controllers\AttachmentController::update | ||||||
|      * @todo   Implement testUpdate(). |  | ||||||
|      */ |      */ | ||||||
|     public function testUpdate() |     public function testUpdate() | ||||||
|     { |     { | ||||||
|         // Remove the following lines when you implement this test. |         $this->session(['attachments.edit.url' => 'http://localhost']); | ||||||
|         $this->markTestIncomplete( |  | ||||||
|             'This test has not been implemented yet.' |         $args = [ | ||||||
|         ); |             'title'       => 'New title', | ||||||
|  |             'description' => 'New descr', | ||||||
|  |             'notes'       => 'New notes', | ||||||
|  |             '_token'      => Session::token(), | ||||||
|  |         ]; | ||||||
|  |         $this->be($this->user()); | ||||||
|  |  | ||||||
|  |         $response = $this->call('POST', '/attachment/update/1', $args); | ||||||
|  |         $this->assertEquals(302, $response->status()); | ||||||
|  |         $this->assertSessionHas('success'); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user