Skip to content

Commit 3d45411

Browse files
committed
[TASK] Small code cleanup
1 parent 6f036b2 commit 3d45411

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

Classes/Integration/HookSubscribers/ContentIcon.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,23 @@ public function addSubIcon(array $parameters, $caller = null)
9090
if (!$caller instanceof PageLayoutView) {
9191
return '';
9292
}
93-
$provider = null;
94-
$this->attachAssets();
9593
list ($table, $uid, $record) = $parameters;
9694
if ($table !== 'tt_content') {
9795
return '';
9896
}
99-
$icon = '';
10097

98+
$this->attachAssets();
99+
100+
$provider = null;
101+
$icon = '';
101102
$record = null === $record && 0 < $uid ? BackendUtility::getRecord($table, $uid) : $record;
102103
$cacheIdentity = $table . $uid . sha1(serialize($record)) . ($this->isRowCollapsed($record) ? 'collapsed' : 'expanded');
103104
// filter 1: icon must not already be cached and both record and caller must be provided.
104105
// we check the cache here because at this point, the cache key is decidedly
105106
// unique and we have not yet consulted the (potentially costly) Provider.
106107
$cachedIconIdentifier = $this->cache->get($cacheIdentity);
107-
if ($cachedIconIdentifier !== false) {
108-
$icon = $cachedIconIdentifier;
108+
if ($cachedIconIdentifier !== null) {
109+
return $cachedIconIdentifier;
109110
} elseif ($record) {
110111
$field = $this->detectFirstFlexTypeFieldInTableFromPossibilities($table, array_keys($record));
111112
// filter 2: table must have one field defined as "flex" and record must include it.
@@ -118,10 +119,8 @@ public function addSubIcon(array $parameters, $caller = null)
118119
GridProviderInterface::class
119120
);
120121
// filter 3: a Provider must be resolved for the record.
121-
if ($provider) {
122-
if ($provider->getGrid($record)->hasChildren()) {
123-
$icon = $this->drawGridToggle($record);
124-
}
122+
if ($provider && $provider->getGrid($record)->hasChildren()) {
123+
$icon = $this->drawGridToggle($record);
125124
}
126125
}
127126
}

Tests/Unit/Integration/HookSubscribers/ContentIconTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ public function testDrawGridToggle()
9191
* @dataProvider getAddSubIconTestValues
9292
* @param array $parameters
9393
* @param ProviderInterface|NULL
94-
* @param string|NULL $expected
9594
*/
96-
public function testAddSubIcon(array $parameters, $provider, $expected)
95+
public function testAddSubIcon(array $parameters, $provider)
9796
{
9897
$GLOBALS['BE_USER'] = $this->getMockBuilder(BackendUserAuthentication::class)->setMethods(array('calcPerms'))->getMock();
9998
$GLOBALS['BE_USER']->expects($this->any())->method('calcPerms');
@@ -118,13 +117,7 @@ public function testAddSubIcon(array $parameters, $provider, $expected)
118117
ObjectAccess::setProperty($provider, 'configurationService', $configurationServiceMock, true);
119118
}
120119

121-
$result = $instance->addSubIcon($parameters, new PageLayoutView());
122-
if (null === $expected) {
123-
$this->assertEmpty($result);
124-
} else {
125-
$this->assertNotNull($result);
126-
}
127-
unset($GLOBALS['TCA']);
120+
$instance->addSubIcon($parameters, new PageLayoutView());
128121
}
129122

130123
/**
@@ -134,18 +127,21 @@ public function getAddSubIconTestValues()
134127
{
135128
$formWithoutIcon = Form::create();
136129
$formWithIcon = Form::create(array('options' => array('icon' => 'icon')));
137-
$providerWithoutForm = $this->getMockBuilder(Provider::class)->setMethods(array('getForm'))->getMock();
130+
$providerWithoutForm = $this->getMockBuilder(Provider::class)->setMethods(array('getForm', 'getGrid'))->getMock();
138131
$providerWithoutForm->expects($this->any())->method('getForm')->willReturn(null);
139-
$providerWithFormWithoutIcon = $this->getMockBuilder(Provider::class)->setMethods(array('getForm'))->getMock();
132+
$providerWithoutForm->expects($this->any())->method('getGrid')->willReturn(Form\Container\Grid::create());
133+
$providerWithFormWithoutIcon = $this->getMockBuilder(Provider::class)->setMethods(array('getForm', 'getGrid'))->getMock();
140134
$providerWithFormWithoutIcon->expects($this->any())->method('getForm')->willReturn($formWithoutIcon);
141-
$providerWithFormWithIcon = $this->getMockBuilder(Provider::class)->setMethods(array('getForm'))->getMock();
135+
$providerWithFormWithoutIcon->expects($this->any())->method('getGrid')->willReturn(Form\Container\Grid::create());
136+
$providerWithFormWithIcon = $this->getMockBuilder(Provider::class)->setMethods(array('getForm', 'getGrid'))->getMock();
142137
$providerWithFormWithIcon->expects($this->any())->method('getForm')->willReturn($formWithIcon);
138+
$providerWithFormWithIcon->expects($this->any())->method('getGrid')->willReturn(Form\Container\Grid::create());
143139
return array(
144-
array(array('tt_content', 1, array()), null, null),
145-
array(array('tt_content', 1, array()), $providerWithoutForm, null),
146-
array(array('tt_content', 1, array('field' => 'test')), $providerWithoutForm, null),
147-
array(array('tt_content', 1, array('field' => 'test')), $providerWithFormWithoutIcon, null),
148-
array(array('tt_content', 1, array('field' => 'test')), $providerWithFormWithIcon, null),
140+
'no provider' => array(array('tt_content', 1, array()), null),
141+
'provider without form without field' => array(array('tt_content', 1, array()), $providerWithoutForm),
142+
'provider without form with field' => array(array('tt_content', 1, array('field' => 'test')), $providerWithoutForm),
143+
'provider with form without icon' => array(array('tt_content', 1, array('field' => 'test')), $providerWithFormWithoutIcon),
144+
'provider with form with icon' => array(array('tt_content', 1, array('field' => 'test')), $providerWithFormWithIcon),
149145
);
150146
}
151147
}

0 commit comments

Comments
 (0)