Passed
Push — master ( c02e56...6d2ae7 )
by Matthew
02:43
created
src/Extensions/ManageableDataObjectExtension.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
         }
53 53
 
54 54
         return Security::permissionFailure(
55
-        	$this->owner,
56
-			"You don't have permission to add records."
57
-		);
55
+            $this->owner,
56
+            "You don't have permission to add records."
57
+        );
58 58
     }
59 59
 
60 60
     /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
             }
79 79
 
80 80
             return Security::permissionFailure(
81
-            	$this->owner,
82
-				"You don't have permission to edit this record."
83
-			);
81
+                $this->owner,
82
+                "You don't have permission to edit this record."
83
+            );
84 84
         }
85 85
 
86 86
         return $this->owner->httpError(404);
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
             }
106 106
 
107 107
             return Security::permissionFailure(
108
-            	$this->owner,
109
-				"You don't have permission to delete this record."
110
-			);
108
+                $this->owner,
109
+                "You don't have permission to delete this record."
110
+            );
111 111
         }
112 112
 
113 113
         return $this->owner->httpError(404);
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
         return $form;
145 145
     }
146 146
 
147
-	/**
148
-	 * Save object
149
-	 *
150
-	 * @param $data
151
-	 * @param Form $form
152
-	 *
153
-	 * @return \SilverStripe\Control\HTTPResponse
154
-	 * @throws \SilverStripe\ORM\ValidationException
155
-	 */
147
+    /**
148
+     * Save object
149
+     *
150
+     * @param $data
151
+     * @param Form $form
152
+     *
153
+     * @return \SilverStripe\Control\HTTPResponse
154
+     * @throws \SilverStripe\ORM\ValidationException
155
+     */
156 156
     public function doSaveObject($data, Form $form)
157 157
     {
158
-		/** @var \SilverStripe\ORM\DataObject $model */
158
+        /** @var \SilverStripe\ORM\DataObject $model */
159 159
         $model = $this->owner->config()->get('managed_object');
160 160
 
161 161
         /** @var \SilverStripe\ORM\DataObject|\Dynamic\ViewableDataObject\Extensions\ViewableDataObject $object */
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             $object = $model::create();
169 169
             if ($object->hasDatabaseField('URLSegment')) {
170 170
                 $object->URLSegment = Injector::inst()->create(SiteTree::class)
171
-					->generateURLSegment($data['Title']);
171
+                    ->generateURLSegment($data['Title']);
172 172
             }
173 173
             // write on create to relations are saved on final write (needs ID)
174 174
             $object->write();
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
         if ($object->canCreate(Security::getCurrentUser())) {
40 40
 
41 41
             $form = $this->ManageableDataObjectForm();
42
-            if($object->config()->get('add_form_cancel_button')){
42
+            if ($object->config()->get('add_form_cancel_button')) {
43 43
                 $form->Actions()->push(new CancelFormAction($this->owner->Link(), 'Cancel'));
44 44
             }
45 45
 
46 46
             return $this->owner->customise([
47 47
                 'Title' => ($this->owner->config()->get('add_item_title'))
48 48
                     ? $this->owner->config()->get('add_item_title')
49
-                    : 'Add new ' . $object->singular_name(),
49
+                    : 'Add new '.$object->singular_name(),
50 50
                 'ManageableDataObjectForm' => $form,
51 51
             ]);
52 52
         }
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
                 $form = $this->ManageableDataObjectForm($item);
72 72
 
73 73
                 return $this->owner->customise([
74
-                    'Title' => 'Edit ' . $item->singular_name(),
74
+                    'Title' => 'Edit '.$item->singular_name(),
75 75
                     'ManageableDataObjectForm' => $form,
76 76
                     'Item' => $item,
77 77
                 ]);
Please login to merge, or discard this patch.
src/Form/ManageableDataObjectForm.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
             $object = Injector::inst()->get($object);
27 27
         }
28 28
 
29
-		/** @var \SilverStripe\ORM\DataObject|\Dynamic\ManageableDataObject\Interfaces\ManageableDataObjectInterface $object */
29
+        /** @var \SilverStripe\ORM\DataObject|\Dynamic\ManageableDataObject\Interfaces\ManageableDataObjectInterface $object */
30 30
         $fields = $object->getFrontEndFields();
31 31
         $actions = $object->getFrontEndActions();
32 32
         if (!$actions->dataFieldByName('action_doSaveObject')) {
Please login to merge, or discard this patch.
tests/Model/SampleManageableObjectPageController.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -16,36 +16,36 @@
 block discarded – undo
16 16
 class SampleManageableObjectPageController extends \PageController implements TestOnly
17 17
 {
18 18
 
19
-	/**
20
-	 * @var array
21
-	 */
22
-	private static $allowed_actions = [
23
-		'Form',
24
-	];
25
-
26
-	/**
27
-	 * @var array
28
-	 */
29
-	private static $extensions = [
30
-		ManageableDataObjectExtension::class
31
-	];
32
-
33
-	/**
34
-	 * @var string
35
-	 */
36
-	private static $managed_object = SampleManageableDataObject::class;
37
-
38
-	/**
39
-	 *
40
-	 */
41
-	public function init()
42
-	{
43
-		parent::init();
44
-		Requirements::clear();
45
-	}
46
-
47
-	public function Form()
48
-	{
49
-		return ManageableDataObjectForm::create($this, 'Form', $this->config()->get('managed_object'));
50
-	}
19
+    /**
20
+     * @var array
21
+     */
22
+    private static $allowed_actions = [
23
+        'Form',
24
+    ];
25
+
26
+    /**
27
+     * @var array
28
+     */
29
+    private static $extensions = [
30
+        ManageableDataObjectExtension::class
31
+    ];
32
+
33
+    /**
34
+     * @var string
35
+     */
36
+    private static $managed_object = SampleManageableDataObject::class;
37
+
38
+    /**
39
+     *
40
+     */
41
+    public function init()
42
+    {
43
+        parent::init();
44
+        Requirements::clear();
45
+    }
46
+
47
+    public function Form()
48
+    {
49
+        return ManageableDataObjectForm::create($this, 'Form', $this->config()->get('managed_object'));
50
+    }
51 51
 }
Please login to merge, or discard this patch.
tests/Model/SampleManageableDataObject.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 class SampleManageableDataObject extends DataObject implements PermissionProvider, ManageableDataObjectInterface, TestOnly
23 23
 {
24 24
 
25
-	/**
26
-	 * @var string
27
-	 */
28
-	private static $table_name = 'SampleManageableDataObject';
25
+    /**
26
+     * @var string
27
+     */
28
+    private static $table_name = 'SampleManageableDataObject';
29 29
 
30 30
     /**
31 31
      * @var string
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
         ];
54 54
     }
55 55
 
56
-	/**
57
-	 * @param null $member
58
-	 * @param array $context
59
-	 *
60
-	 * @return bool|int
61
-	 */
56
+    /**
57
+     * @param null $member
58
+     * @param array $context
59
+     *
60
+     * @return bool|int
61
+     */
62 62
     public function canCreate($member = null, $context = array())
63 63
     {
64 64
         return Permission::check('MDO_Create', 'any', $member);
Please login to merge, or discard this patch.
tests/Model/SampleManageableObjectPage.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
  */
11 11
 class SampleManageableObjectPage extends \Page implements TestOnly
12 12
 {
13
-	/**
14
-	 * @var string
15
-	 */
16
-	private static $table_name = 'SampleManageableObjectPage';
13
+    /**
14
+     * @var string
15
+     */
16
+    private static $table_name = 'SampleManageableObjectPage';
17 17
 }
Please login to merge, or discard this patch.
tests/Extensions/ManageableObjectDataExtensionTest.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
     /**
24 24
      * @var array
25 25
      */
26
-	protected static $extra_dataobjects = [
26
+    protected static $extra_dataobjects = [
27 27
         SampleManageableDataObject::class,
28 28
         SampleManageableObjectPage::class,
29 29
     ];
30 30
 
31
-	/**
32
-	 * Ensure any current member is logged out
33
-	 */
34
-	public function logOut()
35
-	{
36
-		if ($member = Security::getCurrentUser()) {
37
-			Security::setCurrentUser(null);
38
-		}
39
-	}
31
+    /**
32
+     * Ensure any current member is logged out
33
+     */
34
+    public function logOut()
35
+    {
36
+        if ($member = Security::getCurrentUser()) {
37
+            Security::setCurrentUser(null);
38
+        }
39
+    }
40 40
 
41 41
     /**
42 42
      *
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function testGetAddLink()
54 54
     {
55
-		/** @var SampleManageableObjectPage $page */
56
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
57
-		/** @var SampleManageableDataObject $object */
58
-		$object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
55
+        /** @var SampleManageableObjectPage $page */
56
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
57
+        /** @var SampleManageableDataObject $object */
58
+        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
59 59
 
60 60
         $this->logOut();
61 61
         $this->assertFalse($object->getAddLink());
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function testGetEditLink()
74 74
     {
75
-		/** @var SampleManageableObjectPage $page */
76
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
77
-		/** @var SampleManageableDataObject $object */
78
-		$object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
75
+        /** @var SampleManageableObjectPage $page */
76
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
77
+        /** @var SampleManageableDataObject $object */
78
+        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
79 79
 
80 80
         $this->logOut();
81 81
         $this->assertFalse($object->getEditLink());
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public function testGetDeleteLink()
94 94
     {
95
-    	/** @var SampleManageableObjectPage $page */
95
+        /** @var SampleManageableObjectPage $page */
96 96
         $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
97
-		/** @var SampleManageableDataObject $object */
97
+        /** @var SampleManageableDataObject $object */
98 98
         $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
99 99
 
100 100
         $this->logOut();
Please login to merge, or discard this patch.
tests/Extensions/ManageableDataObjectExtensionTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 		$this->assertEquals(200, $response->getStatusCode());
83 83
 		$this->logOut();
84 84
 
85
-		$response2 = $this->get('/SampleManageableObjectPageController/edit/' . 0);
85
+		$response2 = $this->get('/SampleManageableObjectPageController/edit/'.0);
86 86
 		$this->assertEquals(404, $response2->getStatusCode());
87 87
 	}
88 88
 
Please login to merge, or discard this patch.
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -16,139 +16,139 @@
 block discarded – undo
16 16
 class ManageableDataObjectExtensionTest extends FunctionalTest
17 17
 {
18 18
 
19
-	/**
20
-	 * @var string
21
-	 */
22
-	protected static $fixture_file = '../fixtures.yml';
23
-
24
-	/**
25
-	 * @var array
26
-	 */
27
-	protected static $extra_dataobjects = [
28
-		SampleManageableDataObject::class,
29
-		SampleManageableObjectPage::class,
30
-	];
31
-
32
-	/**
33
-	 *
34
-	 */
35
-	public function setUp()
36
-	{
37
-		parent::setUp();
38
-		// Suppress themes
39
-		SSViewer::config()->update('theme_enabled', false);
40
-		$this->session()->set('readingMode', 'Stage.Stage');
41
-		$this->session()->set('unsecuredDraftSite', true);
42
-	}
43
-
44
-	/**
45
-	 * Ensure any current member is logged out
46
-	 */
47
-	public function logOut()
48
-	{
49
-		if ($member = Security::getCurrentUser()) {
50
-			Security::setCurrentUser(null);
51
-		}
52
-	}
53
-
54
-	/**
55
-	 *
56
-	 */
57
-	public function testAdd()
58
-	{
59
-		/** @var SampleManageableObjectPage $page */
60
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
61
-
62
-		$this->logInWithPermission('MDO_Create');
63
-		$response = $this->get($page->Link('add'));
64
-		$this->assertEquals(200, $response->getStatusCode());
65
-		$this->logOut();
66
-	}
67
-
68
-	/**
69
-	 *
70
-	 */
71
-	public function testEdit()
72
-	{
73
-		/** @var SampleManageableDataObject $object */
74
-		$object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
75
-		/** @var SampleManageableObjectPage $page */
76
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
77
-
78
-		$this->logInWithPermission('MDO_Edit');
79
-		$response = $this->get(Controller::join_links(
80
-			$page->Link(),
81
-			'edit',
82
-			$object->ID
83
-		));
84
-		$this->assertEquals(200, $response->getStatusCode());
85
-		$this->logOut();
86
-
87
-		$response2 = $this->get('/SampleManageableObjectPageController/edit/' . 0);
88
-		$this->assertEquals(404, $response2->getStatusCode());
89
-	}
90
-
91
-	/**
92
-	 *
93
-	 */
94
-	public function testDelete()
95
-	{
96
-		/** @var SampleManageableObjectPage $page */
97
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
98
-
99
-		$newObject = SampleManageableDataObject::create();
100
-		$newObject->Title = 'Foo';
101
-		$newObject->write();
102
-
103
-		$id = $newObject->ID;
104
-
105
-		$this->logInWithPermission('MDO_Delete');
106
-
107
-		$response404 = $this->get(Controller::join_links(
108
-			$page->Link(),
109
-			'delete',
110
-			0
111
-		));
112
-		$this->assertEquals(404, $response404->getStatusCode());
113
-
114
-		$success = $this->get(Controller::join_links(
115
-			$page->Link(),
116
-			'delete',
117
-			$id
118
-		));
119
-		$this->assertEquals(200, $success->getStatusCode());
120
-		$this->assertNull(SampleManageableDataObject::get()->byID($id));
121
-
122
-		$this->logOut();
123
-	}
124
-
125
-	/**
126
-	 *
127
-	 */
128
-	public function testDoSaveObject()
129
-	{
130
-		/** @var SampleManageableObjectPage $page */
131
-		$page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
132
-
133
-		$this->logInWithPermission('MDO_Create');
134
-
135
-		$controller = SampleManageableObjectPageController::create(
136
-			$this->objFromFixture(SampleManageableObjectPage::class, 'one')
137
-		);
138
-		$form = $controller->Form();
139
-
140
-		$response = $this->get($page->Link('add'));
141
-		$this->assertEquals(200, $response->getStatusCode(), 'Submission successful');
142
-
143
-		$data = ['Title' => 'Foobar'];
144
-		$responseSubmission = $this->submitForm(
145
-			'ManageableDataObjectForm_Form',
146
-			'action_doSaveObject',
147
-			$data
148
-		);
149
-
150
-		$record = SampleManageableDataObject::get()->filter($data)->first();
151
-		$this->assertInstanceOf(SampleManageableDataObject::class, $record);
152
-		$this->assertTrue($record->exists());
153
-	}
19
+    /**
20
+     * @var string
21
+     */
22
+    protected static $fixture_file = '../fixtures.yml';
23
+
24
+    /**
25
+     * @var array
26
+     */
27
+    protected static $extra_dataobjects = [
28
+        SampleManageableDataObject::class,
29
+        SampleManageableObjectPage::class,
30
+    ];
31
+
32
+    /**
33
+     *
34
+     */
35
+    public function setUp()
36
+    {
37
+        parent::setUp();
38
+        // Suppress themes
39
+        SSViewer::config()->update('theme_enabled', false);
40
+        $this->session()->set('readingMode', 'Stage.Stage');
41
+        $this->session()->set('unsecuredDraftSite', true);
42
+    }
43
+
44
+    /**
45
+     * Ensure any current member is logged out
46
+     */
47
+    public function logOut()
48
+    {
49
+        if ($member = Security::getCurrentUser()) {
50
+            Security::setCurrentUser(null);
51
+        }
52
+    }
53
+
54
+    /**
55
+     *
56
+     */
57
+    public function testAdd()
58
+    {
59
+        /** @var SampleManageableObjectPage $page */
60
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
61
+
62
+        $this->logInWithPermission('MDO_Create');
63
+        $response = $this->get($page->Link('add'));
64
+        $this->assertEquals(200, $response->getStatusCode());
65
+        $this->logOut();
66
+    }
67
+
68
+    /**
69
+     *
70
+     */
71
+    public function testEdit()
72
+    {
73
+        /** @var SampleManageableDataObject $object */
74
+        $object = $this->objFromFixture(SampleManageableDataObject::class, 'one');
75
+        /** @var SampleManageableObjectPage $page */
76
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
77
+
78
+        $this->logInWithPermission('MDO_Edit');
79
+        $response = $this->get(Controller::join_links(
80
+            $page->Link(),
81
+            'edit',
82
+            $object->ID
83
+        ));
84
+        $this->assertEquals(200, $response->getStatusCode());
85
+        $this->logOut();
86
+
87
+        $response2 = $this->get('/SampleManageableObjectPageController/edit/' . 0);
88
+        $this->assertEquals(404, $response2->getStatusCode());
89
+    }
90
+
91
+    /**
92
+     *
93
+     */
94
+    public function testDelete()
95
+    {
96
+        /** @var SampleManageableObjectPage $page */
97
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
98
+
99
+        $newObject = SampleManageableDataObject::create();
100
+        $newObject->Title = 'Foo';
101
+        $newObject->write();
102
+
103
+        $id = $newObject->ID;
104
+
105
+        $this->logInWithPermission('MDO_Delete');
106
+
107
+        $response404 = $this->get(Controller::join_links(
108
+            $page->Link(),
109
+            'delete',
110
+            0
111
+        ));
112
+        $this->assertEquals(404, $response404->getStatusCode());
113
+
114
+        $success = $this->get(Controller::join_links(
115
+            $page->Link(),
116
+            'delete',
117
+            $id
118
+        ));
119
+        $this->assertEquals(200, $success->getStatusCode());
120
+        $this->assertNull(SampleManageableDataObject::get()->byID($id));
121
+
122
+        $this->logOut();
123
+    }
124
+
125
+    /**
126
+     *
127
+     */
128
+    public function testDoSaveObject()
129
+    {
130
+        /** @var SampleManageableObjectPage $page */
131
+        $page = $this->objFromFixture(SampleManageableObjectPage::class, 'one');
132
+
133
+        $this->logInWithPermission('MDO_Create');
134
+
135
+        $controller = SampleManageableObjectPageController::create(
136
+            $this->objFromFixture(SampleManageableObjectPage::class, 'one')
137
+        );
138
+        $form = $controller->Form();
139
+
140
+        $response = $this->get($page->Link('add'));
141
+        $this->assertEquals(200, $response->getStatusCode(), 'Submission successful');
142
+
143
+        $data = ['Title' => 'Foobar'];
144
+        $responseSubmission = $this->submitForm(
145
+            'ManageableDataObjectForm_Form',
146
+            'action_doSaveObject',
147
+            $data
148
+        );
149
+
150
+        $record = SampleManageableDataObject::get()->filter($data)->first();
151
+        $this->assertInstanceOf(SampleManageableDataObject::class, $record);
152
+        $this->assertTrue($record->exists());
153
+    }
154 154
 }
Please login to merge, or discard this patch.