Passed
Push — master ( 05c65b...4375aa )
by Franco
03:27 queued 02:09
created

UserInvitationTest::testIsExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class UserInvitationTest extends SapphireTest
0 ignored issues
show
Bug introduced by
The type SapphireTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public static $fixture_file = 'UserInvitationTest.yml';
6
7
    public function setUp()
8
    {
9
        parent::setUp();
10
    }
11
12
    /**
13
     * Tests that an invitation email was sent.
14
     */
15
    public function testSendInvitation()
16
    {
17
        Injector::inst()->registerService(new EmailTest_Mailer(), 'Mailer');
0 ignored issues
show
Bug introduced by
The type EmailTest_Mailer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Injector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
        /** @var UserInvitation $joe */
19
        $joe = $this->objFromFixture('UserInvitation', 'joe');
20
21
        $sent = $joe->sendInvitation();
22
        $this->assertEquals($joe->Email, $sent['to']);
23
        $this->assertEquals("Invitation from {$joe->InvitedBy()->FirstName}", $sent['subject']);
24
        $this->assertContains('Click here to accept this invitation', $sent['content']);
25
    }
26
27
    /**
28
     * Tests for expired invitations
29
     */
30
    public function testIsExpired()
31
    {
32
        /** @var UserInvitation $expired */
33
        $expired = $this->objFromFixture('UserInvitation', 'expired');
34
        $this->assertTrue($expired->isExpired());
35
    }
36
37
    /**
38
     * Tests that the TempHash field has been removed
39
     */
40
    public function testGetCMSFields()
41
    {
42
        /** @var UserInvitation $joe */
43
        $joe = $this->objFromFixture('UserInvitation', 'joe');
44
        $fields = $joe->getCMSFields();
45
        $this->assertNull($fields->dataFieldByName('TempHash'));
46
        $this->assertNotNull($fields->dataFieldByName('FirstName'));
47
        $this->assertNotNull($fields->dataFieldByName('Email'));
48
    }
49
50
    /**
51
     * Tests that invitations can't be re-sent.
52
     */
53 View Code Duplication
    public function testInvitationAlreadySent()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $invite = UserInvitation::create(array(
56
            'FirstName' => 'Joe',
57
            'Email' => '[email protected]'
58
        ));
59
        $result = $invite->validate();
60
        $this->assertFalse($result->valid());
61
        $this->assertEquals('This user was already sent an invite.', $result->message());
62
    }
63
64
    /**
65
     * Tests that duplicate members can't be created
66
     */
67 View Code Duplication
    public function testMemberAlreadyExists()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $invite = UserInvitation::create(array(
70
            'FirstName' => 'Jane',
71
            'Email' => '[email protected]'
72
        ));
73
        $result = $invite->validate();
74
        $this->assertFalse($result->valid());
75
        $this->assertEquals('This person is already a member of this system.', $result->message());
76
    }
77
78
    /**
79
     * Tests that a random hash and the logged in users id was added
80
     */
81
    public function testOnBeforeWrite()
82
    {
83
        $this->logInWithPermission('ADMIN');
84
        $invite = UserInvitation::create(array(
85
            'FirstName' => 'Dane',
86
            'Email' => '[email protected]'
87
        ));
88
        $invite->write();
89
        $this->assertNotNull($invite->TempHash);
90
        $this->assertNotNull($invite->InvitedByID);
91
    }
92
}
93