2016-05-31 23:55:06 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Dev\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\BulkLoader_Result;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-10-14 03:30:05 +02:00
|
|
|
use SilverStripe\Dev\Tests\BulkLoaderResultTest\Player;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-05-31 23:55:06 +02:00
|
|
|
class BulkLoaderResultTest extends SapphireTest
|
|
|
|
{
|
2016-10-14 03:30:05 +02:00
|
|
|
protected $extraDataObjects = array(Player::class);
|
2016-05-31 23:55:06 +02:00
|
|
|
|
2017-03-24 04:00:54 +01:00
|
|
|
protected function setUp()
|
2016-05-31 23:55:06 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2016-10-14 03:30:05 +02:00
|
|
|
Player::create(array('Name' => 'Vincent', 'Status' => 'Available'))->write();
|
2016-05-31 23:55:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testBulkLoaderResultCreated()
|
|
|
|
{
|
|
|
|
$results = BulkLoader_Result::create();
|
2016-10-14 03:30:05 +02:00
|
|
|
$player = Player::create(array('Name' => 'Rangi', 'Status' => 'Possible'));
|
2016-05-31 23:55:06 +02:00
|
|
|
$player->write();
|
|
|
|
$results->addCreated($player, 'Speedster');
|
|
|
|
|
|
|
|
$this->assertEquals($results->CreatedCount(), 1);
|
|
|
|
$this->assertSame(
|
|
|
|
'Rangi',
|
|
|
|
$results->Created()->find('Name', 'Rangi')->Name,
|
|
|
|
'The player Rangi should be recorded as created in $results'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
'Possible',
|
|
|
|
$results->Created()->find('Name', 'Rangi')->Status,
|
|
|
|
'The player Rangi should have Status of "Possible" in $results'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
'Speedster',
|
|
|
|
$results->Created()->find('Name', 'Rangi')->_BulkLoaderMessage,
|
|
|
|
'Rangi should have _BulkLoaderMessage of Speedster'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBulkLoaderResultDeleted()
|
|
|
|
{
|
|
|
|
$results = BulkLoader_Result::create();
|
2016-10-14 03:30:05 +02:00
|
|
|
$player = Player::get()->find('Name', 'Vincent');
|
2016-05-31 23:55:06 +02:00
|
|
|
$results->addDeleted($player, 'Retired');
|
|
|
|
$player->delete();
|
|
|
|
|
|
|
|
$this->assertEquals($results->DeletedCount(), 1);
|
|
|
|
$this->assertSame(
|
|
|
|
'Vincent',
|
|
|
|
$results->Deleted()->find('Name', 'Vincent')->Name,
|
|
|
|
'The player Vincent should be recorded as deleted'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
'Retired',
|
|
|
|
$results->Deleted()->find('Name', 'Vincent')->_BulkLoaderMessage,
|
|
|
|
'Vincent should have a _BulkLoaderMessage of Retired'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBulkLoaderResultUpdated()
|
|
|
|
{
|
|
|
|
$results = BulkLoader_Result::create();
|
2016-10-14 03:30:05 +02:00
|
|
|
$player = Player::get()->find('Name', 'Vincent');
|
2016-05-31 23:55:06 +02:00
|
|
|
$player->Status = 'Unavailable';
|
|
|
|
$player->write();
|
|
|
|
$results->addUpdated($player, 'Injured');
|
|
|
|
|
|
|
|
$this->assertEquals($results->UpdatedCount(), 1);
|
|
|
|
$this->assertSame(
|
|
|
|
'Vincent',
|
|
|
|
$results->Updated()->find('Name', 'Vincent')->Name,
|
|
|
|
'The player Vincent should be recorded as updated'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
'Unavailable',
|
|
|
|
$results->Updated()->find('Name', 'Vincent')->Status,
|
|
|
|
'The player Vincent should have a Status of Unavailable'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
'Injured',
|
|
|
|
$results->Updated()->find('Name', 'Vincent')->_BulkLoaderMessage,
|
|
|
|
'Vincent is injured'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|