silverstripe-framework/tests/security/GroupCsvBulkLoaderTest.php
Ingo Schommer 6b556ef90d ENHANCEMENT Added GroupCsvBulkLoader class to facilitate group imports with permission codes and hierarchy (merged from r94252)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98715 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:18:30 +13:00

54 lines
1.9 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage tests
*/
class GroupCsvBulkLoaderTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/security/GroupCsvBulkLoaderTest.yml';
function testNewImport() {
$loader = new GroupCsvBulkLoader();
$results = $loader->load('sapphire/tests/security/GroupCsvBulkLoaderTest.csv');
$created = $results->Created()->toArray();
$this->assertEquals(count($created), 2);
$this->assertEquals($created[0]->Code, 'newgroup1');
$this->assertEquals($created[0]->ParentID, 0);
$this->assertEquals($created[1]->Code, 'newchildgroup1');
$this->assertEquals($created[1]->ParentID, $created[0]->ID);
}
function testOverwriteExistingImport() {
$existinggroup = new Group();
$existinggroup->Title = 'Old Group Title';
$existinggroup->Code = 'newgroup1';
$existinggroup->write();
$loader = new GroupCsvBulkLoader();
$results = $loader->load('sapphire/tests/security/GroupCsvBulkLoaderTest.csv');
$created = $results->Created()->toArray();
$this->assertEquals(count($created), 1);
$this->assertEquals($created[0]->Code, 'newchildgroup1');
$updated = $results->Updated()->toArray();
$this->assertEquals(count($updated), 1);
$this->assertEquals($updated[0]->Code, 'newgroup1');
$this->assertEquals($updated[0]->Title, 'New Group 1');
}
function testImportPermissions() {
$loader = new GroupCsvBulkLoader();
$results = $loader->load('sapphire/tests/security/GroupCsvBulkLoaderTest_withExisting.csv');
$created = $results->Created()->toArray();
$this->assertEquals(count($created), 1);
$this->assertEquals($created[0]->Code, 'newgroup1');
$this->assertEquals($created[0]->Permissions()->column('Code'), array('CODE1'));
$updated = $results->Updated()->toArray();
$this->assertEquals(count($updated), 1);
$this->assertEquals($updated[0]->Code, 'existinggroup');
$this->assertEquals($updated[0]->Permissions()->column('Code'), array('CODE1', 'CODE2'));
}
}