| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace TractorCow\Fluent\Tests\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Page; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\CMS\Model\SiteTree; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Control\Director; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Core\Config\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\Dev\SapphireTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\ORM\ArrayList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\View\ArrayData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use TractorCow\Fluent\Extension\FluentDirectorExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use TractorCow\Fluent\Extension\FluentSiteTreeExtension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use TractorCow\Fluent\Model\Domain; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use TractorCow\Fluent\Model\Locale; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use TractorCow\Fluent\State\FluentState; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class FluentSiteTreeExtensionTest extends SapphireTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     protected static $fixture_file = 'FluentSiteTreeExtensionTest.yml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected static $required_extensions = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         SiteTree::class => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             FluentSiteTreeExtension::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         Config::modify() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ->set(Director::class, 'alternate_base_url', 'http://mocked') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->set(FluentDirectorExtension::class, 'disable_default_prefix', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         // Clear cache | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         Locale::clearCached(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         Domain::clearCached(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         FluentState::singleton() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->setLocale('de_DE') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ->setIsDomainMode(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function testGetLocaleInformation() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         /** @var Page|FluentSiteTreeExtension $page */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $page = $this->objFromFixture(Page::class, 'nz-page'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $result = $page->LocaleInformation('en_NZ'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->assertInstanceOf(ArrayData::class, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->assertEquals([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'Locale' => 'en_NZ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             'LocaleRFC1766' => 'en-NZ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             'Title' => 'English (New Zealand)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             'LanguageNative' => 'English', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'Language' => 'en', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             'Link' => '/newzealand/a-page/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             'AbsoluteLink' => 'http://mocked/newzealand/a-page/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             'LinkingMode' => 'link', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             'URLSegment' => 'newzealand' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ], $result->toMap()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function testGetLocales() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         /** @var Page|FluentSiteTreeExtension $page */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $page = $this->objFromFixture(Page::class, 'nz-page'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $result = $page->Locales(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertInstanceOf(ArrayList::class, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->assertCount(4, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertListEquals([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ['Locale' => 'en_NZ'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             ['Locale' => 'de_DE'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ['Locale' => 'en_US'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ['Locale' => 'es_ES'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ], $result); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Tests for url generation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @return array list of tests with values: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      *  - domain (or false for non-domain mode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      *  - locale | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      *  - disable_default_prefix flag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      *  - page id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      *  - expected link | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     public function provideURLTests() | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         return [ | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |             // Non-domain tests | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |             [null, 'de_DE', false, 'home', '/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |             [null, 'de_DE', false, 'about', '/german/about-us/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |             [null, 'de_DE', false, 'staff', '/german/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |             // Since de_DE is the only locale on the www.example.de domain, ensure that the locale | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |             // isn't unnecessarily added to the link. | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |             // In this case disable_default_prefix is ignored | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |             // See https://github.com/tractorcow/silverstripe-fluent/issues/75 | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |             ['www.example.de', 'de_DE', false, 'home', '/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |             ['www.example.de', 'de_DE', false, 'about', '/about-us/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |             ['www.example.de', 'de_DE', false, 'staff', '/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |             // Test domains with multiple locales | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |             //  - es_ES non default locale | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |             ['www.example.com', 'es_ES', false, 'home', '/es_ES/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |             ['www.example.com', 'es_ES', false, 'about', '/es_ES/about-us/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |             ['www.example.com', 'es_ES', false, 'staff', '/es_ES/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |             //  - en_US default locale | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |             ['www.example.com', 'en_US', false, 'home', '/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |             ['www.example.com', 'en_US', false, 'about', '/usa/about-us/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |             ['www.example.com', 'en_US', false, 'staff', '/usa/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |             //  - en_US default locale, but with disable_default_prefix on | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |             ['www.example.com', 'en_US', true, 'home', '/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             ['www.example.com', 'en_US', true, 'about', '/about-us/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |             ['www.example.com', 'en_US', true, 'staff', '/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |             // Test cross-domain links include the opposing domain | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |             // - to default locale | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |             ['www.example.de', 'en_US', true, 'home', 'http://www.example.com/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |             ['www.example.de', 'en_US', true, 'staff', 'http://www.example.com/about-us/my-staff/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |             // - to non defalut locale | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |             ['www.example.de', 'es_ES', true, 'home', 'http://www.example.com/es_ES/'], | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |             ['www.example.de', 'es_ES', true, 'staff', 'http://www.example.com/es_ES/about-us/my-staff/'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * Test that URLS for pages are generated correctly | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * @dataProvider provideURLTests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * @param string $domain | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @param string $locale | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * @param bool $prefixDisabled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @param string $pageName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @param string $url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     public function testFluentURLs($domain, $locale, $prefixDisabled, $pageName, $url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         // Set state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         FluentState::singleton() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             ->setLocale($locale) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             ->setDomain($domain) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             ->setIsDomainMode(!empty($domain)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         // Set url generation option | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         Config::modify() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             ->set(FluentDirectorExtension::class, 'disable_default_prefix', $prefixDisabled); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         /** @var Page|FluentSiteTreeExtension $page */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $page = $this->objFromFixture('Page', $pageName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $this->assertEquals($url, $page->Link()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 153 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 154 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths