Skip to content

Commit

Permalink
API Rename FormField Value to getFormattedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 21, 2025
1 parent f075bb3 commit 7e75542
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/Forms/DiffField.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function getComparisonField()
return $this->comparisonField;
}

public function Value()
public function getFormattedValue(): string
{
$oldValue = $this->getOutdatedField()->Value();
$newValue = $this->getComparisonField()->Value();
$oldValue = $this->getOutdatedField()->getValue();
$newValue = $this->getComparisonField()->getValue();

// Objects can't be diffed
if (is_object($oldValue) || is_object($newValue)) {
Expand All @@ -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 `<i>('none')</i>`
$emptyPlaceholder = ReadonlyField::create('na')->Value();
$emptyPlaceholder = ReadonlyField::create('na')->getValue();
if ($oldValue === $newValue && $newValue === $emptyPlaceholder) {
// if both the old and new valus are empty, let the surronding <i> tags render as HTML (escape = false)
$escape = false;
Expand Down Expand Up @@ -102,14 +102,14 @@ public function getSchemaDataDefaults()

public function getSchemaStateDefaults()
{
$fromValue = $this->getOutdatedField()->Value();
$fromValue = $this->getOutdatedField()->getValue();
$toField = $this->getComparisonField();
$toValue = $toField->Value();
$toValue = $toField->getValue();

$state = array_merge(
$toField->getSchemaStateDefaults(),
parent::getSchemaStateDefaults(),
['value' => $this->Value()]
['value' => $this->getValue()]
);
$state['data']['diff'] = [
'from' => $fromValue,
Expand Down
8 changes: 4 additions & 4 deletions tests/Forms/DiffFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testScalarValuesAreDiffed()
$diffField->setComparisonField($newField);
$diffField->setValue('old');

$this->assertMatchesRegularExpression('/^<del>old<\/del> *<ins>new<\/ins>$/', $diffField->Value());
$this->assertMatchesRegularExpression('/^<del>old<\/del> *<ins>new<\/ins>$/', $diffField->getValue());
}

/**
Expand All @@ -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->getValue());
}

#[DataProvider('provideEscaping')]
Expand All @@ -50,15 +50,15 @@ public function testEscaping(
// 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')->getValue();
$emptyPlaceholderNoTags = strip_tags($emptyPlaceholder);
$expected = str_replace('$emptyPlaceholderNoTags', $emptyPlaceholderNoTags, $expected);
$expected = str_replace('$emptyPlaceholder', $emptyPlaceholder, $expected);
$newField = new $className('Test', 'Test', $oldValue);
$diffField = DiffField::create('DiffTest');
$diffField->setComparisonField($newField);
$diffField->setValue($newValue);
$this->assertSame($expected, $diffField->Value(), $message);
$this->assertSame($expected, $diffField->getValue(), $message);
}

public static function provideEscaping()
Expand Down
8 changes: 4 additions & 4 deletions tests/Forms/DiffTransformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->getValue(), 'Value before is shown');
$this->assertStringContainsString($expected[$index]['after'], $field->getValue(), 'Value after is shown');
}
}

Expand All @@ -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->getValue(), 'Value before is shown');
$this->assertStringContainsString($expected[$index]['after'], $field->getValue(), 'Value after is shown');
}
}

Expand Down

0 comments on commit 7e75542

Please sign in to comment.