mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix issue with assertListEquals() ignoring field getters
This commit is contained in:
parent
280222abbe
commit
34ac228029
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
31
tests/php/Dev/ViewableDataContainsTest/TestObject.php
Normal file
31
tests/php/Dev/ViewableDataContainsTest/TestObject.php
Normal 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';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user