BUG Fix issue with assertListEquals() ignoring field getters

This commit is contained in:
Damian Mooyman 2019-01-11 11:25:44 +13:00
parent 280222abbe
commit 34ac228029
No known key found for this signature in database
GPG Key ID: 4327857F75021D92
3 changed files with 43 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class ViewableDataContains extends PHPUnit_Framework_Constraint implements TestO
$success = true;
foreach ($this->match as $fieldName => $value) {
if ($other->getField($fieldName) != $value) {
if ($other->$fieldName != $value) {
$success = false;
break;
}

View File

@ -4,6 +4,7 @@ namespace SilverStripe\Dev\Tests;
use SilverStripe\Dev\Constraint\ViewableDataContains;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\Tests\ViewableDataContainsTest\TestObject;
use SilverStripe\Security\Member;
use SilverStripe\View\ArrayData;
@ -100,4 +101,14 @@ class ViewableDataContainsTest extends SapphireTest
$this->assertFalse($constraint->evaluate($item, '', true));
}
public function testFieldAccess()
{
$data = new TestObject(['name' => 'Damian']);
$constraint = new ViewableDataContains(['name' => 'Damian', 'Something' => 'something']);
$this->assertTrue($constraint->evaluate($data, '', true));
$constraint = new ViewableDataContains(['name' => 'Damian', 'Something' => 'notthing']);
$this->assertFalse($constraint->evaluate($data, '', true));
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace SilverStripe\Dev\Tests\ViewableDataContainsTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\View\ViewableData;
class TestObject extends ViewableData implements TestOnly
{
protected $data = null;
public function __construct($data)
{
$this->data = $data;
}
public function hasField($name)
{
return isset($this->data[$name]);
}
public function getField($name)
{
return isset($this->data[$name]) ?: null;
}
public function getSomething()
{
return 'something';
}
}