2009-12-02 10:40:38 +01:00
|
|
|
<?php
|
2016-06-23 01:37:22 +02:00
|
|
|
|
|
|
|
use SilverStripe\Security\GroupCsvBulkLoader;
|
|
|
|
use SilverStripe\Security\Group;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-12-02 10:40:38 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class GroupCsvBulkLoaderTest extends SapphireTest {
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'GroupCsvBulkLoaderTest.yml';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testNewImport() {
|
2009-12-02 10:40:38 +01:00
|
|
|
$loader = new GroupCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/GroupCsvBulkLoaderTest.csv');
|
2009-12-02 10:40:38 +01:00
|
|
|
$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);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testOverwriteExistingImport() {
|
2009-12-02 10:40:38 +01:00
|
|
|
$existinggroup = new Group();
|
|
|
|
$existinggroup->Title = 'Old Group Title';
|
|
|
|
$existinggroup->Code = 'newgroup1';
|
|
|
|
$existinggroup->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
$loader = new GroupCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/GroupCsvBulkLoaderTest.csv');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
$created = $results->Created()->toArray();
|
|
|
|
$this->assertEquals(count($created), 1);
|
|
|
|
$this->assertEquals($created[0]->Code, 'newchildgroup1');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
$updated = $results->Updated()->toArray();
|
|
|
|
$this->assertEquals(count($updated), 1);
|
|
|
|
$this->assertEquals($updated[0]->Code, 'newgroup1');
|
|
|
|
$this->assertEquals($updated[0]->Title, 'New Group 1');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testImportPermissions() {
|
2009-12-02 10:40:38 +01:00
|
|
|
$loader = new GroupCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/GroupCsvBulkLoaderTest_withExisting.csv');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
$created = $results->Created()->toArray();
|
|
|
|
$this->assertEquals(count($created), 1);
|
|
|
|
$this->assertEquals($created[0]->Code, 'newgroup1');
|
|
|
|
$this->assertEquals($created[0]->Permissions()->column('Code'), array('CODE1'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:38 +01:00
|
|
|
$updated = $results->Updated()->toArray();
|
|
|
|
$this->assertEquals(count($updated), 1);
|
|
|
|
$this->assertEquals($updated[0]->Code, 'existinggroup');
|
2010-10-13 02:46:44 +02:00
|
|
|
$array1=$updated[0]->Permissions()->column('Code');
|
|
|
|
$array2=array('CODE1', 'CODE2');
|
|
|
|
sort($array1);
|
|
|
|
sort($array2);
|
|
|
|
$this->assertEquals($array1, $array2);
|
2009-12-02 10:40:38 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|