Passed
Pull Request — master (#5)
by Robbie
02:50 queued 32s
created

testPasswordSentMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace SilverStripe\LDAP\Tests\Authenticators;
4
5
use SilverStripe\Control\HTTPRequest;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\Form;
9
use SilverStripe\LDAP\Authenticators\LDAPAuthenticator;
10
use SilverStripe\LDAP\Authenticators\LDAPLostPasswordHandler;
11
use SilverStripe\LDAP\Services\LDAPService;
12
use SilverStripe\ORM\FieldType\DBField;
13
14
class LDAPLostPasswordHandlerTest extends SapphireTest
15
{
16
    /**
17
     * @var LDAPLostPasswordHandler
18
     */
19
    protected $handler;
20
21
    protected function setUp()
22
    {
23
        parent::setUp();
24
25
        $authenticator = new LDAPAuthenticator;
26
        $this->handler = LDAPLostPasswordHandler::create('foo', $authenticator);
0 ignored issues
show
Bug introduced by
'foo' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $this->handler = LDAPLostPasswordHandler::create(/** @scrutinizer ignore-type */ 'foo', $authenticator);
Loading history...
Bug introduced by
$authenticator of type SilverStripe\LDAP\Authenticators\LDAPAuthenticator is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $this->handler = LDAPLostPasswordHandler::create('foo', /** @scrutinizer ignore-type */ $authenticator);
Loading history...
27
    }
28
29
    public function testGetAndSetLdapService()
30
    {
31
        $service = new LDAPService;
32
33
        $this->handler->setService($service);
34
        $this->assertSame($service, $this->handler->getService());
35
    }
36
37
    public function testLostPasswordFormLabels()
38
    {
39
        Config::modify()->set(LDAPAuthenticator::class, 'allow_email_login', 'no');
40
        $result = $this->handler->lostpassword();
41
42
        $this->assertInternalType('array', $result);
43
        $this->assertInstanceOf(DBField::class, $result['Content']);
44
        $this->assertInstanceOf(Form::class, $result['Form']);
45
        $this->assertContains('Enter your username and we will send you a link', $result['Content']->getValue());
46
47
        Config::modify()->set(LDAPAuthenticator::class, 'allow_email_login', 'yes');
48
        $result = $this->handler->lostpassword();
49
        $this->assertInternalType('array', $result);
50
        $this->assertContains('Enter your username or your email address', $result['Content']->getValue());
51
    }
52
53
    public function testPasswordSentMessage()
54
    {
55
        $request = (new HTTPRequest('GET', '/'))->setRouteParams(['OtherID' => 'banana']);
56
57
        $this->handler->setRequest($request);
58
59
        $result = $this->handler->passwordsent();
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
60
61
        $this->assertSame([
62
            'Title' => "Password reset link sent to 'banana'",
63
            'Content' => "Thank you! A reset link has been sent to 'banana', provided an account exists.",
64
            'Username' => 'banana'
65
        ], $this->handler->passwordsent());
66
    }
67
}
68