|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodingSocks\ChunkUploader\Tests\Identifier; |
| 4 | + |
| 5 | +use CodingSocks\ChunkUploader\Identifier\AuthIdentifier; |
| 6 | +use Illuminate\Support\Facades\Auth; |
| 7 | +use Illuminate\Validation\UnauthorizedException; |
| 8 | +use Orchestra\Testbench\TestCase; |
| 9 | + |
| 10 | +class AuthIdentifierTest extends TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @var \CodingSocks\ChunkUploader\Identifier\Identifier |
| 14 | + */ |
| 15 | + private $identifier; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + Auth::shouldReceive('id') |
| 22 | + ->andReturn(100); |
| 23 | + |
| 24 | + $this->identifier = new AuthIdentifier(); |
| 25 | + } |
| 26 | + |
| 27 | + protected function tearDown(): void |
| 28 | + { |
| 29 | + parent::tearDown(); |
| 30 | + |
| 31 | + Auth::clearResolvedInstances(); |
| 32 | + } |
| 33 | + |
| 34 | + public function testGenerateIdentifierThrowsUnauthorizedException() |
| 35 | + { |
| 36 | + Auth::shouldReceive('check') |
| 37 | + ->andReturn(false); |
| 38 | + |
| 39 | + $this->expectException(UnauthorizedException::class); |
| 40 | + $this->identifier->generateIdentifier('any_string'); |
| 41 | + } |
| 42 | + |
| 43 | + public function testGenerateIdentifier() |
| 44 | + { |
| 45 | + Auth::shouldReceive('check') |
| 46 | + ->andReturn(true); |
| 47 | + |
| 48 | + $identifier = $this->identifier->generateIdentifier('any_string'); |
| 49 | + $this->assertEquals('2b2ea43a7652e1f7925c588b9ae7a31f09be3bf9', $identifier); |
| 50 | + } |
| 51 | + |
| 52 | + public function testUploadedFileIdentifierName() |
| 53 | + { |
| 54 | + Auth::shouldReceive('check') |
| 55 | + ->andReturn(true); |
| 56 | + |
| 57 | + $identifier = $this->identifier->generateFileIdentifier(200, 'any_filename.ext'); |
| 58 | + $this->assertEquals('4317e3d56e27deda5bd84dd35830bff799736257', $identifier); |
| 59 | + } |
| 60 | +} |
0 commit comments