Completed
Push — master ( 24a71d...4147fa )
by Robbie
9s
created
src/Forms/GridFieldExportReportButton.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
      * it sources the {@link List} from $gridField->getList() instead of $gridField->getManipulatedList()
28 28
      *
29 29
      * @param GridField $gridField
30
-     * @return array
30
+     * @return string
31 31
      */
32 32
     public function generateExportFileData($gridField)
33 33
     {
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -20,78 +20,78 @@
 block discarded – undo
20 20
 class GridFieldExportReportButton extends GridFieldExportButton
21 21
 {
22 22
 
23
-    /**
24
-     * Generate export fields for CSV.
25
-     *
26
-     * Replaces the definition in GridFieldExportButton, this is the same as original except
27
-     * it sources the {@link List} from $gridField->getList() instead of $gridField->getManipulatedList()
28
-     *
29
-     * @param GridField $gridField
30
-     * @return array
31
-     */
32
-    public function generateExportFileData($gridField)
33
-    {
34
-        $separator = $this->csvSeparator;
35
-        $csvColumns = ($this->exportColumns)
36
-            ? $this->exportColumns
37
-            : singleton($gridField->getModelClass())->summaryFields();
38
-        $fileData = '';
39
-        $columnData = array();
23
+	/**
24
+	 * Generate export fields for CSV.
25
+	 *
26
+	 * Replaces the definition in GridFieldExportButton, this is the same as original except
27
+	 * it sources the {@link List} from $gridField->getList() instead of $gridField->getManipulatedList()
28
+	 *
29
+	 * @param GridField $gridField
30
+	 * @return array
31
+	 */
32
+	public function generateExportFileData($gridField)
33
+	{
34
+		$separator = $this->csvSeparator;
35
+		$csvColumns = ($this->exportColumns)
36
+			? $this->exportColumns
37
+			: singleton($gridField->getModelClass())->summaryFields();
38
+		$fileData = '';
39
+		$columnData = array();
40 40
 
41
-        if ($this->csvHasHeader) {
42
-            $headers = array();
41
+		if ($this->csvHasHeader) {
42
+			$headers = array();
43 43
 
44
-            // determine the CSV headers. If a field is callable (e.g. anonymous function) then use the
45
-            // source name as the header instead
46
-            foreach ($csvColumns as $columnSource => $columnHeader) {
47
-                if (is_array($columnHeader) && array_key_exists('title', $columnHeader)) {
48
-                    $headers[] = $columnHeader['title'];
49
-                } else {
50
-                    $headers[] = (!is_string($columnHeader) && is_callable($columnHeader))
51
-                        ? $columnSource
52
-                        : $columnHeader;
53
-                }
54
-            }
44
+			// determine the CSV headers. If a field is callable (e.g. anonymous function) then use the
45
+			// source name as the header instead
46
+			foreach ($csvColumns as $columnSource => $columnHeader) {
47
+				if (is_array($columnHeader) && array_key_exists('title', $columnHeader)) {
48
+					$headers[] = $columnHeader['title'];
49
+				} else {
50
+					$headers[] = (!is_string($columnHeader) && is_callable($columnHeader))
51
+						? $columnSource
52
+						: $columnHeader;
53
+				}
54
+			}
55 55
 
56
-            $fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\"";
57
-            $fileData .= "\n";
58
-        }
56
+			$fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\"";
57
+			$fileData .= "\n";
58
+		}
59 59
 
60
-        // The is the only variation from the parent, using getList() instead of getManipulatedList()
61
-        $items = $gridField->getList();
60
+		// The is the only variation from the parent, using getList() instead of getManipulatedList()
61
+		$items = $gridField->getList();
62 62
 
63
-        // @todo should GridFieldComponents change behaviour based on whether others are available in the config?
64
-        foreach ($gridField->getConfig()->getComponents() as $component) {
65
-            if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) {
66
-                $items = $component->getManipulatedData($gridField, $items);
67
-            }
68
-        }
63
+		// @todo should GridFieldComponents change behaviour based on whether others are available in the config?
64
+		foreach ($gridField->getConfig()->getComponents() as $component) {
65
+			if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) {
66
+				$items = $component->getManipulatedData($gridField, $items);
67
+			}
68
+		}
69 69
 
70
-        foreach ($items->limit(null) as $item) {
71
-            $columnData = array();
70
+		foreach ($items->limit(null) as $item) {
71
+			$columnData = array();
72 72
 
73
-            foreach ($csvColumns as $columnSource => $columnHeader) {
74
-                if (!is_string($columnHeader) && is_callable($columnHeader)) {
75
-                    if ($item->hasMethod($columnSource)) {
76
-                        $relObj = $item->{$columnSource}();
77
-                    } else {
78
-                        $relObj = $item->relObject($columnSource);
79
-                    }
73
+			foreach ($csvColumns as $columnSource => $columnHeader) {
74
+				if (!is_string($columnHeader) && is_callable($columnHeader)) {
75
+					if ($item->hasMethod($columnSource)) {
76
+						$relObj = $item->{$columnSource}();
77
+					} else {
78
+						$relObj = $item->relObject($columnSource);
79
+					}
80 80
 
81
-                    $value = $columnHeader($relObj);
82
-                } else {
83
-                    $value = $gridField->getDataFieldValue($item, $columnSource);
84
-                }
81
+					$value = $columnHeader($relObj);
82
+				} else {
83
+					$value = $gridField->getDataFieldValue($item, $columnSource);
84
+				}
85 85
 
86
-                $value = str_replace(array("\r", "\n"), "\n", $value);
87
-                $columnData[] = '"' . str_replace('"', '\"', $value) . '"';
88
-            }
89
-            $fileData .= implode($separator, $columnData);
90
-            $fileData .= "\n";
86
+				$value = str_replace(array("\r", "\n"), "\n", $value);
87
+				$columnData[] = '"' . str_replace('"', '\"', $value) . '"';
88
+			}
89
+			$fileData .= implode($separator, $columnData);
90
+			$fileData .= "\n";
91 91
 
92
-            $item->destroy();
93
-        }
92
+			$item->destroy();
93
+		}
94 94
 
95
-        return $fileData;
96
-    }
95
+		return $fileData;
96
+	}
97 97
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
                 }
54 54
             }
55 55
 
56
-            $fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\"";
56
+            $fileData .= "\"".implode("\"{$separator}\"", array_values($headers))."\"";
57 57
             $fileData .= "\n";
58 58
         }
59 59
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                 }
85 85
 
86 86
                 $value = str_replace(array("\r", "\n"), "\n", $value);
87
-                $columnData[] = '"' . str_replace('"', '\"', $value) . '"';
87
+                $columnData[] = '"'.str_replace('"', '\"', $value).'"';
88 88
             }
89 89
             $fileData .= implode($separator, $columnData);
90 90
             $fileData .= "\n";
Please login to merge, or discard this patch.
src/Forms/GridFieldPrintReportButton.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -22,59 +22,59 @@
 block discarded – undo
22 22
 class GridFieldPrintReportButton extends GridFieldPrintButton
23 23
 {
24 24
 
25
-    /**
26
-     * Export core
27
-     *
28
-     * Replaces definition in GridFieldPrintButton
29
-     * same as original except sources data from $gridField->getList() instead of $gridField->getManipulatedList()
30
-     *
31
-     * @param GridField
32
-     * @return ArrayData
33
-     */
34
-    public function generatePrintData(GridField $gridField)
35
-    {
36
-        $printColumns = $this->getPrintColumnsForGridField($gridField);
37
-        $header = null;
25
+	/**
26
+	 * Export core
27
+	 *
28
+	 * Replaces definition in GridFieldPrintButton
29
+	 * same as original except sources data from $gridField->getList() instead of $gridField->getManipulatedList()
30
+	 *
31
+	 * @param GridField
32
+	 * @return ArrayData
33
+	 */
34
+	public function generatePrintData(GridField $gridField)
35
+	{
36
+		$printColumns = $this->getPrintColumnsForGridField($gridField);
37
+		$header = null;
38 38
 
39
-        if ($this->printHasHeader) {
40
-            $header = new ArrayList();
41
-            foreach ($printColumns as $field => $label) {
42
-                $header->push(new ArrayData(array(
43
-                    "CellString" => $label,
44
-                )));
45
-            }
46
-        }
39
+		if ($this->printHasHeader) {
40
+			$header = new ArrayList();
41
+			foreach ($printColumns as $field => $label) {
42
+				$header->push(new ArrayData(array(
43
+					"CellString" => $label,
44
+				)));
45
+			}
46
+		}
47 47
 
48
-        // The is the only variation from the parent class, using getList() instead of getManipulatedList()
49
-        $items = $gridField->getList();
48
+		// The is the only variation from the parent class, using getList() instead of getManipulatedList()
49
+		$items = $gridField->getList();
50 50
 
51
-        $itemRows = new ArrayList();
51
+		$itemRows = new ArrayList();
52 52
 
53
-        foreach ($items as $item) {
54
-            $itemRow = new ArrayList();
53
+		foreach ($items as $item) {
54
+			$itemRow = new ArrayList();
55 55
 
56
-            foreach ($printColumns as $field => $label) {
57
-                $value = $gridField->getDataFieldValue($item, $field);
58
-                $itemRow->push(new ArrayData(array(
59
-                    "CellString" => $value,
60
-                )));
61
-            }
56
+			foreach ($printColumns as $field => $label) {
57
+				$value = $gridField->getDataFieldValue($item, $field);
58
+				$itemRow->push(new ArrayData(array(
59
+					"CellString" => $value,
60
+				)));
61
+			}
62 62
 
63
-            $itemRows->push(new ArrayData(array(
64
-                "ItemRow" => $itemRow
65
-            )));
63
+			$itemRows->push(new ArrayData(array(
64
+				"ItemRow" => $itemRow
65
+			)));
66 66
 
67
-            $item->destroy();
68
-        }
67
+			$item->destroy();
68
+		}
69 69
 
70
-        $ret = new ArrayData(array(
71
-            "Title" => $this->getTitle($gridField),
72
-            "Header" => $header,
73
-            "ItemRows" => $itemRows,
74
-            "Datetime" => DBDatetime::now(),
75
-            "Member" => Security::getCurrentUser(),
76
-        ));
70
+		$ret = new ArrayData(array(
71
+			"Title" => $this->getTitle($gridField),
72
+			"Header" => $header,
73
+			"ItemRows" => $itemRows,
74
+			"Datetime" => DBDatetime::now(),
75
+			"Member" => Security::getCurrentUser(),
76
+		));
77 77
 
78
-        return $ret;
79
-    }
78
+		return $ret;
79
+	}
80 80
 }
Please login to merge, or discard this patch.
src/Subsites/SubsiteSecurityReport.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@
 block discarded – undo
12 12
 class SubsiteSecurityReport extends Extension
13 13
 {
14 14
 
15
-    /**
16
-     * Columns in the report
17
-     *
18
-     * @var array
19
-     * @config
20
-     */
21
-    private static $columns = array(
22
-        'SubsiteDescription' => 'Subsites (edit permissions)',
23
-    );
15
+	/**
16
+	 * Columns in the report
17
+	 *
18
+	 * @var array
19
+	 * @config
20
+	 */
21
+	private static $columns = array(
22
+		'SubsiteDescription' => 'Subsites (edit permissions)',
23
+	);
24 24
 }
Please login to merge, or discard this patch.
src/Subsites/SubsiteMemberReportExtension.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,37 +13,37 @@
 block discarded – undo
13 13
 class SubsiteMemberReportExtension extends DataExtension
14 14
 {
15 15
     
16
-    /**
17
-     * Set cast of additional field
18
-     *
19
-     * @var array
20
-     * @config
21
-     */
22
-    private static $casting = array(
23
-        'SubsiteDescription' => 'Text'
24
-    );
16
+	/**
17
+	 * Set cast of additional field
18
+	 *
19
+	 * @var array
20
+	 * @config
21
+	 */
22
+	private static $casting = array(
23
+		'SubsiteDescription' => 'Text'
24
+	);
25 25
     
26
-    /**
27
-     * Default permission to filter for
28
-     *
29
-     * @var string
30
-     * @config
31
-     */
32
-    private static $subsite_description_permission = 'SITETREE_EDIT_ALL';
26
+	/**
27
+	 * Default permission to filter for
28
+	 *
29
+	 * @var string
30
+	 * @config
31
+	 */
32
+	private static $subsite_description_permission = 'SITETREE_EDIT_ALL';
33 33
     
34
-    /**
35
-     * Describes the subsites this user has SITETREE_EDIT_ALL access to
36
-     *
37
-     * @return string
38
-     */
39
-    public function getSubsiteDescription()
40
-    {
41
-        $subsites = Subsite::accessible_sites(
42
-            $this->owner->config()->get('subsite_description_permission'),
43
-            true,
44
-            "Main site",
45
-            $this->owner
46
-        );
47
-        return implode(', ', $subsites->column('Title'));
48
-    }
34
+	/**
35
+	 * Describes the subsites this user has SITETREE_EDIT_ALL access to
36
+	 *
37
+	 * @return string
38
+	 */
39
+	public function getSubsiteDescription()
40
+	{
41
+		$subsites = Subsite::accessible_sites(
42
+			$this->owner->config()->get('subsite_description_permission'),
43
+			true,
44
+			"Main site",
45
+			$this->owner
46
+		);
47
+		return implode(', ', $subsites->column('Title'));
48
+	}
49 49
 }
Please login to merge, or discard this patch.
src/UserSecurityReport.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function title()
48 48
     {
49
-        return _t(__CLASS__ . '.REPORTTITLE', 'Users, Groups and Permissions');
49
+        return _t(__CLASS__.'.REPORTTITLE', 'Users, Groups and Permissions');
50 50
     }
51 51
 
52 52
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         return str_replace(
60 60
             array('http', 'https', '://'),
61 61
             '',
62
-            Director::protocolAndHost() . ' - ' . date('d/m/Y H:i:s')
62
+            Director::protocolAndHost().' - '.date('d/m/Y H:i:s')
63 63
         );
64 64
     }
65 65
 
Please login to merge, or discard this patch.
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -22,130 +22,130 @@
 block discarded – undo
22 22
 class UserSecurityReport extends Report
23 23
 {
24 24
 
25
-    /**
26
-     * Columns in the report
27
-     *
28
-     * @var array
29
-     * @config
30
-     */
31
-    private static $columns = array(
32
-        'ID' => 'User ID',
33
-        'FirstName' => 'First Name',
34
-        'Surname' => 'Surname',
35
-        'Email' => 'Email',
36
-        'Created' => 'Date Created',
37
-        'LastLoggedIn' => 'Last Logged In',
38
-        'GroupsDescription' => 'Groups',
39
-        'PermissionsDescription' => 'Permissions',
40
-    );
25
+	/**
26
+	 * Columns in the report
27
+	 *
28
+	 * @var array
29
+	 * @config
30
+	 */
31
+	private static $columns = array(
32
+		'ID' => 'User ID',
33
+		'FirstName' => 'First Name',
34
+		'Surname' => 'Surname',
35
+		'Email' => 'Email',
36
+		'Created' => 'Date Created',
37
+		'LastLoggedIn' => 'Last Logged In',
38
+		'GroupsDescription' => 'Groups',
39
+		'PermissionsDescription' => 'Permissions',
40
+	);
41 41
     
42
-    protected $dataClass = Member::class;
42
+	protected $dataClass = Member::class;
43 43
 
44
-    /**
45
-     * Returns the report title
46
-     *
47
-     * @return string
48
-     */
49
-    public function title()
50
-    {
51
-        return _t(__CLASS__ . '.REPORTTITLE', 'Users, Groups and Permissions');
52
-    }
44
+	/**
45
+	 * Returns the report title
46
+	 *
47
+	 * @return string
48
+	 */
49
+	public function title()
50
+	{
51
+		return _t(__CLASS__ . '.REPORTTITLE', 'Users, Groups and Permissions');
52
+	}
53 53
 
54
-    /**
55
-     * Builds a report description which is the current hostname with the current date and time
56
-     *
57
-     * @return string e.g. localhost/sitename - 21/12/2112
58
-     */
59
-    public function description()
60
-    {
61
-        return str_replace(
62
-            array('http', 'https', '://'),
63
-            '',
64
-            Director::protocolAndHost() . ' - ' . date('d/m/Y H:i:s')
65
-        );
66
-    }
54
+	/**
55
+	 * Builds a report description which is the current hostname with the current date and time
56
+	 *
57
+	 * @return string e.g. localhost/sitename - 21/12/2112
58
+	 */
59
+	public function description()
60
+	{
61
+		return str_replace(
62
+			array('http', 'https', '://'),
63
+			'',
64
+			Director::protocolAndHost() . ' - ' . date('d/m/Y H:i:s')
65
+		);
66
+	}
67 67
 
68
-    /**
69
-     * Returns the column names of the report
70
-     *
71
-     * @return array
72
-     */
73
-    public function columns()
74
-    {
75
-        $columns = self::config()->columns;
76
-        if (!Security::config()->get('login_recording')) {
77
-            unset($columns['LastLoggedIn']);
78
-        }
79
-        return $columns;
80
-    }
68
+	/**
69
+	 * Returns the column names of the report
70
+	 *
71
+	 * @return array
72
+	 */
73
+	public function columns()
74
+	{
75
+		$columns = self::config()->columns;
76
+		if (!Security::config()->get('login_recording')) {
77
+			unset($columns['LastLoggedIn']);
78
+		}
79
+		return $columns;
80
+	}
81 81
 
82
-    /**
83
-     * Alias of columns(), to support the export to csv action
84
-     * in {@link GridFieldExportButton} generateExportFileData method.
85
-     * @return array
86
-     */
87
-    public function getColumns()
88
-    {
89
-        return $this->columns();
90
-    }
82
+	/**
83
+	 * Alias of columns(), to support the export to csv action
84
+	 * in {@link GridFieldExportButton} generateExportFileData method.
85
+	 * @return array
86
+	 */
87
+	public function getColumns()
88
+	{
89
+		return $this->columns();
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    public function summaryFields()
96
-    {
97
-        return $this->columns();
98
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	public function summaryFields()
96
+	{
97
+		return $this->columns();
98
+	}
99 99
 
100
-    /**
101
-     * Defines the sortable columns on the report gridfield
102
-     *
103
-     * @return array
104
-     */
105
-    public function sortColumns()
106
-    {
107
-        return array_keys($this->columns());
108
-    }
100
+	/**
101
+	 * Defines the sortable columns on the report gridfield
102
+	 *
103
+	 * @return array
104
+	 */
105
+	public function sortColumns()
106
+	{
107
+		return array_keys($this->columns());
108
+	}
109 109
 
110
-    /**
111
-     * Get the source records for the report gridfield
112
-     *
113
-     * @return DataList
114
-     */
115
-    public function sourceRecords()
116
-    {
117
-        // Get members sorted by ID
118
-        return Member::get()->sort('ID');
119
-    }
110
+	/**
111
+	 * Get the source records for the report gridfield
112
+	 *
113
+	 * @return DataList
114
+	 */
115
+	public function sourceRecords()
116
+	{
117
+		// Get members sorted by ID
118
+		return Member::get()->sort('ID');
119
+	}
120 120
 
121
-    /**
122
-     * Restrict access to this report to users with security admin access
123
-     *
124
-     * @param Member $member
125
-     * @return boolean
126
-     */
127
-    public function canView($member = null)
128
-    {
129
-        return (bool)Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin");
130
-    }
121
+	/**
122
+	 * Restrict access to this report to users with security admin access
123
+	 *
124
+	 * @param Member $member
125
+	 * @return boolean
126
+	 */
127
+	public function canView($member = null)
128
+	{
129
+		return (bool)Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin");
130
+	}
131 131
 
132
-    /**
133
-     * Return a field, such as a {@link GridField} that is
134
-     * used to show and manipulate data relating to this report.
135
-     *
136
-     * @return FormField subclass
137
-     */
138
-    public function getReportField()
139
-    {
140
-        /** @var GridField $gridField */
141
-        $gridField = parent::getReportField();
142
-        $gridField->setModelClass(self::class);
143
-        $gridConfig = $gridField->getConfig();
144
-        $gridConfig->removeComponentsByType([GridFieldPrintButton::class, GridFieldExportButton::class]);
145
-        $gridConfig->addComponents(
146
-            new GridFieldPrintReportButton('buttons-before-left'),
147
-            new GridFieldExportReportButton('buttons-before-left')
148
-        );
149
-        return $gridField;
150
-    }
132
+	/**
133
+	 * Return a field, such as a {@link GridField} that is
134
+	 * used to show and manipulate data relating to this report.
135
+	 *
136
+	 * @return FormField subclass
137
+	 */
138
+	public function getReportField()
139
+	{
140
+		/** @var GridField $gridField */
141
+		$gridField = parent::getReportField();
142
+		$gridField->setModelClass(self::class);
143
+		$gridConfig = $gridField->getConfig();
144
+		$gridConfig->removeComponentsByType([GridFieldPrintButton::class, GridFieldExportButton::class]);
145
+		$gridConfig->addComponents(
146
+			new GridFieldPrintReportButton('buttons-before-left'),
147
+			new GridFieldExportReportButton('buttons-before-left')
148
+		);
149
+		return $gridField;
150
+	}
151 151
 }
Please login to merge, or discard this patch.
tests/SubsitesReportTest.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -18,67 +18,67 @@
 block discarded – undo
18 18
 class SubsitesReportTest extends SapphireTest
19 19
 {
20 20
 
21
-    protected static $fixture_file = 'SubsitesReportTest.yml';
21
+	protected static $fixture_file = 'SubsitesReportTest.yml';
22 22
 
23
-    protected $records;
23
+	protected $records;
24 24
 
25
-    protected static $required_extensions = [
26
-        Member::class => [
27
-            MemberReportExtension::class,
28
-            SubsiteMemberReportExtension::class,
29
-        ],
30
-    ];
25
+	protected static $required_extensions = [
26
+		Member::class => [
27
+			MemberReportExtension::class,
28
+			SubsiteMemberReportExtension::class,
29
+		],
30
+	];
31 31
 
32
-    protected function setUp()
33
-    {
34
-        if (!class_exists(Subsite::class)) {
35
-            // Don't break the parent:setUp() when failing to create Subsite fixtures
36
-            static::$fixture_file = null;
37
-            parent::setUp();
38
-            $this->markTestSkipped("Please install Subsites to run this test");
39
-        }
32
+	protected function setUp()
33
+	{
34
+		if (!class_exists(Subsite::class)) {
35
+			// Don't break the parent:setUp() when failing to create Subsite fixtures
36
+			static::$fixture_file = null;
37
+			parent::setUp();
38
+			$this->markTestSkipped("Please install Subsites to run this test");
39
+		}
40 40
 
41
-        parent::setUp();
41
+		parent::setUp();
42 42
 
43
-        $reports = Report::get_reports();
44
-        $report = $reports[UserSecurityReport::class];
45
-        $this->records = $report->sourceRecords()->toArray();
46
-    }
43
+		$reports = Report::get_reports();
44
+		$report = $reports[UserSecurityReport::class];
45
+		$this->records = $report->sourceRecords()->toArray();
46
+	}
47 47
 
48
-    public function testSourceRecords()
49
-    {
50
-        $this->assertNotEmpty($this->records);
51
-    }
48
+	public function testSourceRecords()
49
+	{
50
+		$this->assertNotEmpty($this->records);
51
+	}
52 52
 
53
-    public function testGetMemberGroups()
54
-    {
53
+	public function testGetMemberGroups()
54
+	{
55 55
 
56
-        // Admin
57
-        $admin = $this->objFromFixture(Member::class, 'memberadmin');
58
-        $subsites = $admin->SubsiteDescription;
59
-        $this->assertContains('TestMainSite', $subsites);
60
-        $this->assertContains('TestSubsite1', $subsites);
61
-        $this->assertContains('TestSubsite2', $subsites);
56
+		// Admin
57
+		$admin = $this->objFromFixture(Member::class, 'memberadmin');
58
+		$subsites = $admin->SubsiteDescription;
59
+		$this->assertContains('TestMainSite', $subsites);
60
+		$this->assertContains('TestSubsite1', $subsites);
61
+		$this->assertContains('TestSubsite2', $subsites);
62 62
 
63
-        // Editor
64
-        $membereditor = $this->objFromFixture(Member::class, 'membereditor');
65
-        $subsites = $membereditor->SubsiteDescription;
66
-        $this->assertContains('TestMainSite', $subsites);
67
-        $this->assertContains('TestSubsite1', $subsites);
68
-        $this->assertContains('TestSubsite2', $subsites);
63
+		// Editor
64
+		$membereditor = $this->objFromFixture(Member::class, 'membereditor');
65
+		$subsites = $membereditor->SubsiteDescription;
66
+		$this->assertContains('TestMainSite', $subsites);
67
+		$this->assertContains('TestSubsite1', $subsites);
68
+		$this->assertContains('TestSubsite2', $subsites);
69 69
 
70
-        // First User
71
-        $membersubsite1 = $this->objFromFixture(Member::class, 'membersubsite1');
72
-        $subsites = $membersubsite1->SubsiteDescription;
73
-        $this->assertNotContains('TestMainSite', $subsites);
74
-        $this->assertContains('TestSubsite1', $subsites);
75
-        $this->assertNotContains('TestSubsite2', $subsites);
70
+		// First User
71
+		$membersubsite1 = $this->objFromFixture(Member::class, 'membersubsite1');
72
+		$subsites = $membersubsite1->SubsiteDescription;
73
+		$this->assertNotContains('TestMainSite', $subsites);
74
+		$this->assertContains('TestSubsite1', $subsites);
75
+		$this->assertNotContains('TestSubsite2', $subsites);
76 76
 
77
-        // Second user
78
-        $memberallsubsites = $this->objFromFixture(Member::class, 'memberallsubsites');
79
-        $subsites = $memberallsubsites->SubsiteDescription;
80
-        $this->assertNotContains('TestMainSite', $subsites);
81
-        $this->assertContains('TestSubsite1', $subsites);
82
-        $this->assertContains('TestSubsite2', $subsites);
83
-    }
77
+		// Second user
78
+		$memberallsubsites = $this->objFromFixture(Member::class, 'memberallsubsites');
79
+		$subsites = $memberallsubsites->SubsiteDescription;
80
+		$this->assertNotContains('TestMainSite', $subsites);
81
+		$this->assertContains('TestSubsite1', $subsites);
82
+		$this->assertContains('TestSubsite2', $subsites);
83
+	}
84 84
 }
Please login to merge, or discard this patch.
tests/UserSecurityReportTest.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,80 +20,80 @@
 block discarded – undo
20 20
 class UserSecurityReportTest extends SapphireTest
21 21
 {
22 22
 
23
-    protected static $fixture_file = 'UserSecurityReportTest.yml';
24
-
25
-    protected $records;
26
-    protected $report;
27
-
28
-    protected static $required_extensions = [
29
-        Member::class => [
30
-            MemberReportExtension::class,
31
-        ],
32
-    ];
33
-
34
-    protected static $illegal_extensions = [
35
-        Group::class => [
36
-            GroupSubsites::class,
37
-        ],
38
-    ];
39
-
40
-    /**
41
-     * Utility method for all tests to use.
42
-     *
43
-     * @return \ArrayList
44
-     * @todo pre-fill the report with fixture-defined users
45
-     */
46
-    protected function setUp()
47
-    {
48
-        parent::setUp();
49
-        $reports = Report::get_reports();
50
-        $report = $reports[UserSecurityReport::class];
51
-        $this->report = $report;
52
-        $this->records = $report->sourceRecords()->toArray();
53
-    }
54
-
55
-    public function testSourceRecords()
56
-    {
57
-        $this->assertNotEmpty($this->records);
58
-    }
59
-
60
-    public function testGetMemberGroups()
61
-    {
62
-        //getMemberGroups(&$member) returns string
63
-        $member = $this->objFromFixture(Member::class, 'member-has-0-groups');
64
-        $groups = $member->GroupsDescription;
65
-        $this->assertEquals('Not in a Security Group', $groups);
66
-
67
-        $member = $this->objFromFixture(Member::class, 'member-has-1-groups');
68
-        $groups = $member->GroupsDescription;
69
-        $this->assertEquals('Group Test 01', $groups);
70
-    }
71
-
72
-    public function testGetMemberPermissions()
73
-    {
74
-        $member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
75
-        $perms = $member->PermissionsDescription;
76
-        $this->assertEquals('No Permissions', $perms);
77
-
78
-        $member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
79
-        $perms = $member->PermissionsDescription;
80
-        $this->assertEquals('Full administrative rights', $perms);
81
-
82
-        $member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
83
-        $perms = $member->PermissionsDescription;
84
-        $this->assertEquals('Full administrative rights, Edit any page', $perms);
85
-    }
86
-
87
-    public function testLoginLoggingColumnShowsOnlyWhenApplicable()
88
-    {
89
-        $original = Config::inst()->get(Security::class, 'login_recording');
90
-
91
-        Config::modify()->set(Security::class, 'login_recording', true);
92
-        $this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
93
-
94
-        Config::modify()->set(Security::class, 'login_recording', false);
95
-        $this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
96
-
97
-        Config::modify()->set(Security::class, 'login_recording', $original);
98
-    }
23
+	protected static $fixture_file = 'UserSecurityReportTest.yml';
24
+
25
+	protected $records;
26
+	protected $report;
27
+
28
+	protected static $required_extensions = [
29
+		Member::class => [
30
+			MemberReportExtension::class,
31
+		],
32
+	];
33
+
34
+	protected static $illegal_extensions = [
35
+		Group::class => [
36
+			GroupSubsites::class,
37
+		],
38
+	];
39
+
40
+	/**
41
+	 * Utility method for all tests to use.
42
+	 *
43
+	 * @return \ArrayList
44
+	 * @todo pre-fill the report with fixture-defined users
45
+	 */
46
+	protected function setUp()
47
+	{
48
+		parent::setUp();
49
+		$reports = Report::get_reports();
50
+		$report = $reports[UserSecurityReport::class];
51
+		$this->report = $report;
52
+		$this->records = $report->sourceRecords()->toArray();
53
+	}
54
+
55
+	public function testSourceRecords()
56
+	{
57
+		$this->assertNotEmpty($this->records);
58
+	}
59
+
60
+	public function testGetMemberGroups()
61
+	{
62
+		//getMemberGroups(&$member) returns string
63
+		$member = $this->objFromFixture(Member::class, 'member-has-0-groups');
64
+		$groups = $member->GroupsDescription;
65
+		$this->assertEquals('Not in a Security Group', $groups);
66
+
67
+		$member = $this->objFromFixture(Member::class, 'member-has-1-groups');
68
+		$groups = $member->GroupsDescription;
69
+		$this->assertEquals('Group Test 01', $groups);
70
+	}
71
+
72
+	public function testGetMemberPermissions()
73
+	{
74
+		$member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
75
+		$perms = $member->PermissionsDescription;
76
+		$this->assertEquals('No Permissions', $perms);
77
+
78
+		$member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
79
+		$perms = $member->PermissionsDescription;
80
+		$this->assertEquals('Full administrative rights', $perms);
81
+
82
+		$member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
83
+		$perms = $member->PermissionsDescription;
84
+		$this->assertEquals('Full administrative rights, Edit any page', $perms);
85
+	}
86
+
87
+	public function testLoginLoggingColumnShowsOnlyWhenApplicable()
88
+	{
89
+		$original = Config::inst()->get(Security::class, 'login_recording');
90
+
91
+		Config::modify()->set(Security::class, 'login_recording', true);
92
+		$this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
93
+
94
+		Config::modify()->set(Security::class, 'login_recording', false);
95
+		$this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
96
+
97
+		Config::modify()->set(Security::class, 'login_recording', $original);
98
+	}
99 99
 }
Please login to merge, or discard this patch.
src/MemberReportExtension.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -13,113 +13,113 @@
 block discarded – undo
13 13
 class MemberReportExtension extends DataExtension
14 14
 {
15 15
 
16
-    /**
17
-     * Connect the link to LoginAttempt.
18
-     * This relationship is always defined (whether enabled or not),
19
-     * although only normally accessible from the `LoginAttempt` side.
20
-     * This is adding the reflection, as that it is also accessible
21
-     * from the `Member` side.
22
-     *
23
-     * @var array
24
-     * @config
25
-     */
26
-    private static $has_many = [
27
-        'LoginAttempts' => LoginAttempt::class
28
-    ];
16
+	/**
17
+	 * Connect the link to LoginAttempt.
18
+	 * This relationship is always defined (whether enabled or not),
19
+	 * although only normally accessible from the `LoginAttempt` side.
20
+	 * This is adding the reflection, as that it is also accessible
21
+	 * from the `Member` side.
22
+	 *
23
+	 * @var array
24
+	 * @config
25
+	 */
26
+	private static $has_many = [
27
+		'LoginAttempts' => LoginAttempt::class
28
+	];
29 29
     
30
-    /**
31
-     * Set cast of additional fields
32
-     *
33
-     * @var array
34
-     * @config
35
-     */
36
-    private static $casting = array(
37
-        'GroupsDescription' => 'Text',
38
-        'PermissionsDescription' => 'Text'
39
-    );
30
+	/**
31
+	 * Set cast of additional fields
32
+	 *
33
+	 * @var array
34
+	 * @config
35
+	 */
36
+	private static $casting = array(
37
+		'GroupsDescription' => 'Text',
38
+		'PermissionsDescription' => 'Text'
39
+	);
40 40
 
41
-    /**
42
-     * Retrieves the most recent successful LoginAttempt
43
-     *
44
-     * @return DBDatetime|string
45
-     */
46
-    public function getLastLoggedIn()
47
-    {
48
-        $lastTime = $this->owner->LoginAttempts()
49
-            ->filter('Status', 'Success')
50
-            ->sort('Created', 'DESC')
51
-            ->first();
41
+	/**
42
+	 * Retrieves the most recent successful LoginAttempt
43
+	 *
44
+	 * @return DBDatetime|string
45
+	 */
46
+	public function getLastLoggedIn()
47
+	{
48
+		$lastTime = $this->owner->LoginAttempts()
49
+			->filter('Status', 'Success')
50
+			->sort('Created', 'DESC')
51
+			->first();
52 52
 
53
-        return $lastTime ? $lastTime->dbObject('Created') : _t(__CLASS__ . '.NEVER', 'Never');
54
-    }
53
+		return $lastTime ? $lastTime->dbObject('Created') : _t(__CLASS__ . '.NEVER', 'Never');
54
+	}
55 55
 
56
-    /**
57
-     * Builds a comma separated list of member group names for a given Member.
58
-     *
59
-     * @return string
60
-     */
61
-    public function getGroupsDescription()
62
-    {
63
-        if (class_exists(Subsite::class)) {
64
-            Subsite::disable_subsite_filter(true);
65
-        }
56
+	/**
57
+	 * Builds a comma separated list of member group names for a given Member.
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public function getGroupsDescription()
62
+	{
63
+		if (class_exists(Subsite::class)) {
64
+			Subsite::disable_subsite_filter(true);
65
+		}
66 66
         
67
-        // Get the member's groups, if any
68
-        $groups = $this->owner->Groups();
69
-        if ($groups->Count()) {
70
-            // Collect the group names
71
-            $groupNames = array();
72
-            foreach ($groups as $group) {
73
-                $groupNames[] = html_entity_decode($group->getTreeTitle());
74
-            }
75
-            // return a csv string of the group names, sans-markup
76
-            $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
77
-        } else {
78
-            // If no groups then return a status label
79
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
80
-        }
67
+		// Get the member's groups, if any
68
+		$groups = $this->owner->Groups();
69
+		if ($groups->Count()) {
70
+			// Collect the group names
71
+			$groupNames = array();
72
+			foreach ($groups as $group) {
73
+				$groupNames[] = html_entity_decode($group->getTreeTitle());
74
+			}
75
+			// return a csv string of the group names, sans-markup
76
+			$result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
77
+		} else {
78
+			// If no groups then return a status label
79
+			$result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
80
+		}
81 81
         
82
-        if (class_exists(Subsite::class)) {
83
-            Subsite::disable_subsite_filter(false);
84
-        }
85
-        return $result;
86
-    }
82
+		if (class_exists(Subsite::class)) {
83
+			Subsite::disable_subsite_filter(false);
84
+		}
85
+		return $result;
86
+	}
87 87
     
88
-    /**
89
-     * Builds a comma separated list of human-readbale permissions for a given Member.
90
-     *
91
-     * @return string
92
-     */
93
-    public function getPermissionsDescription()
94
-    {
95
-        if (class_exists(Subsite::class)) {
96
-            Subsite::disable_subsite_filter(true);
97
-        }
88
+	/**
89
+	 * Builds a comma separated list of human-readbale permissions for a given Member.
90
+	 *
91
+	 * @return string
92
+	 */
93
+	public function getPermissionsDescription()
94
+	{
95
+		if (class_exists(Subsite::class)) {
96
+			Subsite::disable_subsite_filter(true);
97
+		}
98 98
         
99
-        $permissionsUsr = Permission::permissions_for_member($this->owner->ID);
100
-        $permissionsSrc = Permission::get_codes(true);
101
-        sort($permissionsUsr);
99
+		$permissionsUsr = Permission::permissions_for_member($this->owner->ID);
100
+		$permissionsSrc = Permission::get_codes(true);
101
+		sort($permissionsUsr);
102 102
         
103
-        $permissionNames = array();
104
-        foreach ($permissionsUsr as $code) {
105
-            $code = strtoupper($code);
106
-            foreach ($permissionsSrc as $k => $v) {
107
-                if (isset($v[$code])) {
108
-                    $name = empty($v[$code]['name'])
109
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
110
-                        : $v[$code]['name'];
111
-                    $permissionNames[] = $name;
112
-                }
113
-            }
114
-        }
103
+		$permissionNames = array();
104
+		foreach ($permissionsUsr as $code) {
105
+			$code = strtoupper($code);
106
+			foreach ($permissionsSrc as $k => $v) {
107
+				if (isset($v[$code])) {
108
+					$name = empty($v[$code]['name'])
109
+						? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
110
+						: $v[$code]['name'];
111
+					$permissionNames[] = $name;
112
+				}
113
+			}
114
+		}
115 115
 
116
-        $result = $permissionNames
117
-            ? implode(', ', $permissionNames)
118
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
116
+		$result = $permissionNames
117
+			? implode(', ', $permissionNames)
118
+			: _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
119 119
         
120
-        if (class_exists(Subsite::class)) {
121
-            Subsite::disable_subsite_filter(false);
122
-        }
123
-        return $result;
124
-    }
120
+		if (class_exists(Subsite::class)) {
121
+			Subsite::disable_subsite_filter(false);
122
+		}
123
+		return $result;
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
             ->sort('Created', 'DESC')
51 51
             ->first();
52 52
 
53
-        return $lastTime ? $lastTime->dbObject('Created') : _t(__CLASS__ . '.NEVER', 'Never');
53
+        return $lastTime ? $lastTime->dbObject('Created') : _t(__CLASS__.'.NEVER', 'Never');
54 54
     }
55 55
 
56 56
     /**
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
77 77
         } else {
78 78
             // If no groups then return a status label
79
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
79
+            $result = _t(__CLASS__.'.NOGROUPS', 'Not in a Security Group');
80 80
         }
81 81
         
82 82
         if (class_exists(Subsite::class)) {
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             foreach ($permissionsSrc as $k => $v) {
107 107
                 if (isset($v[$code])) {
108 108
                     $name = empty($v[$code]['name'])
109
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
109
+                        ? _t(__CLASS__.'.UNKNOWN', 'Unknown')
110 110
                         : $v[$code]['name'];
111 111
                     $permissionNames[] = $name;
112 112
                 }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
         $result = $permissionNames
117 117
             ? implode(', ', $permissionNames)
118
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
118
+            : _t(__CLASS__.'.NOPERMISSIONS', 'No Permissions');
119 119
         
120 120
         if (class_exists(Subsite::class)) {
121 121
             Subsite::disable_subsite_filter(false);
Please login to merge, or discard this patch.