2009-12-02 10:40:33 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-12-02 10:40:33 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class MemberCsvBulkLoaderTest extends SapphireTest {
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'MemberCsvBulkLoaderTest.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:33 +01:00
|
|
|
$loader = new MemberCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
|
2009-12-02 10:40:33 +01:00
|
|
|
$created = $results->Created()->toArray();
|
|
|
|
$this->assertEquals(count($created), 2);
|
|
|
|
$this->assertEquals($created[0]->Email, 'author1@test.com');
|
|
|
|
$this->assertEquals($created[1]->Email, 'author2@test.com');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testOverwriteExistingImport() {
|
2009-12-02 10:40:33 +01:00
|
|
|
$author1 = new Member();
|
|
|
|
$author1->FirstName = 'author1_first_old';
|
|
|
|
$author1->Email = 'author1@test.com';
|
|
|
|
$author1->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:33 +01:00
|
|
|
$loader = new MemberCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
|
2009-12-02 10:40:33 +01:00
|
|
|
$created = $results->Created()->toArray();
|
|
|
|
$this->assertEquals(count($created), 1);
|
|
|
|
$updated = $results->Updated()->toArray();
|
|
|
|
$this->assertEquals(count($updated), 1);
|
|
|
|
$this->assertEquals($created[0]->Email, 'author2@test.com');
|
|
|
|
$this->assertEquals($updated[0]->Email, 'author1@test.com');
|
|
|
|
$this->assertEquals($updated[0]->FirstName, 'author1_first');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testAddToPredefinedGroups() {
|
2009-12-02 10:40:33 +01:00
|
|
|
$existinggroup = $this->objFromFixture('Group', 'existinggroup');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:33 +01:00
|
|
|
$loader = new MemberCsvBulkLoader();
|
|
|
|
$loader->setGroups(array($existinggroup));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:33 +01:00
|
|
|
$created = $results->Created()->toArray();
|
2013-07-04 22:46:23 +02:00
|
|
|
$this->assertEquals(1, count($created[0]->Groups()->column('ID')));
|
|
|
|
$this->assertContains($existinggroup->ID, $created[0]->Groups()->column('ID'));
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($created[1]->Groups()->column('ID')));
|
|
|
|
$this->assertContains($existinggroup->ID, $created[1]->Groups()->column('ID'));
|
2009-12-02 10:40:33 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testAddToCsvColumnGroupsByCode() {
|
2009-12-02 10:40:33 +01:00
|
|
|
$existinggroup = $this->objFromFixture('Group', 'existinggroup');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:33 +01:00
|
|
|
$loader = new MemberCsvBulkLoader();
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_withGroups.csv');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-06-21 00:32:08 +02:00
|
|
|
$newgroup = DataObject::get_one('Group', array(
|
|
|
|
'"Group"."Code"' => 'newgroup'
|
|
|
|
));
|
2009-12-02 10:40:33 +01:00
|
|
|
$this->assertEquals($newgroup->Title, 'newgroup');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-12-02 10:40:33 +01:00
|
|
|
$created = $results->Created()->toArray();
|
2013-07-04 22:46:23 +02:00
|
|
|
$this->assertEquals(1, count($created[0]->Groups()->column('ID')));
|
|
|
|
$this->assertContains($existinggroup->ID, $created[0]->Groups()->column('ID'));
|
|
|
|
|
|
|
|
$this->assertEquals(2, count($created[1]->Groups()->column('ID')));
|
|
|
|
$this->assertContains($existinggroup->ID, $created[1]->Groups()->column('ID'));
|
|
|
|
$this->assertContains($newgroup->ID, $created[1]->Groups()->column('ID'));
|
2009-12-02 10:40:33 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCleartextPasswordsAreHashedWithDefaultAlgo() {
|
2010-02-12 01:58:10 +01:00
|
|
|
$loader = new MemberCsvBulkLoader();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_cleartextpws.csv');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-02-12 01:58:10 +01:00
|
|
|
$member = $results->Created()->First();
|
|
|
|
$memberID = $member->ID;
|
|
|
|
DataObject::flush_and_destroy_cache();
|
|
|
|
$member = DataObject::get_by_id('Member', $memberID);
|
|
|
|
|
|
|
|
// TODO Direct getter doesn't work, wtf!
|
2013-03-21 19:48:54 +01:00
|
|
|
$this->assertEquals(Security::config()->password_encryption_algorithm, $member->getField('PasswordEncryption'));
|
2010-02-12 01:58:10 +01:00
|
|
|
$result = $member->checkPassword('mypassword');
|
|
|
|
$this->assertTrue($result->valid());
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|