2010-02-22 05:37:32 +01:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\ORM\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class ComponentSetTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
|
|
|
protected static $fixture_file = 'ComponentSetTest.yml';
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
protected static $extra_dataobjects = [
|
2016-12-16 05:34:21 +01:00
|
|
|
ComponentSetTest\Player::class,
|
|
|
|
ComponentSetTest\Team::class,
|
2020-04-20 19:58:09 +02:00
|
|
|
];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
public function testSetByIDListManyMany()
|
|
|
|
{
|
|
|
|
$team1 = $this->objFromFixture(ComponentSetTest\Team::class, 'team1');
|
|
|
|
$player1_team1 = $this->objFromFixture(ComponentSetTest\Player::class, 'player1_team1');
|
|
|
|
$player2 = $this->objFromFixture(ComponentSetTest\Player::class, 'player2');
|
2010-02-22 05:37:32 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$team1->Players()->setByIdList(
|
2020-04-20 19:58:09 +02:00
|
|
|
[
|
2016-12-16 05:34:21 +01:00
|
|
|
$player1_team1->ID,
|
|
|
|
$player2->ID
|
2020-04-20 19:58:09 +02:00
|
|
|
]
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
$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(
|
2020-04-20 19:58:09 +02:00
|
|
|
[
|
2016-12-16 05:34:21 +01:00
|
|
|
$player1_team1->ID
|
2020-04-20 19:58:09 +02:00
|
|
|
]
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
$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'
|
|
|
|
);
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
$team1->Players()->setByIdList([]);
|
2016-12-16 05:34:21 +01:00
|
|
|
$team1->flushCache();
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
$team1->Players()->Count(),
|
|
|
|
'Can remove all entries by passing an empty array'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|