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