| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Created by PhpStorm. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * User: arthur | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Date: 03.10.18 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Time: 22:58. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Foundation\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Foundation\Abstracts\Tests\CreatesApplication; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Foundation\Abstracts\Tests\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Illuminate\Contracts\Auth\Authenticatable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Illuminate\Contracts\Filesystem\Filesystem; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Illuminate\Foundation\Auth\Access\Authorizable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Modules\User\Entities\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class HelpersTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function testClassImplementsHelper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertFalse(classImplementsInterface(self::class, Filesystem::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->assertTrue(classImplementsInterface(self::class, \PHPUnit\Framework\Test::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->assertFalse(classImplementsInterface(new HelpersTest(), Filesystem::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertTrue(classImplementsInterface(new HelpersTest(), \PHPUnit\Framework\Test::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function testUnauthenticatedUserHelper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->expectException(UnauthorizedHttpException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         getAuthenticatedUser(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function testAuthenticatedUserHelper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->actingAs(factory(User::class)->make()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->assertTrue(classImplementsInterface(getAuthenticatedUser(), Authenticatable::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function testClassShortNameHelper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertEquals('HelpersTest', getShortClassName(self::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     public function testRandomArrayElementHelper() | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $array = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             "test", | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             "x", | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             "blabla", | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |             "hello", | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             "hey" | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $randomArrayElement = getRandomArrayElement($array); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->assertContains($randomArrayElement, $array); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function testClassUsesTraitHelper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $this->assertTrue(classUsesTrait(self::class, CreatesApplication::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->assertFalse(classUsesTrait(self::class, Authorizable::class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |  |