Completed
Pull Request — master (#48)
by Sam
07:14
created
features/bootstrap/SilverStripe/SiteConfig/Test/Behaviour/ThemeContext.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -54,6 +54,9 @@  discard block
 block discarded – undo
54 54
         $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55 55
     }
56 56
 
57
+    /**
58
+     * @param string $filename
59
+     */
57 60
     protected function requireFile($filename, $content)
58 61
     {
59 62
         // Already exists
@@ -71,6 +74,9 @@  discard block
 block discarded – undo
71 74
         }
72 75
     }
73 76
 
77
+    /**
78
+     * @param string $dirname
79
+     */
74 80
     protected function requireDir($dirname)
75 81
     {
76 82
         // Directory doesn't exist, create it and mark it for deletion
Please login to merge, or discard this patch.
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -2,15 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace SilverStripe\Siteconfig\Test\Behaviour;
4 4
 
5
-use Behat\Behat\Context\ClosuredContextInterface;
6
-use Behat\Behat\Context\TranslatedContextInterface;
7 5
 use Behat\Behat\Context\BehatContext;
8
-use Behat\Behat\Context\Step;
9
-use Behat\Behat\Event\StepEvent;
10
-use Behat\Behat\Exception\PendingException;
11
-use Behat\Mink\Driver\Selenium2Driver;
12
-use Behat\Gherkin\Node\PyStringNode;
13
-use Behat\Gherkin\Node\TableNode;
14 6
 
15 7
 /**
16 8
  * Context used to create fixtures in the SilverStripe ORM.
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -17,100 +17,100 @@
 block discarded – undo
17 17
  */
18 18
 class ThemeContext extends BehatContext
19 19
 {
20
-    protected $restoreFiles = array();
21
-    protected $restoreDirectories = array();
20
+	protected $restoreFiles = array();
21
+	protected $restoreDirectories = array();
22 22
 
23
-    /**
24
-     * Create a test theme
25
-     *
26
-     * @Given /^a theme "(?<theme>[^"]+)"/
27
-     */
28
-    public function stepCreateTheme($theme)
29
-    {
30
-        if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
31
-            throw new \InvalidArgumentException("Bad theme '$theme'");
32
-        }
23
+	/**
24
+	 * Create a test theme
25
+	 *
26
+	 * @Given /^a theme "(?<theme>[^"]+)"/
27
+	 */
28
+	public function stepCreateTheme($theme)
29
+	{
30
+		if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
31
+			throw new \InvalidArgumentException("Bad theme '$theme'");
32
+		}
33 33
 
34
-        $this->requireDir(BASE_PATH . '/themes');
35
-        $this->requireDir(BASE_PATH . '/themes/' . $theme);
36
-        $this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
37
-    }
34
+		$this->requireDir(BASE_PATH . '/themes');
35
+		$this->requireDir(BASE_PATH . '/themes/' . $theme);
36
+		$this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
37
+	}
38 38
 
39
-    /**
40
-     * Create a template within a test theme
41
-     *
42
-     * @Given /^a template "(?<template>[^"]+)" in theme "(?<theme>[^"]+)" with content "(?<content>[^"]+)"/
43
-     */
44
-    public function stepCreateTemplate($template, $theme, $content)
45
-    {
46
-        if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
47
-            throw new \InvalidArgumentException("Bad theme '$theme'");
48
-        }
49
-        if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) {
50
-            throw new \InvalidArgumentException("Bad template '$template'");
51
-        }
39
+	/**
40
+	 * Create a template within a test theme
41
+	 *
42
+	 * @Given /^a template "(?<template>[^"]+)" in theme "(?<theme>[^"]+)" with content "(?<content>[^"]+)"/
43
+	 */
44
+	public function stepCreateTemplate($template, $theme, $content)
45
+	{
46
+		if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) {
47
+			throw new \InvalidArgumentException("Bad theme '$theme'");
48
+		}
49
+		if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) {
50
+			throw new \InvalidArgumentException("Bad template '$template'");
51
+		}
52 52
 
53
-        $this->stepCreateTheme($theme);
54
-        $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55
-    }
53
+		$this->stepCreateTheme($theme);
54
+		$this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
55
+	}
56 56
 
57
-    protected function requireFile($filename, $content)
58
-    {
59
-        // Already exists
60
-        if (file_exists($filename)) {
61
-            // If the content is different, remember old content for restoration
62
-            $origContent = file_get_contents($filename);
63
-            if ($origContent != $content) {
64
-                file_put_contents($filename, $content);
65
-                $this->restoreFiles[$filename] = $origContent;
66
-            }
67
-        // Doesn't exist, mark it for deletion after test
68
-        } else {
69
-            file_put_contents($filename, $content);
70
-            $this->restoreFiles[$filename] = null;
71
-        }
72
-    }
57
+	protected function requireFile($filename, $content)
58
+	{
59
+		// Already exists
60
+		if (file_exists($filename)) {
61
+			// If the content is different, remember old content for restoration
62
+			$origContent = file_get_contents($filename);
63
+			if ($origContent != $content) {
64
+				file_put_contents($filename, $content);
65
+				$this->restoreFiles[$filename] = $origContent;
66
+			}
67
+		// Doesn't exist, mark it for deletion after test
68
+		} else {
69
+			file_put_contents($filename, $content);
70
+			$this->restoreFiles[$filename] = null;
71
+		}
72
+	}
73 73
 
74
-    protected function requireDir($dirname)
75
-    {
76
-        // Directory doesn't exist, create it and mark it for deletion
77
-        if (!file_exists($dirname)) {
78
-            mkdir($dirname);
79
-            $this->restoreDirectories[] = $dirname;
80
-        }
81
-    }
74
+	protected function requireDir($dirname)
75
+	{
76
+		// Directory doesn't exist, create it and mark it for deletion
77
+		if (!file_exists($dirname)) {
78
+			mkdir($dirname);
79
+			$this->restoreDirectories[] = $dirname;
80
+		}
81
+	}
82 82
 
83
-    /**
84
-     * Clean up any theme manipulation
85
-     *
86
-     * @AfterScenario
87
-     */
88
-    public function cleanThemesAfterScenario()
89
-    {
90
-        // Restore any created/modified files.
91
-        //  - If modified, revert then to original contnet
92
-        //  - If created, delete them
93
-        if ($this->restoreFiles) {
94
-            foreach ($this->restoreFiles as $file => $origContent) {
95
-                if ($origContent === null) {
96
-                    unlink($file);
97
-                } else {
98
-                    file_put_contents($file, $origContent);
99
-                }
100
-            }
83
+	/**
84
+	 * Clean up any theme manipulation
85
+	 *
86
+	 * @AfterScenario
87
+	 */
88
+	public function cleanThemesAfterScenario()
89
+	{
90
+		// Restore any created/modified files.
91
+		//  - If modified, revert then to original contnet
92
+		//  - If created, delete them
93
+		if ($this->restoreFiles) {
94
+			foreach ($this->restoreFiles as $file => $origContent) {
95
+				if ($origContent === null) {
96
+					unlink($file);
97
+				} else {
98
+					file_put_contents($file, $origContent);
99
+				}
100
+			}
101 101
 
102
-            $this->restoreFiles = array();
103
-        }
102
+			$this->restoreFiles = array();
103
+		}
104 104
 
105
-        // Restore any created directories: that is, delete them
106
-        if ($this->restoreDirectories) {
107
-            // Flip the order so that nested direcotires are unlinked() first
108
-            $this->restoreDirectories = array_reverse($this->restoreDirectories);
109
-            foreach ($this->restoreDirectories as $dir) {
110
-                rmdir($dir);
111
-            }
105
+		// Restore any created directories: that is, delete them
106
+		if ($this->restoreDirectories) {
107
+			// Flip the order so that nested direcotires are unlinked() first
108
+			$this->restoreDirectories = array_reverse($this->restoreDirectories);
109
+			foreach ($this->restoreDirectories as $dir) {
110
+				rmdir($dir);
111
+			}
112 112
 
113
-            $this->restoreDirectories = array();
114
-        }
115
-    }
113
+			$this->restoreDirectories = array();
114
+		}
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
             throw new \InvalidArgumentException("Bad theme '$theme'");
32 32
         }
33 33
 
34
-        $this->requireDir(BASE_PATH . '/themes');
35
-        $this->requireDir(BASE_PATH . '/themes/' . $theme);
36
-        $this->requireDir(BASE_PATH . '/themes/' . $theme . '/templates');
34
+        $this->requireDir(BASE_PATH.'/themes');
35
+        $this->requireDir(BASE_PATH.'/themes/'.$theme);
36
+        $this->requireDir(BASE_PATH.'/themes/'.$theme.'/templates');
37 37
     }
38 38
 
39 39
     /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         }
52 52
 
53 53
         $this->stepCreateTheme($theme);
54
-        $this->requireFile(BASE_PATH . '/themes/' . $theme . '/templates/' . $template, $content);
54
+        $this->requireFile(BASE_PATH.'/themes/'.$theme.'/templates/'.$template, $content);
55 55
     }
56 56
 
57 57
     protected function requireFile($filename, $content)
Please login to merge, or discard this patch.
code/SiteConfig.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@
 block discarded – undo
242 242
      * Can a user view this SiteConfig instance?
243 243
      *
244 244
      * @param Member $member
245
-     * @return boolean
245
+     * @return boolean|string
246 246
      */
247 247
     public function canView($member = null)
248 248
     {
Please login to merge, or discard this patch.
Indentation   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -34,399 +34,399 @@
 block discarded – undo
34 34
  */
35 35
 class SiteConfig extends DataObject implements PermissionProvider, TemplateGlobalProvider
36 36
 {
37
-    private static $db = array(
38
-        "Title" => "Varchar(255)",
39
-        "Tagline" => "Varchar(255)",
40
-        "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
41
-        "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
42
-        "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
43
-    );
44
-
45
-    private static $many_many = array(
46
-        "ViewerGroups" => "SilverStripe\\Security\\Group",
47
-        "EditorGroups" => "SilverStripe\\Security\\Group",
48
-        "CreateTopLevelGroups" => "SilverStripe\\Security\\Group"
49
-    );
50
-
51
-    private static $defaults = array(
52
-        "CanViewType" => "Anyone",
53
-        "CanEditType" => "LoggedInUsers",
54
-        "CanCreateTopLevelType" => "LoggedInUsers",
55
-    );
56
-
57
-    private static $table_name = 'SiteConfig';
58
-
59
-    /**
60
-     * Default permission to check for 'LoggedInUsers' to create or edit pages
61
-     *
62
-     * @var array
63
-     * @config
64
-     */
65
-    private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
66
-
67
-
68
-    public function populateDefaults()
69
-    {
70
-        $this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
71
-        $this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
72
-
73
-        // Allow these defaults to be overridden
74
-        parent::populateDefaults();
75
-    }
76
-
77
-    /**
78
-     * Get the fields that are sent to the CMS.
79
-     *
80
-     * In your extensions: updateCMSFields($fields).
81
-     *
82
-     * @return FieldList
83
-     */
84
-    public function getCMSFields()
85
-    {
86
-        $groupsMap = array();
87
-
88
-        foreach (Group::get() as $group) {
89
-            // Listboxfield values are escaped, use ASCII char instead of &raquo;
90
-            $groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
91
-        }
92
-        asort($groupsMap);
93
-
94
-        $fields = new FieldList(
95
-            new TabSet("Root",
96
-                $tabMain = new Tab('Main',
97
-                    $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
98
-                    $taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan"))
99
-                ),
100
-                $tabAccess = new Tab('Access',
101
-                    $viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
102
-                    $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
103
-                        ->setSource($groupsMap)
104
-                        ->setAttribute(
105
-                            'data-placeholder',
106
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
107
-                        ),
108
-                    $editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
109
-                    $editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
110
-                        ->setSource($groupsMap)
111
-                        ->setAttribute(
112
-                            'data-placeholder',
113
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
114
-                        ),
115
-                    $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
116
-                    $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
117
-                        ->setSource($groupsMap)
118
-                        ->setAttribute(
119
-                            'data-placeholder',
120
-                            _t('SiteTree.GroupPlaceholder', 'Click to select group')
121
-                        )
122
-                )
123
-            ),
124
-            new HiddenField('ID')
125
-        );
126
-
127
-        $viewersOptionsSource = array();
128
-        $viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
129
-        $viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
130
-        $viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
131
-        $viewersOptionsField->setSource($viewersOptionsSource);
132
-
133
-        $editorsOptionsSource = array();
134
-        $editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
135
-        $editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
136
-        $editorsOptionsField->setSource($editorsOptionsSource);
137
-
138
-        $topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
139
-
140
-        if (!Permission::check('EDIT_SITECONFIG')) {
141
-            $fields->makeFieldReadonly($viewersOptionsField);
142
-            $fields->makeFieldReadonly($viewerGroupsField);
143
-            $fields->makeFieldReadonly($editorsOptionsField);
144
-            $fields->makeFieldReadonly($editorGroupsField);
145
-            $fields->makeFieldReadonly($topLevelCreatorsOptionsField);
146
-            $fields->makeFieldReadonly($topLevelCreatorsGroupsField);
147
-            $fields->makeFieldReadonly($taglineField);
148
-            $fields->makeFieldReadonly($titleField);
149
-        }
150
-
151
-        if (file_exists(BASE_PATH . '/install.php')) {
152
-            $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
153
-                "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
154
-                "Warning: You should remove install.php from this SilverStripe install for security reasons.")
155
-                . "</p>"), "Title");
156
-        }
157
-
158
-        $tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
159
-        $tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
160
-        $this->extend('updateCMSFields', $fields);
161
-
162
-        return $fields;
163
-    }
164
-
165
-    /**
166
-     * Get the actions that are sent to the CMS.
167
-     *
168
-     * In your extensions: updateEditFormActions($actions)
169
-     *
170
-     * @return FieldList
171
-     */
172
-    public function getCMSActions()
173
-    {
174
-        if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
175
-            $actions = new FieldList(
176
-                FormAction::create('save_siteconfig',
177
-                    _t('CMSMain.SAVE', 'Save')
178
-                )->addExtraClass('btn-primary font-icon-save')
179
-            );
180
-        } else {
181
-            $actions = new FieldList();
182
-        }
183
-
184
-        $this->extend('updateCMSActions', $actions);
185
-
186
-        return $actions;
187
-    }
188
-
189
-    /**
190
-     * @return string
191
-     */
192
-    public function CMSEditLink()
193
-    {
194
-        return SiteConfigLeftAndMain::singleton()->Link();
195
-    }
196
-
197
-    /**
198
-     * Get the current sites SiteConfig, and creates a new one through
199
-     * {@link make_site_config()} if none is found.
200
-     *
201
-     * @return SiteConfig
202
-     */
203
-    public static function current_site_config()
204
-    {
205
-        if ($siteConfig = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig')) {
206
-            return $siteConfig;
207
-        }
208
-
209
-        return self::make_site_config();
210
-    }
211
-
212
-    /**
213
-     * Setup a default SiteConfig record if none exists.
214
-     */
215
-    public function requireDefaultRecords()
216
-    {
217
-        parent::requireDefaultRecords();
218
-
219
-        $config = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig');
220
-
221
-        if (!$config) {
222
-            self::make_site_config();
223
-
224
-            DB::alteration_message("Added default site config", "created");
225
-        }
226
-    }
227
-
228
-    /**
229
-     * Create SiteConfig with defaults from language file.
230
-     *
231
-     * @return SiteConfig
232
-     */
233
-    public static function make_site_config()
234
-    {
235
-        $config = SiteConfig::create();
236
-        $config->write();
237
-
238
-        return $config;
239
-    }
240
-
241
-    /**
242
-     * Can a user view this SiteConfig instance?
243
-     *
244
-     * @param Member $member
245
-     * @return boolean
246
-     */
247
-    public function canView($member = null)
248
-    {
249
-        if (!$member) {
250
-            $member = Member::currentUserID();
251
-        }
252
-        if ($member && is_numeric($member)) {
253
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
254
-        }
255
-
256
-        $extended = $this->extendedCan('canView', $member);
257
-        if ($extended !== null) {
258
-            return $extended;
259
-        }
260
-
261
-        // Assuming all that can edit this object can also view it
262
-        return $this->canEdit($member);
263
-    }
264
-
265
-    /**
266
-     * Can a user view pages on this site? This method is only
267
-     * called if a page is set to Inherit, but there is nothing
268
-     * to inherit from.
269
-     *
270
-     * @param Member $member
271
-     * @return boolean
272
-     */
273
-    public function canViewPages($member = null)
274
-    {
275
-        if (!$member) {
276
-            $member = Member::currentUserID();
277
-        }
278
-        if ($member && is_numeric($member)) {
279
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
280
-        }
281
-
282
-        if ($member && Permission::checkMember($member, "ADMIN")) {
283
-            return true;
284
-        }
285
-
286
-        $extended = $this->extendedCan('canViewPages', $member);
287
-        if ($extended !== null) {
288
-            return $extended;
289
-        }
290
-
291
-        if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
292
-            return true;
293
-        }
294
-
295
-        // check for any logged-in users
296
-        if ($this->CanViewType === 'LoggedInUsers' && $member) {
297
-            return true;
298
-        }
299
-
300
-        // check for specific groups
301
-        if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
302
-            return true;
303
-        }
304
-
305
-        return false;
306
-    }
307
-
308
-    /**
309
-     * Can a user edit pages on this site? This method is only
310
-     * called if a page is set to Inherit, but there is nothing
311
-     * to inherit from, or on new records without a parent.
312
-     *
313
-     * @param Member $member
314
-     * @return boolean
315
-     */
316
-    public function canEditPages($member = null)
317
-    {
318
-        if (!$member) {
319
-            $member = Member::currentUserID();
320
-        }
321
-        if ($member && is_numeric($member)) {
322
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
323
-        }
324
-
325
-        if ($member && Permission::checkMember($member, "ADMIN")) {
326
-            return true;
327
-        }
328
-
329
-        $extended = $this->extendedCan('canEditPages', $member);
330
-        if ($extended !== null) {
331
-            return $extended;
332
-        }
333
-
334
-        // check for any logged-in users with CMS access
335
-        if ($this->CanEditType === 'LoggedInUsers'
336
-            && Permission::checkMember($member, $this->config()->required_permission)
337
-        ) {
338
-            return true;
339
-        }
340
-
341
-            // check for specific groups
342
-        if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
343
-            return true;
344
-        }
345
-
346
-        return false;
347
-    }
348
-
349
-    public function canEdit($member = null)
350
-    {
351
-        if (!$member) {
352
-            $member = Member::currentUserID();
353
-        }
354
-        if ($member && is_numeric($member)) {
355
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
356
-        }
357
-
358
-        $extended = $this->extendedCan('canEdit', $member);
359
-        if ($extended !== null) {
360
-            return $extended;
361
-        }
362
-
363
-        return Permission::checkMember($member, "EDIT_SITECONFIG");
364
-    }
365
-
366
-    /**
367
-     * @return array
368
-     */
369
-    public function providePermissions()
370
-    {
371
-        return array(
372
-            'EDIT_SITECONFIG' => array(
373
-                'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
374
-                'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
375
-                'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
376
-                'sort' => 400
377
-            )
378
-        );
379
-    }
380
-
381
-    /**
382
-     * Can a user create pages in the root of this site?
383
-     *
384
-     * @param Member $member
385
-     * @return boolean
386
-     */
387
-    public function canCreateTopLevel($member = null)
388
-    {
389
-        if (!$member) {
390
-            $member = Member::currentUserID();
391
-        }
392
-        if ($member && is_numeric($member)) {
393
-            $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
394
-        }
395
-
396
-        if ($member && Permission::checkMember($member, "ADMIN")) {
397
-            return true;
398
-        }
399
-
400
-        $extended = $this->extendedCan('canCreateTopLevel', $member);
401
-        if ($extended !== null) {
402
-            return $extended;
403
-        }
404
-
405
-        // check for any logged-in users with CMS permission
406
-        if ($this->CanCreateTopLevelType === 'LoggedInUsers'
407
-            && Permission::checkMember($member, $this->config()->required_permission)
408
-        ) {
409
-            return true;
410
-        }
411
-
412
-        // check for specific groups
413
-        if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
414
-            && $member
415
-            && $member->inGroups($this->CreateTopLevelGroups())
416
-        ) {
417
-            return true;
418
-        }
419
-
420
-        return false;
421
-    }
422
-
423
-    /**
424
-     * Add $SiteConfig to all SSViewers
425
-     */
426
-    public static function get_template_global_variables()
427
-    {
428
-        return array(
429
-            'SiteConfig' => 'current_site_config',
430
-        );
431
-    }
37
+	private static $db = array(
38
+		"Title" => "Varchar(255)",
39
+		"Tagline" => "Varchar(255)",
40
+		"CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')",
41
+		"CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
42
+		"CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')",
43
+	);
44
+
45
+	private static $many_many = array(
46
+		"ViewerGroups" => "SilverStripe\\Security\\Group",
47
+		"EditorGroups" => "SilverStripe\\Security\\Group",
48
+		"CreateTopLevelGroups" => "SilverStripe\\Security\\Group"
49
+	);
50
+
51
+	private static $defaults = array(
52
+		"CanViewType" => "Anyone",
53
+		"CanEditType" => "LoggedInUsers",
54
+		"CanCreateTopLevelType" => "LoggedInUsers",
55
+	);
56
+
57
+	private static $table_name = 'SiteConfig';
58
+
59
+	/**
60
+	 * Default permission to check for 'LoggedInUsers' to create or edit pages
61
+	 *
62
+	 * @var array
63
+	 * @config
64
+	 */
65
+	private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain');
66
+
67
+
68
+	public function populateDefaults()
69
+	{
70
+		$this->Title = _t('SiteConfig.SITENAMEDEFAULT', "Your Site Name");
71
+		$this->Tagline = _t('SiteConfig.TAGLINEDEFAULT', "your tagline here");
72
+
73
+		// Allow these defaults to be overridden
74
+		parent::populateDefaults();
75
+	}
76
+
77
+	/**
78
+	 * Get the fields that are sent to the CMS.
79
+	 *
80
+	 * In your extensions: updateCMSFields($fields).
81
+	 *
82
+	 * @return FieldList
83
+	 */
84
+	public function getCMSFields()
85
+	{
86
+		$groupsMap = array();
87
+
88
+		foreach (Group::get() as $group) {
89
+			// Listboxfield values are escaped, use ASCII char instead of &raquo;
90
+			$groupsMap[$group->ID] = $group->getBreadcrumbs(' > ');
91
+		}
92
+		asort($groupsMap);
93
+
94
+		$fields = new FieldList(
95
+			new TabSet("Root",
96
+				$tabMain = new Tab('Main',
97
+					$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),
98
+					$taglineField = new TextField("Tagline", _t('SiteConfig.SITETAGLINE', "Site Tagline/Slogan"))
99
+				),
100
+				$tabAccess = new Tab('Access',
101
+					$viewersOptionsField = new OptionsetField("CanViewType", _t('SiteConfig.VIEWHEADER', "Who can view pages on this site?")),
102
+					$viewerGroupsField = ListboxField::create("ViewerGroups", _t('SiteTree.VIEWERGROUPS', "Viewer Groups"))
103
+						->setSource($groupsMap)
104
+						->setAttribute(
105
+							'data-placeholder',
106
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
107
+						),
108
+					$editorsOptionsField = new OptionsetField("CanEditType", _t('SiteConfig.EDITHEADER', "Who can edit pages on this site?")),
109
+					$editorGroupsField = ListboxField::create("EditorGroups", _t('SiteTree.EDITORGROUPS', "Editor Groups"))
110
+						->setSource($groupsMap)
111
+						->setAttribute(
112
+							'data-placeholder',
113
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
114
+						),
115
+					$topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")),
116
+					$topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t('SiteTree.TOPLEVELCREATORGROUPS', "Top level creators"))
117
+						->setSource($groupsMap)
118
+						->setAttribute(
119
+							'data-placeholder',
120
+							_t('SiteTree.GroupPlaceholder', 'Click to select group')
121
+						)
122
+				)
123
+			),
124
+			new HiddenField('ID')
125
+		);
126
+
127
+		$viewersOptionsSource = array();
128
+		$viewersOptionsSource["Anyone"] = _t('SiteTree.ACCESSANYONE', "Anyone");
129
+		$viewersOptionsSource["LoggedInUsers"] = _t('SiteTree.ACCESSLOGGEDIN', "Logged-in users");
130
+		$viewersOptionsSource["OnlyTheseUsers"] = _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)");
131
+		$viewersOptionsField->setSource($viewersOptionsSource);
132
+
133
+		$editorsOptionsSource = array();
134
+		$editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS");
135
+		$editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)");
136
+		$editorsOptionsField->setSource($editorsOptionsSource);
137
+
138
+		$topLevelCreatorsOptionsField->setSource($editorsOptionsSource);
139
+
140
+		if (!Permission::check('EDIT_SITECONFIG')) {
141
+			$fields->makeFieldReadonly($viewersOptionsField);
142
+			$fields->makeFieldReadonly($viewerGroupsField);
143
+			$fields->makeFieldReadonly($editorsOptionsField);
144
+			$fields->makeFieldReadonly($editorGroupsField);
145
+			$fields->makeFieldReadonly($topLevelCreatorsOptionsField);
146
+			$fields->makeFieldReadonly($topLevelCreatorsGroupsField);
147
+			$fields->makeFieldReadonly($taglineField);
148
+			$fields->makeFieldReadonly($titleField);
149
+		}
150
+
151
+		if (file_exists(BASE_PATH . '/install.php')) {
152
+			$fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
153
+				"<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
154
+				"Warning: You should remove install.php from this SilverStripe install for security reasons.")
155
+				. "</p>"), "Title");
156
+		}
157
+
158
+		$tabMain->setTitle(_t('SiteConfig.TABMAIN', "Main"));
159
+		$tabAccess->setTitle(_t('SiteConfig.TABACCESS', "Access"));
160
+		$this->extend('updateCMSFields', $fields);
161
+
162
+		return $fields;
163
+	}
164
+
165
+	/**
166
+	 * Get the actions that are sent to the CMS.
167
+	 *
168
+	 * In your extensions: updateEditFormActions($actions)
169
+	 *
170
+	 * @return FieldList
171
+	 */
172
+	public function getCMSActions()
173
+	{
174
+		if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
175
+			$actions = new FieldList(
176
+				FormAction::create('save_siteconfig',
177
+					_t('CMSMain.SAVE', 'Save')
178
+				)->addExtraClass('btn-primary font-icon-save')
179
+			);
180
+		} else {
181
+			$actions = new FieldList();
182
+		}
183
+
184
+		$this->extend('updateCMSActions', $actions);
185
+
186
+		return $actions;
187
+	}
188
+
189
+	/**
190
+	 * @return string
191
+	 */
192
+	public function CMSEditLink()
193
+	{
194
+		return SiteConfigLeftAndMain::singleton()->Link();
195
+	}
196
+
197
+	/**
198
+	 * Get the current sites SiteConfig, and creates a new one through
199
+	 * {@link make_site_config()} if none is found.
200
+	 *
201
+	 * @return SiteConfig
202
+	 */
203
+	public static function current_site_config()
204
+	{
205
+		if ($siteConfig = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig')) {
206
+			return $siteConfig;
207
+		}
208
+
209
+		return self::make_site_config();
210
+	}
211
+
212
+	/**
213
+	 * Setup a default SiteConfig record if none exists.
214
+	 */
215
+	public function requireDefaultRecords()
216
+	{
217
+		parent::requireDefaultRecords();
218
+
219
+		$config = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig');
220
+
221
+		if (!$config) {
222
+			self::make_site_config();
223
+
224
+			DB::alteration_message("Added default site config", "created");
225
+		}
226
+	}
227
+
228
+	/**
229
+	 * Create SiteConfig with defaults from language file.
230
+	 *
231
+	 * @return SiteConfig
232
+	 */
233
+	public static function make_site_config()
234
+	{
235
+		$config = SiteConfig::create();
236
+		$config->write();
237
+
238
+		return $config;
239
+	}
240
+
241
+	/**
242
+	 * Can a user view this SiteConfig instance?
243
+	 *
244
+	 * @param Member $member
245
+	 * @return boolean
246
+	 */
247
+	public function canView($member = null)
248
+	{
249
+		if (!$member) {
250
+			$member = Member::currentUserID();
251
+		}
252
+		if ($member && is_numeric($member)) {
253
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
254
+		}
255
+
256
+		$extended = $this->extendedCan('canView', $member);
257
+		if ($extended !== null) {
258
+			return $extended;
259
+		}
260
+
261
+		// Assuming all that can edit this object can also view it
262
+		return $this->canEdit($member);
263
+	}
264
+
265
+	/**
266
+	 * Can a user view pages on this site? This method is only
267
+	 * called if a page is set to Inherit, but there is nothing
268
+	 * to inherit from.
269
+	 *
270
+	 * @param Member $member
271
+	 * @return boolean
272
+	 */
273
+	public function canViewPages($member = null)
274
+	{
275
+		if (!$member) {
276
+			$member = Member::currentUserID();
277
+		}
278
+		if ($member && is_numeric($member)) {
279
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
280
+		}
281
+
282
+		if ($member && Permission::checkMember($member, "ADMIN")) {
283
+			return true;
284
+		}
285
+
286
+		$extended = $this->extendedCan('canViewPages', $member);
287
+		if ($extended !== null) {
288
+			return $extended;
289
+		}
290
+
291
+		if (!$this->CanViewType || $this->CanViewType == 'Anyone') {
292
+			return true;
293
+		}
294
+
295
+		// check for any logged-in users
296
+		if ($this->CanViewType === 'LoggedInUsers' && $member) {
297
+			return true;
298
+		}
299
+
300
+		// check for specific groups
301
+		if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) {
302
+			return true;
303
+		}
304
+
305
+		return false;
306
+	}
307
+
308
+	/**
309
+	 * Can a user edit pages on this site? This method is only
310
+	 * called if a page is set to Inherit, but there is nothing
311
+	 * to inherit from, or on new records without a parent.
312
+	 *
313
+	 * @param Member $member
314
+	 * @return boolean
315
+	 */
316
+	public function canEditPages($member = null)
317
+	{
318
+		if (!$member) {
319
+			$member = Member::currentUserID();
320
+		}
321
+		if ($member && is_numeric($member)) {
322
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
323
+		}
324
+
325
+		if ($member && Permission::checkMember($member, "ADMIN")) {
326
+			return true;
327
+		}
328
+
329
+		$extended = $this->extendedCan('canEditPages', $member);
330
+		if ($extended !== null) {
331
+			return $extended;
332
+		}
333
+
334
+		// check for any logged-in users with CMS access
335
+		if ($this->CanEditType === 'LoggedInUsers'
336
+			&& Permission::checkMember($member, $this->config()->required_permission)
337
+		) {
338
+			return true;
339
+		}
340
+
341
+			// check for specific groups
342
+		if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) {
343
+			return true;
344
+		}
345
+
346
+		return false;
347
+	}
348
+
349
+	public function canEdit($member = null)
350
+	{
351
+		if (!$member) {
352
+			$member = Member::currentUserID();
353
+		}
354
+		if ($member && is_numeric($member)) {
355
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
356
+		}
357
+
358
+		$extended = $this->extendedCan('canEdit', $member);
359
+		if ($extended !== null) {
360
+			return $extended;
361
+		}
362
+
363
+		return Permission::checkMember($member, "EDIT_SITECONFIG");
364
+	}
365
+
366
+	/**
367
+	 * @return array
368
+	 */
369
+	public function providePermissions()
370
+	{
371
+		return array(
372
+			'EDIT_SITECONFIG' => array(
373
+				'name' => _t('SiteConfig.EDIT_PERMISSION', 'Manage site configuration'),
374
+				'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
375
+				'help' => _t('SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'),
376
+				'sort' => 400
377
+			)
378
+		);
379
+	}
380
+
381
+	/**
382
+	 * Can a user create pages in the root of this site?
383
+	 *
384
+	 * @param Member $member
385
+	 * @return boolean
386
+	 */
387
+	public function canCreateTopLevel($member = null)
388
+	{
389
+		if (!$member) {
390
+			$member = Member::currentUserID();
391
+		}
392
+		if ($member && is_numeric($member)) {
393
+			$member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
394
+		}
395
+
396
+		if ($member && Permission::checkMember($member, "ADMIN")) {
397
+			return true;
398
+		}
399
+
400
+		$extended = $this->extendedCan('canCreateTopLevel', $member);
401
+		if ($extended !== null) {
402
+			return $extended;
403
+		}
404
+
405
+		// check for any logged-in users with CMS permission
406
+		if ($this->CanCreateTopLevelType === 'LoggedInUsers'
407
+			&& Permission::checkMember($member, $this->config()->required_permission)
408
+		) {
409
+			return true;
410
+		}
411
+
412
+		// check for specific groups
413
+		if ($this->CanCreateTopLevelType === 'OnlyTheseUsers'
414
+			&& $member
415
+			&& $member->inGroups($this->CreateTopLevelGroups())
416
+		) {
417
+			return true;
418
+		}
419
+
420
+		return false;
421
+	}
422
+
423
+	/**
424
+	 * Add $SiteConfig to all SSViewers
425
+	 */
426
+	public static function get_template_global_variables()
427
+	{
428
+		return array(
429
+			'SiteConfig' => 'current_site_config',
430
+		);
431
+	}
432 432
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -148,9 +148,9 @@
 block discarded – undo
148 148
             $fields->makeFieldReadonly($titleField);
149 149
         }
150 150
 
151
-        if (file_exists(BASE_PATH . '/install.php')) {
151
+        if (file_exists(BASE_PATH.'/install.php')) {
152 152
             $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader",
153
-                "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING",
153
+                "<p class=\"message warning\">"._t("SiteTree.REMOVE_INSTALL_WARNING",
154 154
                 "Warning: You should remove install.php from this SilverStripe install for security reasons.")
155 155
                 . "</p>"), "Title");
156 156
         }
Please login to merge, or discard this patch.
code/SiteConfigLeftAndMain.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 	 *
135 135
 	 * @param array $data
136 136
 	 * @param Form $form
137
-	 * @return String
137
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
138 138
 	 */
139 139
     public function save_siteconfig($data, $form)
140 140
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,6 @@
 block discarded – undo
8 8
 use SilverStripe\Forms\HiddenField;
9 9
 use SilverStripe\Forms\LiteralField;
10 10
 use SilverStripe\Forms\Form;
11
-use SilverStripe\ORM\ValidationException;
12 11
 use SilverStripe\ORM\ArrayList;
13 12
 use SilverStripe\ORM\ValidationResult;
14 13
 use SilverStripe\View\ArrayData;
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	public function init() {
58 58
 		parent::init();
59
-        if (defined('CMS_DIR')) {
60
-            Requirements::javascript(CMS_DIR . '/client/dist/js/bundle.js');
61
-        }
59
+		if (defined('CMS_DIR')) {
60
+			Requirements::javascript(CMS_DIR . '/client/dist/js/bundle.js');
61
+		}
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @return Form
69 69
 	 */
70
-    public function getEditForm($id = null, $fields = null)
71
-    {
70
+	public function getEditForm($id = null, $fields = null)
71
+	{
72 72
 		$siteConfig = SiteConfig::current_site_config();
73 73
 		$fields = $siteConfig->getCMSFields();
74 74
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		$fields->push(new HiddenField('PreviewURL', 'Preview URL', $home));
78 78
 
79 79
 		// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
80
-        /** @skipUpgrade */
80
+		/** @skipUpgrade */
81 81
 		$fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()));
82 82
 		$navField->setAllowHTML(true);
83 83
 
@@ -108,21 +108,21 @@  discard block
 block discarded – undo
108 108
 		$form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form');
109 109
 		$form->setAttribute('data-pjax-fragment', 'CurrentForm');
110 110
 
111
-        if ($form->Fields()->hasTabSet()) {
112
-            $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet');
113
-        }
111
+		if ($form->Fields()->hasTabSet()) {
112
+			$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet');
113
+		}
114 114
 		$form->setHTMLID('Form_EditForm');
115 115
 		$form->loadDataFrom($siteConfig);
116 116
 		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
117 117
 
118 118
 		// Use <button> to allow full jQuery UI styling
119 119
 		$actions = $actions->dataFields();
120
-        if ($actions) {
121
-            /** @var FormAction $action */
122
-            foreach ($actions as $action) {
123
-                $action->setUseButtonTag(true);
124
-            }
125
-        }
120
+		if ($actions) {
121
+			/** @var FormAction $action */
122
+			foreach ($actions as $action) {
123
+				$action->setUseButtonTag(true);
124
+			}
125
+		}
126 126
 
127 127
 		$this->extend('updateEditForm', $form);
128 128
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 	 * @param Form $form
137 137
 	 * @return String
138 138
 	 */
139
-    public function save_siteconfig($data, $form)
140
-    {
139
+	public function save_siteconfig($data, $form)
140
+	{
141 141
 		$siteConfig = SiteConfig::current_site_config();
142 142
 		$form->saveInto($siteConfig);
143 143
 		$siteConfig->write();
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 	}
147 147
 
148 148
 
149
-    public function Breadcrumbs($unlinked = false)
150
-    {
149
+	public function Breadcrumbs($unlinked = false)
150
+	{
151 151
 		return new ArrayList(array(
152 152
 			new ArrayData(array(
153 153
 				'Title' => static::menu_title(),
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	public function init() {
58 58
 		parent::init();
59 59
         if (defined('CMS_DIR')) {
60
-            Requirements::javascript(CMS_DIR . '/client/dist/js/bundle.js');
60
+            Requirements::javascript(CMS_DIR.'/client/dist/js/bundle.js');
61 61
         }
62 62
 	}
63 63
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		)->setHTMLID('Form_EditForm');
97 97
 		$form->setValidationResponseCallback(function(ValidationResult $errors) use ($negotiator, $form) {
98 98
 			$request = $this->getRequest();
99
-			if($request->isAjax() && $negotiator) {
99
+			if ($request->isAjax() && $negotiator) {
100 100
 				$result = $form->forTemplate();
101 101
 				return $negotiator->respond($request, array(
102 102
 					'CurrentForm' => function() use($result) {
Please login to merge, or discard this patch.
tests/behat/features/bootstrap/Context/FeatureContext.php 3 patches
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -2,9 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace SilverStripe\Siteconfig\Test\Behaviour;
4 4
 
5
-use SilverStripe\BehatExtension\Context\SilverStripeContext;
6
-use SilverStripe\BehatExtension\Context\BasicContext;
7
-use SilverStripe\BehatExtension\Context\LoginContext;
8 5
 use SilverStripe\BehatExtension\Context\FixtureContext;
9 6
 use SilverStripe\Cms\Test\Behaviour;
10 7
 use SilverStripe\Core\ClassInfo;
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -19,35 +19,35 @@
 block discarded – undo
19 19
  */
20 20
 class FeatureContext extends \SilverStripe\Framework\Test\Behaviour\FeatureContext
21 21
 {
22
-    /**
23
-     * Initializes context.
24
-     * Every scenario gets it's own context object.
25
-     *
26
-     * @param   array   $parameters     context parameters (set them up through behat.yml)
27
-     */
28
-    public function __construct(array $parameters)
29
-    {
30
-        parent::__construct($parameters);
22
+	/**
23
+	 * Initializes context.
24
+	 * Every scenario gets it's own context object.
25
+	 *
26
+	 * @param   array   $parameters     context parameters (set them up through behat.yml)
27
+	 */
28
+	public function __construct(array $parameters)
29
+	{
30
+		parent::__construct($parameters);
31 31
 
32
-        // Override existing fixture context with more specific one
33
-        $fixtureContext = new \SilverStripe\Siteconfig\Test\Behaviour\FixtureContext($parameters);
34
-        $fixtureContext->setFixtureFactory($this->getFixtureFactory());
35
-        $this->useContext('FixtureContext', $fixtureContext);
32
+		// Override existing fixture context with more specific one
33
+		$fixtureContext = new \SilverStripe\Siteconfig\Test\Behaviour\FixtureContext($parameters);
34
+		$fixtureContext->setFixtureFactory($this->getFixtureFactory());
35
+		$this->useContext('FixtureContext', $fixtureContext);
36 36
 
37
-        // Add extra contexts with more steps
38
-        $this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
39
-        if(!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
40
-            return;
41
-        }
37
+		// Add extra contexts with more steps
38
+		$this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
39
+		if(!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
40
+			return;
41
+		}
42 42
 
43
-        // Use blueprints which auto-publish all subclasses of SiteTree
44
-        $factory = $fixtureContext->getFixtureFactory();
45
-        foreach (ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree') as $id => $class) {
46
-            $blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', $class);
47
-            $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
48
-                $obj->publish('Stage', 'Live');
49
-            });
50
-            $factory->define($class, $blueprint);
51
-        }
52
-    }
43
+		// Use blueprints which auto-publish all subclasses of SiteTree
44
+		$factory = $fixtureContext->getFixtureFactory();
45
+		foreach (ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree') as $id => $class) {
46
+			$blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', $class);
47
+			$blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
48
+				$obj->publish('Stage', 'Live');
49
+			});
50
+			$factory->define($class, $blueprint);
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
         // Add extra contexts with more steps
38 38
         $this->useContext('ThemeContext', new \SilverStripe\Siteconfig\Test\Behaviour\ThemeContext($parameters));
39
-        if(!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
39
+        if (!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
40 40
             return;
41 41
         }
42 42
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         $factory = $fixtureContext->getFixtureFactory();
45 45
         foreach (ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree') as $id => $class) {
46 46
             $blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', $class);
47
-            $blueprint->addCallback('afterCreate', function ($obj, $identifier, &$data, &$fixtures) {
47
+            $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) {
48 48
                 $obj->publish('Stage', 'Live');
49 49
             });
50 50
             $factory->define($class, $blueprint);
Please login to merge, or discard this patch.
tests/SiteConfigTest.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -9,66 +9,66 @@
 block discarded – undo
9 9
  */
10 10
 class SiteConfigTest extends SapphireTest
11 11
 {
12
-    protected static $fixture_file = 'SiteConfigTest.yml';
12
+	protected static $fixture_file = 'SiteConfigTest.yml';
13 13
 
14
-    protected $illegalExtensions = array(
15
-        'SilverStripe\\CMS\\Model\\SiteTree' => array('SiteTreeSubsites')
16
-    );
14
+	protected $illegalExtensions = array(
15
+		'SilverStripe\\CMS\\Model\\SiteTree' => array('SiteTreeSubsites')
16
+	);
17 17
 
18
-    public function setUpOnce()
19
-    {
20
-        // Fix issue with tests failing without CMS module
21
-        if (!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
22
-            unset($this->illegalExtensions['SilverStripe\\CMS\\Model\\SiteTree']);
23
-        }
18
+	public function setUpOnce()
19
+	{
20
+		// Fix issue with tests failing without CMS module
21
+		if (!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) {
22
+			unset($this->illegalExtensions['SilverStripe\\CMS\\Model\\SiteTree']);
23
+		}
24 24
 
25
-        parent::setUpOnce(); // TODO: Change the autogenerated stub
26
-    }
25
+		parent::setUpOnce(); // TODO: Change the autogenerated stub
26
+	}
27 27
 
28
-    public function testCanCreateRootPages()
29
-    {
30
-        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
28
+	public function testCanCreateRootPages()
29
+	{
30
+		$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
31 31
 
32
-        // Log in without pages admin access
33
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
34
-        $this->assertFalse($config->canCreateTopLevel());
32
+		// Log in without pages admin access
33
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
34
+		$this->assertFalse($config->canCreateTopLevel());
35 35
 
36
-        // Login with necessary edit permission
37
-        $perms = SiteConfig::config()->required_permission;
38
-        $this->logInWithPermission(reset($perms));
39
-        $this->assertTrue($config->canCreateTopLevel());
40
-    }
36
+		// Login with necessary edit permission
37
+		$perms = SiteConfig::config()->required_permission;
38
+		$this->logInWithPermission(reset($perms));
39
+		$this->assertTrue($config->canCreateTopLevel());
40
+	}
41 41
 
42
-    public function testCanViewPages()
43
-    {
44
-        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
45
-        $this->assertTrue($config->canViewPages());
46
-    }
42
+	public function testCanViewPages()
43
+	{
44
+		$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
45
+		$this->assertTrue($config->canViewPages());
46
+	}
47 47
 
48
-    public function testCanEdit()
49
-    {
50
-        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
48
+	public function testCanEdit()
49
+	{
50
+		$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
51 51
 
52
-        // Unrelated permissions don't allow siteconfig
53
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
54
-        $this->assertFalse($config->canEdit());
52
+		// Unrelated permissions don't allow siteconfig
53
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
54
+		$this->assertFalse($config->canEdit());
55 55
 
56
-        // Only those with edit permission can do this
57
-        $this->logInWithPermission('EDIT_SITECONFIG');
58
-        $this->assertTrue($config->canEdit());
59
-    }
56
+		// Only those with edit permission can do this
57
+		$this->logInWithPermission('EDIT_SITECONFIG');
58
+		$this->assertTrue($config->canEdit());
59
+	}
60 60
 
61
-    public function testCanEditPages()
62
-    {
63
-        $config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
61
+	public function testCanEditPages()
62
+	{
63
+		$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default');
64 64
 
65
-        // Log in without pages admin access
66
-        $this->logInWithPermission('CMS_ACCESS_AssetAdmin');
67
-        $this->assertFalse($config->canEditPages());
65
+		// Log in without pages admin access
66
+		$this->logInWithPermission('CMS_ACCESS_AssetAdmin');
67
+		$this->assertFalse($config->canEditPages());
68 68
 
69
-        // Login with necessary edit permission
70
-        $perms = SiteConfig::config()->required_permission;
71
-        $this->logInWithPermission(reset($perms));
72
-        $this->assertTrue($config->canEditPages());
73
-    }
69
+		// Login with necessary edit permission
70
+		$perms = SiteConfig::config()->required_permission;
71
+		$this->logInWithPermission(reset($perms));
72
+		$this->assertTrue($config->canEditPages());
73
+	}
74 74
 }
Please login to merge, or discard this patch.