-
Notifications
You must be signed in to change notification settings - Fork 821
/
MemberCsvBulkLoaderTest.php
77 lines (62 loc) · 2.95 KB
/
MemberCsvBulkLoaderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* @package framework
* @subpackage tests
*/
class MemberCsvBulkLoaderTest extends SapphireTest {
static $fixture_file = 'MemberCsvBulkLoaderTest.yml';
function testNewImport() {
$loader = new MemberCsvBulkLoader();
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
$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');
}
function testOverwriteExistingImport() {
$author1 = new Member();
$author1->FirstName = 'author1_first_old';
$author1->Email = 'author1@test.com';
$author1->write();
$loader = new MemberCsvBulkLoader();
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
$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');
}
function testAddToPredefinedGroups() {
$existinggroup = $this->objFromFixture('Group', 'existinggroup');
$loader = new MemberCsvBulkLoader();
$loader->setGroups(array($existinggroup));
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest.csv');
$created = $results->Created()->toArray();
$this->assertEquals($created[0]->Groups()->column('ID'), array($existinggroup->ID));
$this->assertEquals($created[1]->Groups()->column('ID'), array($existinggroup->ID));
}
function testAddToCsvColumnGroupsByCode() {
$existinggroup = $this->objFromFixture('Group', 'existinggroup');
$loader = new MemberCsvBulkLoader();
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_withGroups.csv');
$newgroup = DataObject::get_one('Group', sprintf('"Code" = \'%s\'', 'newgroup'));
$this->assertEquals($newgroup->Title, 'newgroup');
$created = $results->Created()->toArray();
$this->assertEquals($created[0]->Groups()->column('ID'), array($existinggroup->ID));
$this->assertEquals($created[1]->Groups()->column('ID'), array($existinggroup->ID, $newgroup->ID));
}
function testCleartextPasswordsAreHashedWithDefaultAlgo() {
$loader = new MemberCsvBulkLoader();
$results = $loader->load($this->getCurrentRelativePath() . '/MemberCsvBulkLoaderTest_cleartextpws.csv');
$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!
$this->assertEquals(Security::get_password_encryption_algorithm(), $member->getField('PasswordEncryption'));
$result = $member->checkPassword('mypassword');
$this->assertTrue($result->valid());
}
}