mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Added ComponentSetTest (from r99580)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99654 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4a6acf6e35
commit
f44b9941ed
75
tests/model/ComponentSetTest.php
Normal file
75
tests/model/ComponentSetTest.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package sapphire
|
||||||
|
* @subpackage tests
|
||||||
|
*/
|
||||||
|
class ComponentSetTest extends SapphireTest {
|
||||||
|
|
||||||
|
static $fixture_file = 'sapphire/tests/model/ComponentSetTest.yml';
|
||||||
|
|
||||||
|
protected $extraDataObjects = array(
|
||||||
|
'ComponentSetTest_Player',
|
||||||
|
'ComponentSetTest_Team'
|
||||||
|
);
|
||||||
|
|
||||||
|
function testSetByIDListManyMany() {
|
||||||
|
$team1 = $this->objFromFixture('ComponentSetTest_Team', 'team1');
|
||||||
|
$player1_team1 = $this->objFromFixture('ComponentSetTest_Player', 'player1_team1');
|
||||||
|
$player2 = $this->objFromFixture('ComponentSetTest_Player', 'player2');
|
||||||
|
|
||||||
|
$team1->Players()->setByIdList(array(
|
||||||
|
$player1_team1->ID,
|
||||||
|
$player2->ID
|
||||||
|
));
|
||||||
|
$team1->flushCache();
|
||||||
|
$this->assertContains(
|
||||||
|
$player2->ID,
|
||||||
|
$team1->Players()->column('ID'),
|
||||||
|
'Can add new entry'
|
||||||
|
);
|
||||||
|
$this->assertContains(
|
||||||
|
$player1_team1->ID,
|
||||||
|
$team1->Players()->column('ID'),
|
||||||
|
'Can retain existing entry'
|
||||||
|
);
|
||||||
|
|
||||||
|
$team1->Players()->setByIdList(array(
|
||||||
|
$player1_team1->ID
|
||||||
|
));
|
||||||
|
$team1->flushCache();
|
||||||
|
$this->assertNotContains(
|
||||||
|
$player2->ID,
|
||||||
|
$team1->Players()->column('ID'),
|
||||||
|
'Can remove existing entry'
|
||||||
|
);
|
||||||
|
$this->assertContains(
|
||||||
|
$player1_team1->ID,
|
||||||
|
$team1->Players()->column('ID'),
|
||||||
|
'Can retain existing entry'
|
||||||
|
);
|
||||||
|
|
||||||
|
$team1->Players()->setByIdList(array());
|
||||||
|
$team1->flushCache();
|
||||||
|
$this->assertEquals(0, $team1->Players()->Count(),
|
||||||
|
'Can remove all entries by passing an empty array'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ComponentSetTest_Player extends Member implements TestOnly {
|
||||||
|
static $belongs_many_many = array(
|
||||||
|
'Teams' => 'ComponentSetTest_Team'
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class ComponentSetTest_Team extends DataObject implements TestOnly {
|
||||||
|
|
||||||
|
static $db = array(
|
||||||
|
'Title' => 'Varchar',
|
||||||
|
);
|
||||||
|
|
||||||
|
static $many_many = array(
|
||||||
|
'Players' => 'ComponentSetTest_Player'
|
||||||
|
);
|
||||||
|
}
|
9
tests/model/ComponentSetTest.yml
Normal file
9
tests/model/ComponentSetTest.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
ComponentSetTest_Player:
|
||||||
|
player1_team1:
|
||||||
|
Email: player1_team1@test.com
|
||||||
|
player2:
|
||||||
|
Email: player2@test.com
|
||||||
|
ComponentSetTest_Team:
|
||||||
|
team1:
|
||||||
|
Title: team1
|
||||||
|
Players: =>ComponentSetTest_Player.player1_team1
|
Loading…
x
Reference in New Issue
Block a user