mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
e2e32317d6
Also rename ViewableData to ModelData ahead of the template layer lift-and-shift
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Dev\Tests;
|
|
|
|
use SilverStripe\Dev\Constraint\SSListContains;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Model\List\ArrayList;
|
|
use SilverStripe\Security\Member;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
class SSListContainsTest extends SapphireTest
|
|
{
|
|
public static function provideMatchesForList()
|
|
{
|
|
return [
|
|
[
|
|
[['FirstName' => 'Ingo']]
|
|
],
|
|
[
|
|
[['Surname' => 'Minnee']]
|
|
],
|
|
[
|
|
[['FirstName' => 'Sam', 'Surname' => 'Minnee']]
|
|
],
|
|
[
|
|
[
|
|
['FirstName' => 'Sam', 'Surname' => 'Minnee'], //Sam Minee or Ingo
|
|
['FirstName' => 'Ingo']
|
|
]
|
|
],
|
|
];
|
|
}
|
|
|
|
|
|
public static function provideInvalidMatchesForList()
|
|
{
|
|
return [
|
|
[
|
|
[['FirstName' => 'AnyoneNotInList']]
|
|
],
|
|
[
|
|
[['Surname' => 'NotInList']]
|
|
],
|
|
[
|
|
[['FirstName' => 'Ingo', 'Surname' => 'Minnee']]
|
|
],
|
|
[
|
|
[
|
|
['FirstName' => 'Ingo', 'Surname' => 'Minnee'],
|
|
['FirstName' => 'NotInList']
|
|
]
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param $matches
|
|
*/
|
|
#[DataProvider('provideMatchesForList')]
|
|
public function testEvaluateListMatchesCorrectly($matches)
|
|
{
|
|
$constraint = new SSListContains($matches);
|
|
|
|
$this->assertTrue($constraint->evaluate($this->getListToMatch(), '', true));
|
|
}
|
|
|
|
/**
|
|
* @param $matches
|
|
*/
|
|
#[DataProvider('provideInvalidMatchesForList')]
|
|
public function testEvaluateListDoesNotMatchWrongMatches($matches)
|
|
{
|
|
$constraint = new SSListContains($matches);
|
|
|
|
$this->assertFalse($constraint->evaluate($this->getListToMatch(), '', true));
|
|
}
|
|
|
|
/**
|
|
* @return ArrayList<Member>
|
|
*/
|
|
private function getListToMatch()
|
|
{
|
|
$list = ArrayList::create();
|
|
$list->push(Member::create(['FirstName' => 'Ingo', 'Surname' => 'Schommer']));
|
|
$list->push(Member::create(['FirstName' => 'Sam', 'Surname' => 'Minnee']));
|
|
$list->push(Member::create(['FirstName' => 'Foo', 'Surname' => 'Bar']));
|
|
|
|
return $list;
|
|
}
|
|
}
|