Completed
Push — master ( c84c43...54ac69 )
by Robbie
16s
created
tests/DocumentConverterDecoratorTest.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -2,18 +2,18 @@
 block discarded – undo
2 2
 
3 3
 class DocumentConverterDecoratorTest extends SapphireTest
4 4
 {
5
-    protected $requiredExtensions = array(
6
-        'SiteTree' => array(
7
-            'DocumentConverterDecorator',
8
-        ),
9
-    );
5
+	protected $requiredExtensions = array(
6
+		'SiteTree' => array(
7
+			'DocumentConverterDecorator',
8
+		),
9
+	);
10 10
 
11
-    public function testFieldListHasDocumentImportField()
12
-    {
13
-        $fields = (new SiteTree)->getCMSFields();
14
-        $this->assertInstanceOf(
15
-            'DocumentImportField',
16
-            $fields->fieldByName('Root.Import')->Fields()->First()
17
-        );
18
-    }
11
+	public function testFieldListHasDocumentImportField()
12
+	{
13
+		$fields = (new SiteTree)->getCMSFields();
14
+		$this->assertInstanceOf(
15
+			'DocumentImportField',
16
+			$fields->fieldByName('Root.Import')->Fields()->First()
17
+		);
18
+	}
19 19
 }
Please login to merge, or discard this patch.
tests/DocumentImportFieldTest.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -2,50 +2,50 @@
 block discarded – undo
2 2
 
3 3
 class DocumentImportFieldTest extends SapphireTest
4 4
 {
5
-    /**
6
-     * @expectedException InvalidArgumentException
7
-     */
8
-    public function testConstructorThrowsExceptionWhenGivenString()
9
-    {
10
-        new DocumentImportField('exception time!');
11
-    }
12
-
13
-    /**
14
-     * @expectedException InvalidArgumentException
15
-     */
16
-    public function testConstructorThrowsExceptionWhenGivenChildren()
17
-    {
18
-        new DocumentImportField(['i', 'don\'t', 'like', 'kids']);
19
-    }
20
-
21
-    public function testFieldAddsJavascriptRequirements()
22
-    {
23
-        // Start with a clean slate (no global state interference)
24
-        Requirements::backend()->clear();
25
-
26
-        new DocumentImportField();
27
-        $javascript = Requirements::backend()->get_javascript();
28
-        $this->assertNotEmpty($javascript);
29
-    }
30
-
31
-    public function testFieldListGeneration()
32
-    {
33
-        $importField = new DocumentImportField();
34
-
35
-        $fields = $importField->getChildren();
36
-        $this->assertInstanceOf('FieldList', $fields);
37
-
38
-        // We don't need to check that all of the fields are there, but just check a couple
39
-        $this->assertInstanceOf('HeaderField', $fields->fieldByName('FileWarningHeader'));
40
-        $innerField = $fields->fieldByName('ImportedFromFile');
41
-        $this->assertInstanceOf('DocumentImportInnerField', $innerField);
42
-
43
-        // Check the getter works
44
-        $this->assertSame($innerField, $importField->getInnerField());
45
-
46
-        // Check the fields have been given has the change tracker disabled
47
-        $splitHeader = $fields->fieldByName('DocumentImportField-SplitHeader');
48
-        $this->assertInstanceOf('DropdownField', $splitHeader);
49
-        $this->assertContains('no-change-track', $splitHeader->extraClass());
50
-    }
5
+	/**
6
+	 * @expectedException InvalidArgumentException
7
+	 */
8
+	public function testConstructorThrowsExceptionWhenGivenString()
9
+	{
10
+		new DocumentImportField('exception time!');
11
+	}
12
+
13
+	/**
14
+	 * @expectedException InvalidArgumentException
15
+	 */
16
+	public function testConstructorThrowsExceptionWhenGivenChildren()
17
+	{
18
+		new DocumentImportField(['i', 'don\'t', 'like', 'kids']);
19
+	}
20
+
21
+	public function testFieldAddsJavascriptRequirements()
22
+	{
23
+		// Start with a clean slate (no global state interference)
24
+		Requirements::backend()->clear();
25
+
26
+		new DocumentImportField();
27
+		$javascript = Requirements::backend()->get_javascript();
28
+		$this->assertNotEmpty($javascript);
29
+	}
30
+
31
+	public function testFieldListGeneration()
32
+	{
33
+		$importField = new DocumentImportField();
34
+
35
+		$fields = $importField->getChildren();
36
+		$this->assertInstanceOf('FieldList', $fields);
37
+
38
+		// We don't need to check that all of the fields are there, but just check a couple
39
+		$this->assertInstanceOf('HeaderField', $fields->fieldByName('FileWarningHeader'));
40
+		$innerField = $fields->fieldByName('ImportedFromFile');
41
+		$this->assertInstanceOf('DocumentImportInnerField', $innerField);
42
+
43
+		// Check the getter works
44
+		$this->assertSame($innerField, $importField->getInnerField());
45
+
46
+		// Check the fields have been given has the change tracker disabled
47
+		$splitHeader = $fields->fieldByName('DocumentImportField-SplitHeader');
48
+		$this->assertInstanceOf('DropdownField', $splitHeader);
49
+		$this->assertContains('no-change-track', $splitHeader->extraClass());
50
+	}
51 51
 }
Please login to merge, or discard this patch.
src/DocumentImporterField.php 1 patch
Braces   +35 added lines, -12 removed lines patch added patch discarded remove patch
@@ -60,11 +60,15 @@  discard block
 block discarded – undo
60 60
 	 * Process the document immediately upon upload.
61 61
 	 */
62 62
 	public function upload(HTTPRequest $request) {
63
-		if($this->isDisabled() || $this->isReadonly()) return $this->httpError(403);
63
+		if($this->isDisabled() || $this->isReadonly()) {
64
+			return $this->httpError(403);
65
+		}
64 66
 
65 67
 		// Protect against CSRF on destructive action
66 68
 		$token = $this->getForm()->getSecurityToken();
67
-		if(!$token->checkRequest($request)) return $this->httpError(400);
69
+		if(!$token->checkRequest($request)) {
70
+			return $this->httpError(400);
71
+		}
68 72
 
69 73
 		$name = $this->getName();
70 74
 		$tmpfile = $request->postVar($name);
@@ -91,7 +95,9 @@  discard block
 block discarded – undo
91 95
 
92 96
 			// Process the document and write the page.
93 97
 			$preservedDocument = null;
94
-			if ($keepSource) $preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
98
+			if ($keepSource) {
99
+				$preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID);
100
+			}
95 101
 
96 102
 			$importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID);
97 103
 			if (is_array($importResult) && isset($importResult['error'])) {
@@ -142,7 +148,7 @@  discard block
 block discarded – undo
142 148
 					$content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>';
143 149
 				}
144 150
 				$page->Content = $content . '</ul>';
145
-			}  else {
151
+			} else {
146 152
 				$doc = new DOMDocument();
147 153
 				$doc->loadHTML($page->Content);
148 154
 				$body = $doc->getElementsByTagName('body')->item(0);
@@ -171,7 +177,9 @@  discard block
 block discarded – undo
171 177
 
172 178
 			// Store the result
173 179
 			$page->write();
174
-			if($publishPages) $page->doPublish();
180
+			if($publishPages) {
181
+				$page->doPublish();
182
+			}
175 183
 		}
176 184
 	}
177 185
 
@@ -217,16 +225,22 @@  discard block
 block discarded – undo
217 225
 			unset($this->unusedChildren[$page->ID]);
218 226
 			file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode));
219 227
 
220
-			if ($sort) $page->Sort = $sort;
228
+			if ($sort) {
229
+				$page->Sort = $sort;
230
+			}
221 231
 			$page->Content = $this->getBodyText($subdoc, $subnode);
222 232
 			$page->write();
223
-			if($publishPages) $page->doPublish();
233
+			if($publishPages) {
234
+				$page->doPublish();
235
+			}
224 236
 		} else {
225 237
 			// Write to the master page.
226 238
 			$record->Content = $this->getBodyText($subdoc, $subnode);
227 239
 			$record->write();
228 240
 
229
-			if($publishPages) $record->doPublish();
241
+			if($publishPages) {
242
+				$record->doPublish();
243
+			}
230 244
 		}
231 245
 
232 246
 	}
@@ -313,7 +327,9 @@  discard block
 block discarded – undo
313 327
 			}
314 328
 
315 329
 			$nodes = array();
316
-			foreach($xpath->query($rule) as $node) $nodes[] = $node;
330
+			foreach($xpath->query($rule) as $node) {
331
+				$nodes[] = $node;
332
+			}
317 333
 
318 334
 			foreach($nodes as $node) {
319 335
 				$parent = $node->parentNode;
@@ -323,7 +339,9 @@  discard block
 block discarded – undo
323 339
 					$node->nextSibling ? $node->parentNode->insertBefore($parent, $node->nextSibling) : $node->parentNode->appendChild($parent);
324 340
 				}
325 341
 
326
-				while($node->firstChild) $parent->appendChild($node->firstChild);
342
+				while($node->firstChild) {
343
+					$parent->appendChild($node->firstChild);
344
+				}
327 345
 				$node->parentNode->removeChild($node);
328 346
 			}
329 347
 		}
@@ -351,10 +369,15 @@  discard block
 block discarded – undo
351 369
 			// First get all the nodes. Need to build array, as they'll disappear from the nodelist while we're deleteing them, causing the indexing
352 370
 			// to screw up.
353 371
 			$nodes = array();
354
-			foreach($xpath->query($query) as $node) $nodes[] = $node;
372
+			foreach($xpath->query($query) as $node) {
373
+				$nodes[] = $node;
374
+			}
355 375
 
356 376
 			// Then remove them all
357
-			foreach ($nodes as $node) { if ($node->parentNode) $node->parentNode->removeChild($node); }
377
+			foreach ($nodes as $node) { if ($node->parentNode) {
378
+				$node->parentNode->removeChild($node);
379
+			}
380
+			}
358 381
 		}
359 382
 
360 383
 		// Now split the document into portions by H1
Please login to merge, or discard this patch.
src/DocumentConversionField.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,12 @@
 block discarded – undo
29 29
 	 * @param $children FieldSet/array Any additional children.
30 30
 	 */
31 31
 	public function __construct($children = null) {
32
-		if (is_string($children)) throw new InvalidArgumentException('DocumentConversionField::__construct does not accept a name as its parameter, it defaults to "ImportedFromFile" instead. Use DocumentConversionField::getInnerField()->setName() if you want to change it.');
33
-		if ($children) throw new InvalidArgumentException('DocumentConversionField::__construct provides its own fields and does not accept additional children.');
32
+		if (is_string($children)) {
33
+			throw new InvalidArgumentException('DocumentConversionField::__construct does not accept a name as its parameter, it defaults to "ImportedFromFile" instead. Use DocumentConversionField::getInnerField()->setName() if you want to change it.');
34
+		}
35
+		if ($children) {
36
+			throw new InvalidArgumentException('DocumentConversionField::__construct provides its own fields and does not accept additional children.');
37
+		}
34 38
 
35 39
 		// Add JS specific to this field.
36 40
 		Requirements::javascript('silverstripe/documentconverter: javascript/DocumentConversionField.js');
Please login to merge, or discard this patch.
tests/DocumentConverterTest.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@
 block discarded – undo
9 9
 
10 10
 class DocumentConverterTest extends SapphireTest
11 11
 {
12
-    protected $usesDatabase = true;
12
+	protected $usesDatabase = true;
13 13
 
14
-    public function testExtensionAppliesAppropriateFields() {
15
-        $this->markTestIncomplete();
16
-    }
14
+	public function testExtensionAppliesAppropriateFields() {
15
+		$this->markTestIncomplete();
16
+	}
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.