Last active
July 22, 2019 10:45
-
-
Save j-dexx/9b480ae41482a5a9eac393214504ddae to your computer and use it in GitHub Desktop.
Testing File Uploads in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyTest extends TestCase | |
| { | |
| public function test_successful() | |
| { | |
| $type = factory(Type::class)->create([ | |
| 'type' => Type::TYPE_CHECK_IN, | |
| ]); | |
| $admin = $this->createAdmin(); | |
| $client = factory(Client::class)->create(); | |
| $user = factory(User::class)->create([ | |
| 'client_id' => $client->id, | |
| 'email' => 'jeff@example.com', | |
| ]); | |
| $url = $this->url(); | |
| $csv = new UploadedFile(base_path('tests/Resources/touchdown-check-in-import.csv'), 'touchdown-check-in-import.csv', 'text/csv', null, null, true); | |
| $data = [ | |
| 'client_id' => $client->id, | |
| ]; | |
| $files = [ | |
| 'csv' => $csv, | |
| ]; | |
| $response = $this->actingAs($admin)->call('POST', $url, $data, [], $files); | |
| $response->assertRedirect(); | |
| $this->assertDatabaseHas('tracking_events', [ | |
| 'tracking_event_type_id' => $type->id, | |
| 'user_id' => $user->id, | |
| 'source' => Point::OPERATOR_SOURCE, | |
| ]); | |
| $this->assertDatabaseHas('tracking_points', [ | |
| 'source' => Point::OPERATOR_SOURCE, | |
| 'latitude' => 53.72296, | |
| 'longitude' => -0.43833, | |
| 'timestamp' => Carbon::parse('22-07-2019 10:36')->toDateTimeString(), | |
| ]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment