Completed
Push — master ( 64a1fe...12e93c )
by
unknown
02:37 queued 01:20
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/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
@@ -21,80 +21,80 @@
 block discarded – undo
21 21
 class UserSecurityReportTest extends SapphireTest
22 22
 {
23 23
 
24
-    protected static $fixture_file = 'UserSecurityReportTest.yml';
25
-
26
-    protected $records;
27
-    protected $report;
28
-
29
-    protected static $required_extensions = [
30
-        Member::class => [
31
-            MemberReportExtension::class,
32
-        ],
33
-    ];
34
-
35
-    protected static $illegal_extensions = [
36
-        Group::class => [
37
-            GroupSubsites::class,
38
-        ],
39
-    ];
40
-
41
-    /**
42
-     * Utility method for all tests to use.
43
-     *
44
-     * @return ArrayList
45
-     * @todo pre-fill the report with fixture-defined users
46
-     */
47
-    protected function setUp()
48
-    {
49
-        parent::setUp();
50
-        $reports = Report::get_reports();
51
-        $report = $reports[UserSecurityReport::class];
52
-        $this->report = $report;
53
-        $this->records = $report->sourceRecords()->toArray();
54
-    }
55
-
56
-    public function testSourceRecords()
57
-    {
58
-        $this->assertNotEmpty($this->records);
59
-    }
60
-
61
-    public function testGetMemberGroups()
62
-    {
63
-        //getMemberGroups(&$member) returns string
64
-        $member = $this->objFromFixture(Member::class, 'member-has-0-groups');
65
-        $groups = $member->GroupsDescription;
66
-        $this->assertEquals('Not in a Security Group', $groups);
67
-
68
-        $member = $this->objFromFixture(Member::class, 'member-has-1-groups');
69
-        $groups = $member->GroupsDescription;
70
-        $this->assertEquals('Group Test 01', $groups);
71
-    }
72
-
73
-    public function testGetMemberPermissions()
74
-    {
75
-        $member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
76
-        $perms = $member->PermissionsDescription;
77
-        $this->assertEquals('No Permissions', $perms);
78
-
79
-        $member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
80
-        $perms = $member->PermissionsDescription;
81
-        $this->assertEquals('Full administrative rights', $perms);
82
-
83
-        $member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
84
-        $perms = $member->PermissionsDescription;
85
-        $this->assertEquals('Full administrative rights, Edit any page', $perms);
86
-    }
87
-
88
-    public function testLoginLoggingColumnShowsOnlyWhenApplicable()
89
-    {
90
-        $original = Config::inst()->get(Security::class, 'login_recording');
91
-
92
-        Config::modify()->set(Security::class, 'login_recording', true);
93
-        $this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
94
-
95
-        Config::modify()->set(Security::class, 'login_recording', false);
96
-        $this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
97
-
98
-        Config::modify()->set(Security::class, 'login_recording', $original);
99
-    }
24
+	protected static $fixture_file = 'UserSecurityReportTest.yml';
25
+
26
+	protected $records;
27
+	protected $report;
28
+
29
+	protected static $required_extensions = [
30
+		Member::class => [
31
+			MemberReportExtension::class,
32
+		],
33
+	];
34
+
35
+	protected static $illegal_extensions = [
36
+		Group::class => [
37
+			GroupSubsites::class,
38
+		],
39
+	];
40
+
41
+	/**
42
+	 * Utility method for all tests to use.
43
+	 *
44
+	 * @return ArrayList
45
+	 * @todo pre-fill the report with fixture-defined users
46
+	 */
47
+	protected function setUp()
48
+	{
49
+		parent::setUp();
50
+		$reports = Report::get_reports();
51
+		$report = $reports[UserSecurityReport::class];
52
+		$this->report = $report;
53
+		$this->records = $report->sourceRecords()->toArray();
54
+	}
55
+
56
+	public function testSourceRecords()
57
+	{
58
+		$this->assertNotEmpty($this->records);
59
+	}
60
+
61
+	public function testGetMemberGroups()
62
+	{
63
+		//getMemberGroups(&$member) returns string
64
+		$member = $this->objFromFixture(Member::class, 'member-has-0-groups');
65
+		$groups = $member->GroupsDescription;
66
+		$this->assertEquals('Not in a Security Group', $groups);
67
+
68
+		$member = $this->objFromFixture(Member::class, 'member-has-1-groups');
69
+		$groups = $member->GroupsDescription;
70
+		$this->assertEquals('Group Test 01', $groups);
71
+	}
72
+
73
+	public function testGetMemberPermissions()
74
+	{
75
+		$member = $this->objFromFixture(Member::class, 'member-has-0-permissions');
76
+		$perms = $member->PermissionsDescription;
77
+		$this->assertEquals('No Permissions', $perms);
78
+
79
+		$member = $this->objFromFixture(Member::class, 'member-has-1-permissions');
80
+		$perms = $member->PermissionsDescription;
81
+		$this->assertEquals('Full administrative rights', $perms);
82
+
83
+		$member = $this->objFromFixture(Member::class, 'member-has-n-permissions');
84
+		$perms = $member->PermissionsDescription;
85
+		$this->assertEquals('Full administrative rights, Edit any page', $perms);
86
+	}
87
+
88
+	public function testLoginLoggingColumnShowsOnlyWhenApplicable()
89
+	{
90
+		$original = Config::inst()->get(Security::class, 'login_recording');
91
+
92
+		Config::modify()->set(Security::class, 'login_recording', true);
93
+		$this->assertContains('LastLoggedIn', array_keys($this->report->columns()));
94
+
95
+		Config::modify()->set(Security::class, 'login_recording', false);
96
+		$this->assertNotContains('LastLoggedIn', array_keys($this->report->columns()));
97
+
98
+		Config::modify()->set(Security::class, 'login_recording', $original);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
src/MemberReportExtension.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -14,106 +14,106 @@
 block discarded – undo
14 14
  */
15 15
 class MemberReportExtension extends DataExtension
16 16
 {
17
-    /**
18
-     * Set cast of additional fields
19
-     *
20
-     * @var array
21
-     * @config
22
-     */
23
-    private static $casting = array(
24
-        'GroupsDescription' => 'Text',
25
-        'PermissionsDescription' => 'Text'
26
-    );
17
+	/**
18
+	 * Set cast of additional fields
19
+	 *
20
+	 * @var array
21
+	 * @config
22
+	 */
23
+	private static $casting = array(
24
+		'GroupsDescription' => 'Text',
25
+		'PermissionsDescription' => 'Text'
26
+	);
27 27
 
28
-    /**
29
-     * Retrieves the most recent successful LoginAttempt
30
-     *
31
-     * @return DBDatetime|string
32
-     */
33
-    public function getLastLoggedIn()
34
-    {
35
-        $lastTime = LoginAttempt::get()
36
-            ->filter([
37
-                'MemberID' => $this->owner->ID,
38
-                'Status' => 'Success',
39
-            ])
40
-            ->sort('Created', 'DESC')
41
-            ->first();
28
+	/**
29
+	 * Retrieves the most recent successful LoginAttempt
30
+	 *
31
+	 * @return DBDatetime|string
32
+	 */
33
+	public function getLastLoggedIn()
34
+	{
35
+		$lastTime = LoginAttempt::get()
36
+			->filter([
37
+				'MemberID' => $this->owner->ID,
38
+				'Status' => 'Success',
39
+			])
40
+			->sort('Created', 'DESC')
41
+			->first();
42 42
 
43
-        if ($lastTime) {
44
-            return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45
-        }
46
-        return _t(__CLASS__ . '.NEVER', 'Never');
47
-    }
43
+		if ($lastTime) {
44
+			return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45
+		}
46
+		return _t(__CLASS__ . '.NEVER', 'Never');
47
+	}
48 48
 
49
-    /**
50
-     * Builds a comma separated list of member group names for a given Member.
51
-     *
52
-     * @return string
53
-     */
54
-    public function getGroupsDescription()
55
-    {
56
-        if (class_exists(Subsite::class)) {
57
-            Subsite::disable_subsite_filter(true);
58
-        }
49
+	/**
50
+	 * Builds a comma separated list of member group names for a given Member.
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public function getGroupsDescription()
55
+	{
56
+		if (class_exists(Subsite::class)) {
57
+			Subsite::disable_subsite_filter(true);
58
+		}
59 59
 
60
-        // Get the member's groups, if any
61
-        $groups = $this->owner->Groups();
62
-        if ($groups->Count()) {
63
-            // Collect the group names
64
-            $groupNames = array();
65
-            foreach ($groups as $group) {
66
-                /** @var Group $group */
67
-                $groupNames[] = html_entity_decode($group->getTreeTitle());
68
-            }
69
-            // return a csv string of the group names, sans-markup
70
-            $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71
-        } else {
72
-            // If no groups then return a status label
73
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
74
-        }
60
+		// Get the member's groups, if any
61
+		$groups = $this->owner->Groups();
62
+		if ($groups->Count()) {
63
+			// Collect the group names
64
+			$groupNames = array();
65
+			foreach ($groups as $group) {
66
+				/** @var Group $group */
67
+				$groupNames[] = html_entity_decode($group->getTreeTitle());
68
+			}
69
+			// return a csv string of the group names, sans-markup
70
+			$result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71
+		} else {
72
+			// If no groups then return a status label
73
+			$result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
74
+		}
75 75
 
76
-        if (class_exists(Subsite::class)) {
77
-            Subsite::disable_subsite_filter(false);
78
-        }
79
-        return $result;
80
-    }
76
+		if (class_exists(Subsite::class)) {
77
+			Subsite::disable_subsite_filter(false);
78
+		}
79
+		return $result;
80
+	}
81 81
 
82
-    /**
83
-     * Builds a comma separated list of human-readbale permissions for a given Member.
84
-     *
85
-     * @return string
86
-     */
87
-    public function getPermissionsDescription()
88
-    {
89
-        if (class_exists(Subsite::class)) {
90
-            Subsite::disable_subsite_filter(true);
91
-        }
82
+	/**
83
+	 * Builds a comma separated list of human-readbale permissions for a given Member.
84
+	 *
85
+	 * @return string
86
+	 */
87
+	public function getPermissionsDescription()
88
+	{
89
+		if (class_exists(Subsite::class)) {
90
+			Subsite::disable_subsite_filter(true);
91
+		}
92 92
 
93
-        $permissionsUsr = Permission::permissions_for_member($this->owner->ID);
94
-        $permissionsSrc = Permission::get_codes(true);
95
-        sort($permissionsUsr);
93
+		$permissionsUsr = Permission::permissions_for_member($this->owner->ID);
94
+		$permissionsSrc = Permission::get_codes(true);
95
+		sort($permissionsUsr);
96 96
 
97
-        $permissionNames = array();
98
-        foreach ($permissionsUsr as $code) {
99
-            $code = strtoupper($code);
100
-            foreach ($permissionsSrc as $k => $v) {
101
-                if (isset($v[$code])) {
102
-                    $name = empty($v[$code]['name'])
103
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
104
-                        : $v[$code]['name'];
105
-                    $permissionNames[] = $name;
106
-                }
107
-            }
108
-        }
97
+		$permissionNames = array();
98
+		foreach ($permissionsUsr as $code) {
99
+			$code = strtoupper($code);
100
+			foreach ($permissionsSrc as $k => $v) {
101
+				if (isset($v[$code])) {
102
+					$name = empty($v[$code]['name'])
103
+						? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
104
+						: $v[$code]['name'];
105
+					$permissionNames[] = $name;
106
+				}
107
+			}
108
+		}
109 109
 
110
-        $result = $permissionNames
111
-            ? implode(', ', $permissionNames)
112
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
110
+		$result = $permissionNames
111
+			? implode(', ', $permissionNames)
112
+			: _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
113 113
 
114
-        if (class_exists(Subsite::class)) {
115
-            Subsite::disable_subsite_filter(false);
116
-        }
117
-        return $result;
118
-    }
114
+		if (class_exists(Subsite::class)) {
115
+			Subsite::disable_subsite_filter(false);
116
+		}
117
+		return $result;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         if ($lastTime) {
44 44
             return $lastTime->dbObject('Created')->format(DBDatetime::ISO_DATETIME);
45 45
         }
46
-        return _t(__CLASS__ . '.NEVER', 'Never');
46
+        return _t(__CLASS__.'.NEVER', 'Never');
47 47
     }
48 48
 
49 49
     /**
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
             $result = preg_replace("#</?[^>]>#", '', implode(', ', $groupNames));
71 71
         } else {
72 72
             // If no groups then return a status label
73
-            $result = _t(__CLASS__ . '.NOGROUPS', 'Not in a Security Group');
73
+            $result = _t(__CLASS__.'.NOGROUPS', 'Not in a Security Group');
74 74
         }
75 75
 
76 76
         if (class_exists(Subsite::class)) {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             foreach ($permissionsSrc as $k => $v) {
101 101
                 if (isset($v[$code])) {
102 102
                     $name = empty($v[$code]['name'])
103
-                        ? _t(__CLASS__ . '.UNKNOWN', 'Unknown')
103
+                        ? _t(__CLASS__.'.UNKNOWN', 'Unknown')
104 104
                         : $v[$code]['name'];
105 105
                     $permissionNames[] = $name;
106 106
                 }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 
110 110
         $result = $permissionNames
111 111
             ? implode(', ', $permissionNames)
112
-            : _t(__CLASS__ . '.NOPERMISSIONS', 'No Permissions');
112
+            : _t(__CLASS__.'.NOPERMISSIONS', 'No Permissions');
113 113
 
114 114
         if (class_exists(Subsite::class)) {
115 115
             Subsite::disable_subsite_filter(false);
Please login to merge, or discard this patch.
tests/MemberReportExtensionTest.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -9,33 +9,33 @@
 block discarded – undo
9 9
 
10 10
 class MemberReportExtensionTest extends SapphireTest
11 11
 {
12
-    protected static $fixture_file = 'MemberReportExtensionTest.yml';
13
-
14
-    protected static $required_extensions = [
15
-        Member::class => [
16
-            MemberReportExtension::class,
17
-        ],
18
-    ];
19
-
20
-    protected function setUp()
21
-    {
22
-        DBDatetime::set_mock_now('2018-05-03 00:00:00');
23
-
24
-        parent::setUp();
25
-    }
26
-
27
-    public function testGetLastLoggedIn()
28
-    {
29
-        /** @var Member $member */
30
-        $member = $this->objFromFixture(Member::class, 'has_logged_in');
31
-        $result = $member->getLastLoggedIn();
32
-        $this->assertContains('2018-05-03', $result, 'Last logged in date is shown');
33
-    }
34
-
35
-    public function testGetLastLoggedInReturnsNever()
36
-    {
37
-        $member = new Member();
38
-        $member->write();
39
-        $this->assertSame('Never', $member->getLastLoggedIn());
40
-    }
12
+	protected static $fixture_file = 'MemberReportExtensionTest.yml';
13
+
14
+	protected static $required_extensions = [
15
+		Member::class => [
16
+			MemberReportExtension::class,
17
+		],
18
+	];
19
+
20
+	protected function setUp()
21
+	{
22
+		DBDatetime::set_mock_now('2018-05-03 00:00:00');
23
+
24
+		parent::setUp();
25
+	}
26
+
27
+	public function testGetLastLoggedIn()
28
+	{
29
+		/** @var Member $member */
30
+		$member = $this->objFromFixture(Member::class, 'has_logged_in');
31
+		$result = $member->getLastLoggedIn();
32
+		$this->assertContains('2018-05-03', $result, 'Last logged in date is shown');
33
+	}
34
+
35
+	public function testGetLastLoggedInReturnsNever()
36
+	{
37
+		$member = new Member();
38
+		$member->write();
39
+		$this->assertSame('Never', $member->getLastLoggedIn());
40
+	}
41 41
 }
Please login to merge, or discard this patch.