diff --git a/src/Forms/DiffField.php b/src/Forms/DiffField.php
index c43c5f6..1db32bc 100644
--- a/src/Forms/DiffField.php
+++ b/src/Forms/DiffField.php
@@ -42,10 +42,10 @@ public function getComparisonField()
return $this->comparisonField;
}
- public function Value()
+ public function getFormattedValue(): mixed
{
- $oldValue = $this->getOutdatedField()->Value();
- $newValue = $this->getComparisonField()->Value();
+ $oldValue = $this->getOutdatedField()->getFormattedValue();
+ $newValue = $this->getComparisonField()->getFormattedValue();
// Objects can't be diffed
if (is_object($oldValue) || is_object($newValue)) {
@@ -58,7 +58,7 @@ public function Value()
}
// Ensure that the emtpy placeholder value is not escaped
// The empty placeholder value is usually going to be `('none')`
- $emptyPlaceholder = ReadonlyField::create('na')->Value();
+ $emptyPlaceholder = ReadonlyField::create('na')->getFormattedValue();
if ($oldValue === $newValue && $newValue === $emptyPlaceholder) {
// if both the old and new valus are empty, let the surronding tags render as HTML (escape = false)
$escape = false;
@@ -102,14 +102,14 @@ public function getSchemaDataDefaults()
public function getSchemaStateDefaults()
{
- $fromValue = $this->getOutdatedField()->Value();
+ $fromValue = $this->getOutdatedField()->getFormattedValue();
$toField = $this->getComparisonField();
- $toValue = $toField->Value();
+ $toValue = $toField->getFormattedValue();
$state = array_merge(
$toField->getSchemaStateDefaults(),
parent::getSchemaStateDefaults(),
- ['value' => $this->Value()]
+ ['value' => $this->getFormattedValue()]
);
$state['data']['diff'] = [
'from' => $fromValue,
diff --git a/tests/Behat/features/compare-mode.feature b/tests/Behat/features/compare-mode.feature
index 86075df..50e4874 100644
--- a/tests/Behat/features/compare-mode.feature
+++ b/tests/Behat/features/compare-mode.feature
@@ -35,6 +35,7 @@ Feature: Compare mode
Then I should see text matching "Compare mode"
And I should see text matching "Select two versions"
+@sboyd
Scenario: Changes between versions are highlighted
Given I click on "Content" in the header tabs
Then I fill in the "Content" HTML field with "
Hello universe
"
diff --git a/tests/Forms/DiffFieldTest.php b/tests/Forms/DiffFieldTest.php
index a2ef2fc..395cfaf 100644
--- a/tests/Forms/DiffFieldTest.php
+++ b/tests/Forms/DiffFieldTest.php
@@ -22,7 +22,7 @@ public function testScalarValuesAreDiffed()
$diffField->setComparisonField($newField);
$diffField->setValue('old');
- $this->assertMatchesRegularExpression('/^old<\/del> *new<\/ins>$/', $diffField->Value());
+ $this->assertMatchesRegularExpression('/^old<\/del> *new<\/ins>$/', $diffField->getFormattedValue());
}
/**
@@ -36,7 +36,7 @@ public function testObjectValuesAreNotDiffed()
$diffField->setComparisonField($newField);
$diffField->setValue(ManyManyList::create(Group::class, 'Group_Members', 'GroupID', 'MemberID'));
- $this->assertEquals('(No diff available)', $diffField->Value());
+ $this->assertEquals('(No diff available)', $diffField->getFormattedValue());
}
#[DataProvider('provideEscaping')]
@@ -45,59 +45,53 @@ public function testEscaping(
string $oldValue,
string $newValue,
string $expected,
- string $message
) {
// get $emptyPlaceholder here instead of provideEscaping to prevent
// BadMethodCallException: No injector manifests available
// error in dataProvider method
- $emptyPlaceholder = ReadonlyField::create('na')->Value();
+ $emptyPlaceholder = ReadonlyField::create('na')->getFormattedValue();
$emptyPlaceholderNoTags = strip_tags($emptyPlaceholder);
$expected = str_replace('$emptyPlaceholderNoTags', $emptyPlaceholderNoTags, $expected);
$expected = str_replace('$emptyPlaceholder', $emptyPlaceholder, $expected);
- $newField = new $className('Test', 'Test', $oldValue);
+ $newField = new $className('Test', 'Test', $newValue);
$diffField = DiffField::create('DiffTest');
$diffField->setComparisonField($newField);
- $diffField->setValue($newValue);
- $this->assertSame($expected, $diffField->Value(), $message);
+ $diffField->setValue($oldValue);
+ $this->assertSame($expected, $diffField->getFormattedValue());
}
public static function provideEscaping()
{
return [
- [
- ReadonlyField::class,
- 'Something',
- 'Something bold',
- 'Something <strong> bold </strong>',
- 'Non HTML field is escaped'
+ 'readonly-add-bold' => [
+ 'className' => ReadonlyField::class,
+ 'oldValue' => 'Something',
+ 'newValue' => 'Something bold',
+ 'expected' => 'Something <strong> bold </strong>',
],
- [
- HTMLEditorField_Readonly::class,
- 'Something',
- 'Something bold',
- 'Something bold',
- 'Non HTML field is not escaped'
+ 'htmleditor-readonly' => [
+ 'className' => HTMLEditorField_Readonly::class,
+ 'oldValue' => 'Something',
+ 'newValue' => 'Something bold',
+ 'expected' => 'Something bold',
],
- [
- ReadonlyField::class,
- '',
- '',
- '$emptyPlaceholder',
- 'No value is not escaped'
+ 'readonly-nothing' => [
+ 'className' => ReadonlyField::class,
+ 'oldValue' => '',
+ 'newValue' => '',
+ 'expected' => "('none')",
],
- [
- ReadonlyField::class,
- '',
- 'Something',
- 'Something $emptyPlaceholderNoTags',
- 'No value is escaped without tags removed when value added'
+ 'readonly-add-something' => [
+ 'className' => ReadonlyField::class,
+ 'oldValue' => '',
+ 'newValue' => 'Something',
+ 'expected' => "('none') Something",
],
- [
- ReadonlyField::class,
- 'Something',
- '',
- '$emptyPlaceholderNoTags Something',
- 'No value is escaped without tags removed when value removed'
+ 'readonly-remove-something' => [
+ 'className' => ReadonlyField::class,
+ 'oldValue' => 'Something',
+ 'newValue' => '',
+ 'expected' => "Something ('none')",
],
];
}
diff --git a/tests/Forms/DiffTransformationTest.php b/tests/Forms/DiffTransformationTest.php
index c2c094c..7896407 100644
--- a/tests/Forms/DiffTransformationTest.php
+++ b/tests/Forms/DiffTransformationTest.php
@@ -62,8 +62,8 @@ public function testTransform()
$form->loadDataFrom($oldData);
foreach ($form->Fields() as $index => $field) {
- $this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown');
- $this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown');
+ $this->assertStringContainsString($expected[$index]['before'], $field->getFormattedValue());
+ $this->assertStringContainsString($expected[$index]['after'], $field->getFormattedValue());
}
}
@@ -87,8 +87,8 @@ public function testTransformWithCompositeFields()
$form->loadDataFrom($oldData);
foreach (array_values($form->Fields()->dataFields() ?? []) as $index => $field) {
- $this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown');
- $this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown');
+ $this->assertStringContainsString($expected[$index]['before'], $field->getFormattedValue());
+ $this->assertStringContainsString($expected[$index]['after'], $field->getFormattedValue());
}
}