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