| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Nip\Filesystem\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use League\Flysystem\Adapter\Local; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Nip\Filesystem\FileDisk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\HttpFoundation\StreamedResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class FileDiskTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package Nip\Filesystem\Tests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class FileDiskTest extends AbstractTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $fileDisk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function testResponse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->fileDisk->write('file.txt', 'Hello World'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $response = $this->fileDisk->response('file.txt'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         ob_start(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $response->sendContent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $content = ob_get_clean(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         static::assertInstanceOf(StreamedResponse::class, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         static::assertEquals('Hello World', $content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         static::assertEquals('inline; filename=file.txt', $response->headers->get('content-disposition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function testDownload() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->fileDisk->write('file.txt', 'Hello World'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $response = $this->fileDisk->download('file.txt', 'hello.txt'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         static::assertInstanceOf(StreamedResponse::class, $response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         static::assertEquals('attachment; filename=hello.txt', $response->headers->get('content-disposition')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     protected function tearDown(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         parent::tearDown(); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $filesystem = new FileDisk(new Local(TEST_FIXTURE_PATH . '/storage')); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $filesystem->deleteDir('tmp'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     protected function setUp(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->fileDisk = new FileDisk(new Local(TEST_FIXTURE_PATH . '/storage/tmp')); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 52 |  |  | } |