Completed
Push — master ( 284e53...2c3a07 )
by Guy
13s queued 11s
created

LoginContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 29
rs 10
c 3
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A multiFactorAuthenticationIsOptional() 0 8 1
A iSelectFromTheMfaSettings() 0 4 2
A iAmLoggedInWithPermissions() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace SilverStripe\MFA\Tests\Behat\Context;
4
5
use SilverStripe\CMS\Tests\Behaviour\LoginContext as CMSLoginContext;
0 ignored issues
show
Bug introduced by
The type SilverStripe\CMS\Tests\Behaviour\LoginContext 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...
6
use SilverStripe\MFA\Extension\SiteConfigExtension;
7
use SilverStripe\SiteConfig\SiteConfig;
8
9
/**
10
 * Overridden from the CMS module to ensure that MFA can be handled during fixtured member generation
11
 */
12
class LoginContext extends CMSLoginContext
13
{
14
    public function iAmLoggedInWithPermissions($permCode)
15
    {
16
        // Set MFA to optional, perform login logic, then skip MFA
17
        $this->multiFactorAuthenticationIsOptional();
18
        parent::iAmLoggedInWithPermissions($permCode);
19
    }
20
21
    /**
22
     * @Given multi factor authentication is optional
23
     */
24
    public function multiFactorAuthenticationIsOptional()
25
    {
26
        /** @var SiteConfig&SiteConfigExtension $siteConfig */
27
        $siteConfig = SiteConfig::current_site_config();
28
        assertNotNull($siteConfig, 'Current SiteConfig record could not be found!');
29
30
        $siteConfig->MFARequired = false;
31
        $siteConfig->write();
32
    }
33
34
    /**
35
     * @When I select :option from the MFA settings
36
     */
37
    public function iSelectFromTheMfaSettings($option)
38
    {
39
        $value = $option === 'MFA is required for everyone' ? 1 : 0;
40
        $this->getMainContext()->selectOption('MFARequired', $value);
41
    }
42
}
43