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

LoginContext::iSelectFromTheMfaSettings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
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