Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions _build/test/Tests/Model/Element/modElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,61 @@ public function providerProcess() {
];
}

/**
* Property definitions without a desc key must not trigger PHP warnings on get('properties').
*
* @dataProvider providerGetPropertiesWithoutDescKey
* @param array $propertyDefinition
* @param string $expectedDescTrans
*/
public function testGetPropertiesWithoutDescKey(array $propertyDefinition, string $expectedDescTrans)
{
/** @var modElement $element */
$element = $this->modx->newObject(modElement::class);
$element->set('properties', [$propertyDefinition]);

$warnings = [];
set_error_handler(static function ($severity, $message) use (&$warnings) {
if ($severity === E_WARNING) {
$warnings[] = $message;
}
return true;
}, E_WARNING);

try {
$properties = $element->get('properties');
} finally {
restore_error_handler();
}

$this->assertSame([], $warnings, 'Expected no PHP warnings when desc is missing');
$this->assertArrayHasKey('desc_trans', $properties[0]);
$this->assertSame($expectedDescTrans, $properties[0]['desc_trans']);
}

public function providerGetPropertiesWithoutDescKey()
{
return [
'missing desc' => [
[
'name' => 'foo',
'type' => 'textfield',
'value' => 'bar',
],
'',
],
'description fallback' => [
[
'name' => 'foo',
'type' => 'textfield',
'value' => 'bar',
'description' => 'foo_desc',
],
'foo_desc',
],
];
}

/**
* Test the modElement->getTag() method with xPDOObjects as values.
* E.g the nodes when the event `OnResourceSort` is fired
Expand Down
3 changes: 2 additions & 1 deletion core/src/Revolution/modElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public function get($k, $format = null, $formatTemplate = null)
}
$this->xpdo->lexicon->load($property['lexicon']);
}
$property['desc_trans'] = $this->xpdo->lexicon($property['desc']);
$desc = $property['desc'] ?? $property['description'] ?? '';
Comment thread
Ibochkarev marked this conversation as resolved.
Outdated
$property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : '';
$property['area'] = !empty($property['area']) ? $property['area'] : '';
$property['area_trans'] = !empty($property['area']) ? $this->xpdo->lexicon($property['area']) : '';

Expand Down
3 changes: 2 additions & 1 deletion core/src/Revolution/modPropertySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function get($k, $format = null, $formatTemplate = null)
}
$this->xpdo->lexicon->load($property['lexicon']);
}
$property['desc_trans'] = $this->xpdo->lexicon($property['desc']);
$desc = $property['desc'] ?? $property['description'] ?? '';
Comment thread
Ibochkarev marked this conversation as resolved.
Outdated
$property['desc_trans'] = $desc !== '' ? $this->xpdo->lexicon($desc) : '';
$property['area'] = !empty($property['area']) ? $property['area'] : '';

if (!empty($property['options'])) {
Expand Down
Loading