| Conditions | 5 |
| Paths | 16 |
| Total Lines | 72 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 66 | $field = $fields->fieldByName('AllSubsites'); |
||
| 67 | $count = count(array_filter(array_keys($field->getSource()), function ($value) { |
||
| 68 | return is_int($value); |
||
| 69 | })); |
||
| 70 | |||
| 71 | $this->assertEquals(4, $count, '2 subsites plus 2 added options to filter by subsite'); |
||
| 72 | } else { |
||
| 73 | $this->assertNull($fields->fieldByName('AllSubsites')); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | public function testReportFields() |
||
| 78 | { |
||
| 79 | $report = SitewideContentReport::create(); |
||
| 80 | |||
| 81 | // Test pages view |
||
| 82 | $gridField = $report->getReportField('Pages'); |
||
| 83 | |||
| 84 | /* @var $columns GridFieldDataColumns */ |
||
| 85 | $columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); |
||
| 86 | $displayed = $columns->getDisplayFields($gridField); |
||
| 87 | |||
| 88 | $this->assertArrayHasKey('Title', $displayed); |
||
| 89 | $this->assertArrayHasKey('Created', $displayed); |
||
| 90 | $this->assertArrayHasKey('LastEdited', $displayed); |
||
| 91 | $this->assertArrayHasKey('i18n_singular_name', $displayed); |
||
| 92 | $this->assertArrayHasKey('StageState', $displayed); |
||
| 93 | |||
| 94 | // Use correct link |
||
| 95 | $this->assertArrayHasKey('RelativeLink', $displayed); |
||
| 96 | $this->assertArrayNotHasKey('AbsoluteLink', $displayed); |
||
| 97 | |||
| 98 | if (class_exists('Subsite')) { |
||
| 99 | $this->assertArrayHasKey('SubsiteName', $displayed); |
||
| 100 | } else { |
||
| 101 | $this->assertArrayNotHasKey('SubsiteName', $displayed); |
||
| 102 | } |
||
| 103 | |||
| 104 | // Export-only fields are not in display list |
||
| 105 | $this->assertArrayNotHasKey('Terms', $displayed); |
||
| 106 | $this->assertArrayNotHasKey('OwnerNames', $displayed); |
||
| 107 | $this->assertArrayNotHasKey('ReviewDate', $displayed); |
||
| 108 | $this->assertArrayNotHasKey('MetaDescription', $displayed); |
||
| 109 | |||
| 110 | // Tests print / export field |
||
| 111 | /* @var $export GridFieldExportButton */ |
||
| 112 | $export = $gridField->getConfig()->getComponentByType(GridFieldExportButton::class); |
||
| 113 | $exported = $export->getExportColumns(); |
||
| 114 | |||
| 115 | // Make sure all shared columns are in this report |
||
| 116 | $this->assertArrayHasKey('Title', $exported); |
||
| 117 | $this->assertArrayHasKey('Created', $exported); |
||
| 118 | $this->assertArrayHasKey('LastEdited', $exported); |
||
| 119 | $this->assertArrayHasKey('i18n_singular_name', $exported); |
||
| 120 | $this->assertArrayHasKey('StageState', $exported); |
||
| 121 | |||
| 122 | // Export-only fields |
||
| 123 | $this->assertArrayHasKey('MetaDescription', $exported); |
||
| 124 | |||
| 125 | // Use correct link |
||
| 126 | $this->assertArrayHasKey('AbsoluteLink', $exported); |
||
| 127 | $this->assertArrayNotHasKey('RelativeLink', $exported); |
||
| 128 | |||
| 129 | if (class_exists('Subsite')) { |
||
| 130 | $this->assertArrayHasKey('SubsiteName', $exported); |
||
| 131 | } else { |
||
| 132 | $this->assertArrayNotHasKey('SubsiteName', $exported); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (SitewideContentTaxonomy::enabled()) { |
||
| 136 | $this->assertArrayHasKey('Terms', $exported); |
||
| 137 | } else { |
||
| 138 | $this->assertArrayNotHasKey('Terms', $exported); |
||
| 150 |