@@ -15,253 +15,253 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | class SectionIOTest extends SapphireTest  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - protected static $fixture_file = 'SectionIOTest.yml';  | 
                                                        |
| 19 | -  | 
                                                        |
| 20 | - public static function setUpBeforeClass()  | 
                                                        |
| 21 | -    { | 
                                                        |
| 22 | - // add config values  | 
                                                        |
| 23 | - Config::modify()->set(SectionIO::class, 'flush_on_dev_build', true);  | 
                                                        |
| 24 | - Config::modify()->set(SectionIO::class, 'api_url', 'https://example.com');  | 
                                                        |
| 25 | - Config::modify()->set(SectionIO::class, 'account_id', '123456');  | 
                                                        |
| 26 | - Config::modify()->set(SectionIO::class, 'application_id', '987654');  | 
                                                        |
| 27 | - Config::modify()->set(SectionIO::class, 'environment_name', 'Production');  | 
                                                        |
| 28 | - Config::modify()->set(SectionIO::class, 'proxy_name', 'myproxy');  | 
                                                        |
| 29 | - Config::modify()->set(SectionIO::class, 'username', 'someuser');  | 
                                                        |
| 30 | - Config::modify()->set(SectionIO::class, 'password', 'MySafePassword');  | 
                                                        |
| 31 | - Config::modify()->set(SectionIO::class, 'verify_ssl', false);  | 
                                                        |
| 32 | -  | 
                                                        |
| 33 | - // remove extensions otherwise the fixtures will break the tests (by calling the live flush)  | 
                                                        |
| 34 | - File::remove_extension(SectionIOFileExtension::class);  | 
                                                        |
| 35 | - SiteTree::remove_extension(SectionIOSiteTreeExtension::class);  | 
                                                        |
| 36 | - }  | 
                                                        |
| 37 | -  | 
                                                        |
| 38 | - public function setUp()  | 
                                                        |
| 39 | -    { | 
                                                        |
| 40 | - // Set backend root to /ImageTest  | 
                                                        |
| 41 | -        TestAssetStore::activate('FileTest'); | 
                                                        |
| 18 | + protected static $fixture_file = 'SectionIOTest.yml';  | 
                                                        |
| 19 | +  | 
                                                        |
| 20 | + public static function setUpBeforeClass()  | 
                                                        |
| 21 | +	{ | 
                                                        |
| 22 | + // add config values  | 
                                                        |
| 23 | + Config::modify()->set(SectionIO::class, 'flush_on_dev_build', true);  | 
                                                        |
| 24 | + Config::modify()->set(SectionIO::class, 'api_url', 'https://example.com');  | 
                                                        |
| 25 | + Config::modify()->set(SectionIO::class, 'account_id', '123456');  | 
                                                        |
| 26 | + Config::modify()->set(SectionIO::class, 'application_id', '987654');  | 
                                                        |
| 27 | + Config::modify()->set(SectionIO::class, 'environment_name', 'Production');  | 
                                                        |
| 28 | + Config::modify()->set(SectionIO::class, 'proxy_name', 'myproxy');  | 
                                                        |
| 29 | + Config::modify()->set(SectionIO::class, 'username', 'someuser');  | 
                                                        |
| 30 | + Config::modify()->set(SectionIO::class, 'password', 'MySafePassword');  | 
                                                        |
| 31 | + Config::modify()->set(SectionIO::class, 'verify_ssl', false);  | 
                                                        |
| 32 | +  | 
                                                        |
| 33 | + // remove extensions otherwise the fixtures will break the tests (by calling the live flush)  | 
                                                        |
| 34 | + File::remove_extension(SectionIOFileExtension::class);  | 
                                                        |
| 35 | + SiteTree::remove_extension(SectionIOSiteTreeExtension::class);  | 
                                                        |
| 36 | + }  | 
                                                        |
| 37 | +  | 
                                                        |
| 38 | + public function setUp()  | 
                                                        |
| 39 | +	{ | 
                                                        |
| 40 | + // Set backend root to /ImageTest  | 
                                                        |
| 41 | +		TestAssetStore::activate('FileTest'); | 
                                                        |
| 42 | 42 | |
| 43 | - // Create a test files for each of the fixture references  | 
                                                        |
| 44 | - $fileIDs = array_merge(  | 
                                                        |
| 45 | - $this->allFixtureIDs(File::class),  | 
                                                        |
| 46 | - $this->allFixtureIDs(Image::class)  | 
                                                        |
| 47 | - );  | 
                                                        |
| 48 | -        foreach ($fileIDs as $fileID) { | 
                                                        |
| 49 | - /** @var File $file */  | 
                                                        |
| 50 | - $file = DataObject::get_by_id(File::class, $fileID);  | 
                                                        |
| 51 | -            $file->setFromString(str_repeat('x', 1000000), $file->getFilename()); | 
                                                        |
| 52 | - }  | 
                                                        |
| 43 | + // Create a test files for each of the fixture references  | 
                                                        |
| 44 | + $fileIDs = array_merge(  | 
                                                        |
| 45 | + $this->allFixtureIDs(File::class),  | 
                                                        |
| 46 | + $this->allFixtureIDs(Image::class)  | 
                                                        |
| 47 | + );  | 
                                                        |
| 48 | +		foreach ($fileIDs as $fileID) { | 
                                                        |
| 49 | + /** @var File $file */  | 
                                                        |
| 50 | + $file = DataObject::get_by_id(File::class, $fileID);  | 
                                                        |
| 51 | +			$file->setFromString(str_repeat('x', 1000000), $file->getFilename()); | 
                                                        |
| 52 | + }  | 
                                                        |
| 53 | 53 | |
| 54 | - }  | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | - public static function tearDownAfterClass()  | 
                                                        |
| 57 | -    { | 
                                                        |
| 58 | - // re-add extensions  | 
                                                        |
| 59 | -        File::add_extension('SectionIOFileExtension'); | 
                                                        |
| 60 | -        SiteTree::add_extension('SectionIOSiteTreeExtension'); | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - public function tearDown()  | 
                                                        |
| 64 | -    { | 
                                                        |
| 65 | - TestAssetStore::reset();  | 
                                                        |
| 66 | - }  | 
                                                        |
| 67 | -  | 
                                                        |
| 68 | - public function testFlushAll()  | 
                                                        |
| 69 | -    { | 
                                                        |
| 70 | - $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - $this->assertCount(  | 
                                                        |
| 73 | - 1,  | 
                                                        |
| 74 | - $result,  | 
                                                        |
| 75 | - 'one url returned for one application id'  | 
                                                        |
| 76 | - );  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - // url  | 
                                                        |
| 79 | - $this->assertEquals(  | 
                                                        |
| 80 | - 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 81 | - $result[0]['url'],  | 
                                                        |
| 82 | - 'URL is concatenated correctly'  | 
                                                        |
| 83 | - );  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - // ban expression  | 
                                                        |
| 86 | - $this->assertEquals(  | 
                                                        |
| 87 | - 'obj.http.x-url ~ /',  | 
                                                        |
| 88 | - $result[0]['banExpression'],  | 
                                                        |
| 89 | - 'ban expression is correct'  | 
                                                        |
| 90 | - );  | 
                                                        |
| 91 | -  | 
                                                        |
| 92 | - }  | 
                                                        |
| 93 | -  | 
                                                        |
| 94 | - public function testFlush()  | 
                                                        |
| 95 | -    { | 
                                                        |
| 96 | - $result = SectionIOTest_MySectionIO::flush();  | 
                                                        |
| 97 | -  | 
                                                        |
| 98 | - $this->assertCount(  | 
                                                        |
| 99 | - 1,  | 
                                                        |
| 100 | - $result,  | 
                                                        |
| 101 | - 'one url returned for one application id'  | 
                                                        |
| 102 | - );  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - // url  | 
                                                        |
| 105 | - $this->assertEquals(  | 
                                                        |
| 106 | - 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 107 | - $result[0]['url'],  | 
                                                        |
| 108 | - 'URL is concatenated correctly'  | 
                                                        |
| 109 | - );  | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | - // ban expression  | 
                                                        |
| 112 | - $this->assertEquals(  | 
                                                        |
| 113 | - 'obj.http.x-url ~ /',  | 
                                                        |
| 114 | - $result[0]['banExpression'],  | 
                                                        |
| 115 | - 'ban expression is correct'  | 
                                                        |
| 116 | - );  | 
                                                        |
| 117 | -  | 
                                                        |
| 118 | - // test deactivated flush on build  | 
                                                        |
| 119 | - Config::modify()->set(SectionIO::class, 'flush_on_dev_build', false);  | 
                                                        |
| 120 | - $result = SectionIOTest_MySectionIO::flush();  | 
                                                        |
| 121 | - $this->assertNull(  | 
                                                        |
| 122 | - $result,  | 
                                                        |
| 123 | - 'null returned if flush on build deactivated'  | 
                                                        |
| 124 | - );  | 
                                                        |
| 125 | - }  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - public function testMultipleApplicationIDs()  | 
                                                        |
| 128 | -    { | 
                                                        |
| 129 | - // add second application to config  | 
                                                        |
| 130 | - Config::modify()->set(SectionIO::class, 'application_id', '2546987,856954');  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | - $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 133 | -  | 
                                                        |
| 134 | - $this->assertCount(  | 
                                                        |
| 135 | - 2,  | 
                                                        |
| 136 | - $result,  | 
                                                        |
| 137 | - 'two urls returned for two application id'  | 
                                                        |
| 138 | - );  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | - // url  | 
                                                        |
| 141 | - $this->assertEquals(  | 
                                                        |
| 142 | - 'https://example.com/account/123456/application/2546987/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 143 | - $result[0]['url'],  | 
                                                        |
| 144 | - 'URL is concatenated correctly for app 1'  | 
                                                        |
| 145 | - );  | 
                                                        |
| 146 | - $this->assertEquals(  | 
                                                        |
| 147 | - 'https://example.com/account/123456/application/856954/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 148 | - $result[1]['url'],  | 
                                                        |
| 149 | - 'URL is concatenated correctly for app 2'  | 
                                                        |
| 150 | - );  | 
                                                        |
| 151 | -  | 
                                                        |
| 152 | - // add second application to config with spaces in csv  | 
                                                        |
| 153 | - Config::modify()->set(SectionIO::class, 'application_id', '741852, 369258');  | 
                                                        |
| 154 | -  | 
                                                        |
| 155 | - $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 156 | -  | 
                                                        |
| 157 | - $this->assertCount(  | 
                                                        |
| 158 | - 2,  | 
                                                        |
| 159 | - $result,  | 
                                                        |
| 160 | - 'two urls returned for two application id'  | 
                                                        |
| 161 | - );  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | - // url  | 
                                                        |
| 164 | - $this->assertEquals(  | 
                                                        |
| 165 | - 'https://example.com/account/123456/application/741852/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 166 | - $result[0]['url'],  | 
                                                        |
| 167 | - 'URL is concatenated correctly for app 1'  | 
                                                        |
| 168 | - );  | 
                                                        |
| 169 | - $this->assertEquals(  | 
                                                        |
| 170 | - 'https://example.com/account/123456/application/369258/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 171 | - $result[1]['url'],  | 
                                                        |
| 172 | - 'URL is concatenated correctly for app 2'  | 
                                                        |
| 173 | - );  | 
                                                        |
| 174 | - }  | 
                                                        |
| 175 | -  | 
                                                        |
| 176 | - public function testFlushImage()  | 
                                                        |
| 177 | -    { | 
                                                        |
| 178 | -        $imageId = $this->idFromFixture('Image', 'testImage'); | 
                                                        |
| 179 | -  | 
                                                        |
| 180 | - $result = SectionIOTest_MySectionIO::flushImage($imageId);  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - // ban expression  | 
                                                        |
| 183 | - $this->assertEquals(  | 
                                                        |
| 184 | - 'obj.http.x-url ~ "^/assets/SectionTest/test_image\.png$"'  | 
                                                        |
| 185 | - .' || obj.http.x-url ~ "^/assets/SectionTest/test_image__[a-zA-Z0-9_]*\.png$"',  | 
                                                        |
| 186 | - $result[0]['banExpression'],  | 
                                                        |
| 187 | - 'ban expression is correct'  | 
                                                        |
| 188 | - );  | 
                                                        |
| 189 | - }  | 
                                                        |
| 190 | -  | 
                                                        |
| 191 | - public function testFlushFile()  | 
                                                        |
| 192 | -    { | 
                                                        |
| 193 | -        $fileId = $this->idFromFixture('File', 'testFile'); | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | - $result = SectionIOTest_MySectionIO::flushFile($fileId);  | 
                                                        |
| 196 | -  | 
                                                        |
| 197 | - // ban expression  | 
                                                        |
| 198 | - $this->assertEquals(  | 
                                                        |
| 199 | - 'obj.http.x-url ~ "^/assets/SectionTest/test_document\.pdf$"',  | 
                                                        |
| 200 | - $result[0]['banExpression'],  | 
                                                        |
| 201 | - 'ban expression is correct'  | 
                                                        |
| 202 | - );  | 
                                                        |
| 203 | - }  | 
                                                        |
| 204 | -  | 
                                                        |
| 205 | - public function testFlushSiteTree()  | 
                                                        |
| 206 | -    { | 
                                                        |
| 207 | -        $pageId = $this->idFromFixture('Page', 'ceo'); | 
                                                        |
| 208 | -  | 
                                                        |
| 209 | - // test single page flush  | 
                                                        |
| 210 | - Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'single');  | 
                                                        |
| 211 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 212 | - $this->assertEquals(  | 
                                                        |
| 213 | - 'obj.http.content-type ~ "text/html"'  | 
                                                        |
| 214 | - .' && obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$"',  | 
                                                        |
| 215 | - $result[0]['banExpression'],  | 
                                                        |
| 216 | - 'ban expression is correct'  | 
                                                        |
| 217 | - );  | 
                                                        |
| 218 | -  | 
                                                        |
| 219 | - // test parents flush  | 
                                                        |
| 220 | - Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'parents');  | 
                                                        |
| 221 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 222 | - $this->assertEquals(  | 
                                                        |
| 223 | - 'obj.http.content-type ~ "text/html"'  | 
                                                        |
| 224 | - .' && (obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$" || obj.http.x-url ~ "^/about\-us/my\-staff/$" || obj.http.x-url ~ "^/about\-us/$")',  | 
                                                        |
| 225 | - $result[0]['banExpression'],  | 
                                                        |
| 226 | - 'ban expression is correct'  | 
                                                        |
| 227 | - );  | 
                                                        |
| 228 | -  | 
                                                        |
| 229 | - // test all pages flush  | 
                                                        |
| 230 | - Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'all');  | 
                                                        |
| 231 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 232 | - $this->assertEquals(  | 
                                                        |
| 233 | - 'obj.http.content-type ~ "text/html"',  | 
                                                        |
| 234 | - $result[0]['banExpression'],  | 
                                                        |
| 235 | - 'ban expression is correct'  | 
                                                        |
| 236 | - );  | 
                                                        |
| 237 | -  | 
                                                        |
| 238 | - // test whole site flush  | 
                                                        |
| 239 | - Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'everything');  | 
                                                        |
| 240 | - $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 241 | - $this->assertEquals(  | 
                                                        |
| 242 | - 'obj.http.x-url ~ /',  | 
                                                        |
| 243 | - $result[0]['banExpression'],  | 
                                                        |
| 244 | - 'ban expression is correct'  | 
                                                        |
| 245 | - );  | 
                                                        |
| 246 | - }  | 
                                                        |
| 54 | + }  | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | + public static function tearDownAfterClass()  | 
                                                        |
| 57 | +	{ | 
                                                        |
| 58 | + // re-add extensions  | 
                                                        |
| 59 | +		File::add_extension('SectionIOFileExtension'); | 
                                                        |
| 60 | +		SiteTree::add_extension('SectionIOSiteTreeExtension'); | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + public function tearDown()  | 
                                                        |
| 64 | +	{ | 
                                                        |
| 65 | + TestAssetStore::reset();  | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | +  | 
                                                        |
| 68 | + public function testFlushAll()  | 
                                                        |
| 69 | +	{ | 
                                                        |
| 70 | + $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + $this->assertCount(  | 
                                                        |
| 73 | + 1,  | 
                                                        |
| 74 | + $result,  | 
                                                        |
| 75 | + 'one url returned for one application id'  | 
                                                        |
| 76 | + );  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + // url  | 
                                                        |
| 79 | + $this->assertEquals(  | 
                                                        |
| 80 | + 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 81 | + $result[0]['url'],  | 
                                                        |
| 82 | + 'URL is concatenated correctly'  | 
                                                        |
| 83 | + );  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + // ban expression  | 
                                                        |
| 86 | + $this->assertEquals(  | 
                                                        |
| 87 | + 'obj.http.x-url ~ /',  | 
                                                        |
| 88 | + $result[0]['banExpression'],  | 
                                                        |
| 89 | + 'ban expression is correct'  | 
                                                        |
| 90 | + );  | 
                                                        |
| 91 | +  | 
                                                        |
| 92 | + }  | 
                                                        |
| 93 | +  | 
                                                        |
| 94 | + public function testFlush()  | 
                                                        |
| 95 | +	{ | 
                                                        |
| 96 | + $result = SectionIOTest_MySectionIO::flush();  | 
                                                        |
| 97 | +  | 
                                                        |
| 98 | + $this->assertCount(  | 
                                                        |
| 99 | + 1,  | 
                                                        |
| 100 | + $result,  | 
                                                        |
| 101 | + 'one url returned for one application id'  | 
                                                        |
| 102 | + );  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + // url  | 
                                                        |
| 105 | + $this->assertEquals(  | 
                                                        |
| 106 | + 'https://example.com/account/123456/application/987654/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 107 | + $result[0]['url'],  | 
                                                        |
| 108 | + 'URL is concatenated correctly'  | 
                                                        |
| 109 | + );  | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | + // ban expression  | 
                                                        |
| 112 | + $this->assertEquals(  | 
                                                        |
| 113 | + 'obj.http.x-url ~ /',  | 
                                                        |
| 114 | + $result[0]['banExpression'],  | 
                                                        |
| 115 | + 'ban expression is correct'  | 
                                                        |
| 116 | + );  | 
                                                        |
| 117 | +  | 
                                                        |
| 118 | + // test deactivated flush on build  | 
                                                        |
| 119 | + Config::modify()->set(SectionIO::class, 'flush_on_dev_build', false);  | 
                                                        |
| 120 | + $result = SectionIOTest_MySectionIO::flush();  | 
                                                        |
| 121 | + $this->assertNull(  | 
                                                        |
| 122 | + $result,  | 
                                                        |
| 123 | + 'null returned if flush on build deactivated'  | 
                                                        |
| 124 | + );  | 
                                                        |
| 125 | + }  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + public function testMultipleApplicationIDs()  | 
                                                        |
| 128 | +	{ | 
                                                        |
| 129 | + // add second application to config  | 
                                                        |
| 130 | + Config::modify()->set(SectionIO::class, 'application_id', '2546987,856954');  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | + $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 133 | +  | 
                                                        |
| 134 | + $this->assertCount(  | 
                                                        |
| 135 | + 2,  | 
                                                        |
| 136 | + $result,  | 
                                                        |
| 137 | + 'two urls returned for two application id'  | 
                                                        |
| 138 | + );  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | + // url  | 
                                                        |
| 141 | + $this->assertEquals(  | 
                                                        |
| 142 | + 'https://example.com/account/123456/application/2546987/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 143 | + $result[0]['url'],  | 
                                                        |
| 144 | + 'URL is concatenated correctly for app 1'  | 
                                                        |
| 145 | + );  | 
                                                        |
| 146 | + $this->assertEquals(  | 
                                                        |
| 147 | + 'https://example.com/account/123456/application/856954/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 148 | + $result[1]['url'],  | 
                                                        |
| 149 | + 'URL is concatenated correctly for app 2'  | 
                                                        |
| 150 | + );  | 
                                                        |
| 151 | +  | 
                                                        |
| 152 | + // add second application to config with spaces in csv  | 
                                                        |
| 153 | + Config::modify()->set(SectionIO::class, 'application_id', '741852, 369258');  | 
                                                        |
| 154 | +  | 
                                                        |
| 155 | + $result = SectionIOTest_MySectionIO::flushAll();  | 
                                                        |
| 156 | +  | 
                                                        |
| 157 | + $this->assertCount(  | 
                                                        |
| 158 | + 2,  | 
                                                        |
| 159 | + $result,  | 
                                                        |
| 160 | + 'two urls returned for two application id'  | 
                                                        |
| 161 | + );  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | + // url  | 
                                                        |
| 164 | + $this->assertEquals(  | 
                                                        |
| 165 | + 'https://example.com/account/123456/application/741852/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 166 | + $result[0]['url'],  | 
                                                        |
| 167 | + 'URL is concatenated correctly for app 1'  | 
                                                        |
| 168 | + );  | 
                                                        |
| 169 | + $this->assertEquals(  | 
                                                        |
| 170 | + 'https://example.com/account/123456/application/369258/environment/Production/proxy/myproxy/state',  | 
                                                        |
| 171 | + $result[1]['url'],  | 
                                                        |
| 172 | + 'URL is concatenated correctly for app 2'  | 
                                                        |
| 173 | + );  | 
                                                        |
| 174 | + }  | 
                                                        |
| 175 | +  | 
                                                        |
| 176 | + public function testFlushImage()  | 
                                                        |
| 177 | +	{ | 
                                                        |
| 178 | +		$imageId = $this->idFromFixture('Image', 'testImage'); | 
                                                        |
| 179 | +  | 
                                                        |
| 180 | + $result = SectionIOTest_MySectionIO::flushImage($imageId);  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + // ban expression  | 
                                                        |
| 183 | + $this->assertEquals(  | 
                                                        |
| 184 | + 'obj.http.x-url ~ "^/assets/SectionTest/test_image\.png$"'  | 
                                                        |
| 185 | + .' || obj.http.x-url ~ "^/assets/SectionTest/test_image__[a-zA-Z0-9_]*\.png$"',  | 
                                                        |
| 186 | + $result[0]['banExpression'],  | 
                                                        |
| 187 | + 'ban expression is correct'  | 
                                                        |
| 188 | + );  | 
                                                        |
| 189 | + }  | 
                                                        |
| 190 | +  | 
                                                        |
| 191 | + public function testFlushFile()  | 
                                                        |
| 192 | +	{ | 
                                                        |
| 193 | +		$fileId = $this->idFromFixture('File', 'testFile'); | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | + $result = SectionIOTest_MySectionIO::flushFile($fileId);  | 
                                                        |
| 196 | +  | 
                                                        |
| 197 | + // ban expression  | 
                                                        |
| 198 | + $this->assertEquals(  | 
                                                        |
| 199 | + 'obj.http.x-url ~ "^/assets/SectionTest/test_document\.pdf$"',  | 
                                                        |
| 200 | + $result[0]['banExpression'],  | 
                                                        |
| 201 | + 'ban expression is correct'  | 
                                                        |
| 202 | + );  | 
                                                        |
| 203 | + }  | 
                                                        |
| 204 | +  | 
                                                        |
| 205 | + public function testFlushSiteTree()  | 
                                                        |
| 206 | +	{ | 
                                                        |
| 207 | +		$pageId = $this->idFromFixture('Page', 'ceo'); | 
                                                        |
| 208 | +  | 
                                                        |
| 209 | + // test single page flush  | 
                                                        |
| 210 | + Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'single');  | 
                                                        |
| 211 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 212 | + $this->assertEquals(  | 
                                                        |
| 213 | + 'obj.http.content-type ~ "text/html"'  | 
                                                        |
| 214 | + .' && obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$"',  | 
                                                        |
| 215 | + $result[0]['banExpression'],  | 
                                                        |
| 216 | + 'ban expression is correct'  | 
                                                        |
| 217 | + );  | 
                                                        |
| 218 | +  | 
                                                        |
| 219 | + // test parents flush  | 
                                                        |
| 220 | + Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'parents');  | 
                                                        |
| 221 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 222 | + $this->assertEquals(  | 
                                                        |
| 223 | + 'obj.http.content-type ~ "text/html"'  | 
                                                        |
| 224 | + .' && (obj.http.x-url ~ "^/about\-us/my\-staff/ceo/$" || obj.http.x-url ~ "^/about\-us/my\-staff/$" || obj.http.x-url ~ "^/about\-us/$")',  | 
                                                        |
| 225 | + $result[0]['banExpression'],  | 
                                                        |
| 226 | + 'ban expression is correct'  | 
                                                        |
| 227 | + );  | 
                                                        |
| 228 | +  | 
                                                        |
| 229 | + // test all pages flush  | 
                                                        |
| 230 | + Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'all');  | 
                                                        |
| 231 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 232 | + $this->assertEquals(  | 
                                                        |
| 233 | + 'obj.http.content-type ~ "text/html"',  | 
                                                        |
| 234 | + $result[0]['banExpression'],  | 
                                                        |
| 235 | + 'ban expression is correct'  | 
                                                        |
| 236 | + );  | 
                                                        |
| 237 | +  | 
                                                        |
| 238 | + // test whole site flush  | 
                                                        |
| 239 | + Config::modify()->set(SectionIO::class, 'sitetree_flush_strategy', 'everything');  | 
                                                        |
| 240 | + $result = SectionIOTest_MySectionIO::flushSiteTree($pageId);  | 
                                                        |
| 241 | + $this->assertEquals(  | 
                                                        |
| 242 | + 'obj.http.x-url ~ /',  | 
                                                        |
| 243 | + $result[0]['banExpression'],  | 
                                                        |
| 244 | + 'ban expression is correct'  | 
                                                        |
| 245 | + );  | 
                                                        |
| 246 | + }  | 
                                                        |
| 247 | 247 | }  | 
                                                        
| 248 | 248 | |
| 249 | 249 | class SectionIOTest_MySectionIO extends SectionIO  | 
                                                        
| 250 | 250 |  { | 
                                                        
| 251 | - protected static function performFlush($banExpression)  | 
                                                        |
| 252 | -    { | 
                                                        |
| 253 | - $result = array();  | 
                                                        |
| 254 | - $urls = static::getUrls();  | 
                                                        |
| 255 | -        if (count($urls) > 0) { | 
                                                        |
| 256 | -            foreach ($urls as $url) { | 
                                                        |
| 251 | + protected static function performFlush($banExpression)  | 
                                                        |
| 252 | +	{ | 
                                                        |
| 253 | + $result = array();  | 
                                                        |
| 254 | + $urls = static::getUrls();  | 
                                                        |
| 255 | +		if (count($urls) > 0) { | 
                                                        |
| 256 | +			foreach ($urls as $url) { | 
                                                        |
| 257 | 257 | |
| 258 | - $data = array();  | 
                                                        |
| 259 | - $data['url'] = $url;  | 
                                                        |
| 260 | - $data['banExpression'] = $banExpression;  | 
                                                        |
| 261 | - $result[] = $data;  | 
                                                        |
| 258 | + $data = array();  | 
                                                        |
| 259 | + $data['url'] = $url;  | 
                                                        |
| 260 | + $data['banExpression'] = $banExpression;  | 
                                                        |
| 261 | + $result[] = $data;  | 
                                                        |
| 262 | 262 | |
| 263 | - }  | 
                                                        |
| 264 | - }  | 
                                                        |
| 265 | - return $result;  | 
                                                        |
| 266 | - }  | 
                                                        |
| 263 | + }  | 
                                                        |
| 264 | + }  | 
                                                        |
| 265 | + return $result;  | 
                                                        |
| 266 | + }  | 
                                                        |
| 267 | 267 | }  |