-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDemoCest.php
76 lines (63 loc) · 2.41 KB
/
DemoCest.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
<?php
namespace Redmatter\Codeception\Tests;
use \AcceptanceTester;
use Faker\Factory as FakerFactory;
class DemoCest
{
private $faker;
public function __construct()
{
$this->faker = FakerFactory::create('en_GB');
}
public function demo(AcceptanceTester $I)
{
$I->amConnectedToDb('Primary');
list($organisation_id, $user_id) = $I->transaction(function () use ($I) {
$organisation_id = $this->createOrganisation($I);
$user_id = $this->createUser($I, ['OrganisationID' => $organisation_id]);
$this->createUserPassword($I, $user_id);
return [$organisation_id, $user_id];
});
$I->amConnectedToDb('Secondary');
$this->createAudit($I, $organisation_id, null, ['Description'=>'Organisation created']);
$this->createAudit($I, $organisation_id, $user_id, ['Description'=>'User created and password set']);
}
private function createOrganisation(AcceptanceTester $I, array $details = [])
{
return $I->haveInDb('DemoConfig.Organisation', array_merge([
'Name' => $this->faker->name.' & Co. Ltd.',
'Address' => str_replace("\n", ', ', $this->faker->address),
'Active' => 'YES'
], $details));
}
private function createUser(AcceptanceTester $I, array $details = [])
{
return $I->haveInDb('DemoConfig.User', array_merge([
'Name' => $this->faker->name,
'Email' => $this->faker->email,
'Address' => str_replace("\n", ', ', $this->faker->address),
'Active' => 'YES'
], $details));
}
private function createUserPassword(AcceptanceTester $I, $user_id, $password = null)
{
if ($password === null) {
$password = $this->faker->password;
}
$I->haveInDb('DemoConfig.UserPassword', [
'UserID' => $user_id,
'Hash' => sha1($password, true),
'CreatedAt' => '@asis NOW()',
'ExpiresAt' => '@asis DATE_ADD(NOW(), INTERVAL 1 WEEK)'
], 'UserID', $user_id);
}
private function createAudit(AcceptanceTester $I, $organisation_id, $user_id, array $data)
{
$I->haveInDb('DemoWarehouse.Audit', [
'OrganisationID'=>$organisation_id,
'UserID'=>$user_id,
'JSON'=>json_encode($data),
'Time'=>'@asis NOW()'
], 'OrganisationID', $organisation_id);
}
}