| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @author: <mailto:[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @github: <https://github.com/hryvinskyi> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Hryvinskyi\DeferJs\Test\Unit\Model\PassesValidator\Validators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Hryvinskyi\DeferJs\Helper\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Hryvinskyi\DeferJs\Model\PassesValidator\Validators\SkipScriptByAttribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Hryvinskyi\DeferJs\Model\PassesValidator\Validators\SkipScriptsByPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Magento\Framework\App\Request\Http as RequestHttp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Magento\Framework\App\Response\Http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use PHPUnit_Framework_MockObject_MockObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class SkipScriptsByPathTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var Config|PHPUnit_Framework_MockObject_MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var RequestHttp|PHPUnit_Framework_MockObject_MockObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var Http | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private $http; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @var SkipScriptByAttribute | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     private $model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * Sets up the fixture | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     protected function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $this->config = $this->createPartialMock( | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             Config::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             ['getExcludePaths'] | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->request = $this->createPartialMock( | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             RequestHttp::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             ['getRequestUri'] | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->config->expects($this->any())->method('getExcludePaths') | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             ->willReturn('{"_1554036934542_542":{"path":"\/"}}'); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $this->http = (new ObjectManager($this))->getObject(Http::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $this->model = (new ObjectManager($this))->getObject(SkipScriptsByPath::class, [ | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             'config'  => $this->config, | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             'request' => $this->request, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function testSkipScript(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->request->expects($this->any())->method('getRequestUri')->willReturn('/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertEquals(true, $this->model->validate('', $this->http)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function testNoSkipScript(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->request->expects($this->any())->method('getRequestUri')->willReturn('/someUrl.html'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->assertEquals(false, $this->model->validate('', $this->http)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |  |