Completed
Push — master ( e2e2e6...f57935 )
by
unknown
14s
created
tests/Report/CwpStatsReportTest.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,35 +9,35 @@
 block discarded – undo
9 9
 
10 10
 class CwpStatsReportTest extends SapphireTest
11 11
 {
12
-    protected static $fixture_file = 'CwpStatsReportTest.yml';
12
+	protected static $fixture_file = 'CwpStatsReportTest.yml';
13 13
 
14
-    public function testCount()
15
-    {
16
-        // Publish all pages apart from page3.
17
-        $this->objFromFixture(Page::class, 'page1')->publishRecursive();
18
-        $this->objFromFixture(Page::class, 'page2')->publishRecursive();
19
-        $this->objFromFixture(Page::class, 'page3')->publishRecursive();
14
+	public function testCount()
15
+	{
16
+		// Publish all pages apart from page3.
17
+		$this->objFromFixture(Page::class, 'page1')->publishRecursive();
18
+		$this->objFromFixture(Page::class, 'page2')->publishRecursive();
19
+		$this->objFromFixture(Page::class, 'page3')->publishRecursive();
20 20
 
21
-        // Add page5s to a subsite, if the module is installed.
22
-        $page5s = $this->objFromFixture(Page::class, 'page5s');
23
-        if (class_exists(Subsite::class)) {
24
-            $subsite = Subsite::create();
25
-            $subsite->Title = 'subsite';
26
-            $subsite->write();
21
+		// Add page5s to a subsite, if the module is installed.
22
+		$page5s = $this->objFromFixture(Page::class, 'page5s');
23
+		if (class_exists(Subsite::class)) {
24
+			$subsite = Subsite::create();
25
+			$subsite->Title = 'subsite';
26
+			$subsite->write();
27 27
 
28
-            $page5s->SubsiteID = $subsite->ID;
29
-            $page5s->write();
30
-        }
31
-        $page5s->publishRecursive();
28
+			$page5s->SubsiteID = $subsite->ID;
29
+			$page5s->write();
30
+		}
31
+		$page5s->publishRecursive();
32 32
 
33
-        $report = CwpStatsReport::create();
34
-        $records = $report->sourceRecords([])->toArray();
35
-        $i = 0;
36
-        $this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
37
-        if (class_exists(Subsite::class)) {
38
-            $this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
39
-            $this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
40
-        }
41
-        $this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
42
-    }
33
+		$report = CwpStatsReport::create();
34
+		$records = $report->sourceRecords([])->toArray();
35
+		$i = 0;
36
+		$this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
37
+		if (class_exists(Subsite::class)) {
38
+			$this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
39
+			$this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
40
+		}
41
+		$this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
42
+	}
43 43
 }
Please login to merge, or discard this patch.
src/Report/CwpStatsReport.php 2 patches
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -20,108 +20,108 @@
 block discarded – undo
20 20
  */
21 21
 class CwpStatsReport extends Report
22 22
 {
23
-    public function title()
24
-    {
25
-        return _t(__CLASS__ . '.Title', 'Summary statistics');
26
-    }
27
-
28
-    public function description()
29
-    {
30
-        return _t(
31
-            __CLASS__ . '.Description',
32
-            'This report provides various statistics for this site. The "total live page count" is the number that ' .
33
-                'can be compared against the instance size specifications.'
34
-        );
35
-    }
36
-
37
-    public function columns()
38
-    {
39
-        return [
40
-            'Name' => _t(__CLASS__ . '.Name', 'Name'),
41
-            'Count' => _t(__CLASS__ . '.Count', 'Count'),
42
-        ];
43
-    }
44
-
45
-    /**
46
-     * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result.
47
-     *
48
-     * {@inheritDoc}
49
-     */
50
-    public function sourceRecords($params = [], $sort = null, $limit = null)
51
-    {
52
-        $records = [];
53
-
54
-        // Get the query to apply across all variants: looks at all subsites, translations, live stage only.
55
-        $crossVariant = (function ($dataQuery) {
56
-            $params = [
57
-                'Subsite.filter' => false,
58
-                'Versioned.mode' => 'stage',
59
-                'Versioned.stage' => Versioned::LIVE,
60
-            ];
61
-
62
-            return $dataQuery->setDataQueryParam($params);
63
-        });
64
-
65
-        // Total.
66
-        $records[] = [
67
-            'Name' => _t(
68
-                __CLASS__ . '.TotalPageCount',
69
-                'Total live page count, across all translations and subsites'
70
-            ),
71
-            'Count' => $crossVariant(SiteTree::get())->count(),
72
-        ];
73
-
74
-        if (class_exists(Subsite::class)) {
75
-            // Main site.
76
-            $records[] = [
77
-                'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
78
-                'Count' => $crossVariant(SiteTree::get())
79
-                    ->filter(['SubsiteID' => 0])
80
-                    ->count(),
81
-            ];
82
-
83
-            // Per subsite.
84
-            $subsites = Subsite::get();
85
-            foreach ($subsites as $subsite) {
86
-                $records[] = [
87
-                    'Name' => _t(
88
-                        __CLASS__ . '.PagesForSubsite',
89
-                        "- in the subsite '{SubsiteTitle}'",
90
-                        ['SubsiteTitle' => $subsite->Title]
91
-                    ),
92
-                    'Count' => $crossVariant(SiteTree::get())
93
-                        ->filter(['SubsiteID' => $subsite->ID])
94
-                        ->count(),
95
-                ];
96
-            }
97
-        }
98
-
99
-        // Files.
100
-        $records[] = [
101
-            'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
102
-            'Count' => File::get()
103
-                ->setDataQueryParam('Subsite.filter', false)
104
-                ->filter(['ClassName:not' => Folder::class])
105
-                ->count(),
106
-        ];
107
-
108
-        return ArrayList::create($records);
109
-    }
110
-
111
-    /**
112
-     * @return GridField
113
-     */
114
-    public function getReportField()
115
-    {
116
-        /** @var GridField $gridField */
117
-        $gridField = parent::getReportField();
118
-
119
-        /** @var GridFieldConfig $gridConfig */
120
-        $gridConfig = $gridField->getConfig();
121
-        $gridConfig->removeComponentsByType(GridFieldPrintButton::class);
122
-        $gridConfig->removeComponentsByType(GridFieldExportButton::class);
123
-        $gridConfig->removeComponentsByType(GridFieldSortableHeader::class);
124
-
125
-        return $gridField;
126
-    }
23
+	public function title()
24
+	{
25
+		return _t(__CLASS__ . '.Title', 'Summary statistics');
26
+	}
27
+
28
+	public function description()
29
+	{
30
+		return _t(
31
+			__CLASS__ . '.Description',
32
+			'This report provides various statistics for this site. The "total live page count" is the number that ' .
33
+				'can be compared against the instance size specifications.'
34
+		);
35
+	}
36
+
37
+	public function columns()
38
+	{
39
+		return [
40
+			'Name' => _t(__CLASS__ . '.Name', 'Name'),
41
+			'Count' => _t(__CLASS__ . '.Count', 'Count'),
42
+		];
43
+	}
44
+
45
+	/**
46
+	 * Manually create source records for the report. Agreggates cannot be provided as a column of a DataQuery result.
47
+	 *
48
+	 * {@inheritDoc}
49
+	 */
50
+	public function sourceRecords($params = [], $sort = null, $limit = null)
51
+	{
52
+		$records = [];
53
+
54
+		// Get the query to apply across all variants: looks at all subsites, translations, live stage only.
55
+		$crossVariant = (function ($dataQuery) {
56
+			$params = [
57
+				'Subsite.filter' => false,
58
+				'Versioned.mode' => 'stage',
59
+				'Versioned.stage' => Versioned::LIVE,
60
+			];
61
+
62
+			return $dataQuery->setDataQueryParam($params);
63
+		});
64
+
65
+		// Total.
66
+		$records[] = [
67
+			'Name' => _t(
68
+				__CLASS__ . '.TotalPageCount',
69
+				'Total live page count, across all translations and subsites'
70
+			),
71
+			'Count' => $crossVariant(SiteTree::get())->count(),
72
+		];
73
+
74
+		if (class_exists(Subsite::class)) {
75
+			// Main site.
76
+			$records[] = [
77
+				'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
78
+				'Count' => $crossVariant(SiteTree::get())
79
+					->filter(['SubsiteID' => 0])
80
+					->count(),
81
+			];
82
+
83
+			// Per subsite.
84
+			$subsites = Subsite::get();
85
+			foreach ($subsites as $subsite) {
86
+				$records[] = [
87
+					'Name' => _t(
88
+						__CLASS__ . '.PagesForSubsite',
89
+						"- in the subsite '{SubsiteTitle}'",
90
+						['SubsiteTitle' => $subsite->Title]
91
+					),
92
+					'Count' => $crossVariant(SiteTree::get())
93
+						->filter(['SubsiteID' => $subsite->ID])
94
+						->count(),
95
+				];
96
+			}
97
+		}
98
+
99
+		// Files.
100
+		$records[] = [
101
+			'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
102
+			'Count' => File::get()
103
+				->setDataQueryParam('Subsite.filter', false)
104
+				->filter(['ClassName:not' => Folder::class])
105
+				->count(),
106
+		];
107
+
108
+		return ArrayList::create($records);
109
+	}
110
+
111
+	/**
112
+	 * @return GridField
113
+	 */
114
+	public function getReportField()
115
+	{
116
+		/** @var GridField $gridField */
117
+		$gridField = parent::getReportField();
118
+
119
+		/** @var GridFieldConfig $gridConfig */
120
+		$gridConfig = $gridField->getConfig();
121
+		$gridConfig->removeComponentsByType(GridFieldPrintButton::class);
122
+		$gridConfig->removeComponentsByType(GridFieldExportButton::class);
123
+		$gridConfig->removeComponentsByType(GridFieldSortableHeader::class);
124
+
125
+		return $gridField;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
         $records = [];
53 53
 
54 54
         // Get the query to apply across all variants: looks at all subsites, translations, live stage only.
55
-        $crossVariant = (function ($dataQuery) {
55
+        $crossVariant = (function($dataQuery) {
56 56
             $params = [
57 57
                 'Subsite.filter' => false,
58 58
                 'Versioned.mode' => 'stage',
Please login to merge, or discard this patch.