Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 13... Línea 13...
13
//
13
//
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
17
namespace tool_mfa;
-
 
18
use tool_mfa\tool_mfa_trait;
-
 
19
 
-
 
20
defined('MOODLE_INTERNAL') || die();
-
 
Línea 21... Línea 17...
21
require_once(__DIR__ . '/tool_mfa_trait.php');
17
namespace tool_mfa;
22
 
18
 
23
/**
19
/**
24
 * Tests for MFA admin settings
20
 * Tests for MFA admin settings
25
 *
21
 *
26
 * @package     tool_mfa
22
 * @package     tool_mfa
27
 * @author      Mikhail Golenkov <golenkovm@gmail.com>
23
 * @author      Mikhail Golenkov <golenkovm@gmail.com>
28
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
24
 * @author      Peter Burnett <peterburnett@catalyst-au.net>
-
 
25
 * @copyright   Catalyst IT
-
 
26
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @copyright   Catalyst IT
27
 *
30
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @covers \tool_mfa\table\admin_setting_managemfa
Línea 31... Línea 29...
31
 */
29
 */
-
 
30
final class admin_setting_managemfa_test extends \advanced_testcase {
-
 
31
 
-
 
32
    use \tool_mfa\tests\mfa_settings_trait;
-
 
33
 
-
 
34
    /**
-
 
35
     * Setup testcase.
-
 
36
     */
-
 
37
    public function setUp(): void {
-
 
38
        parent::setUp();
-
 
39
        $this->resetAfterTest();
Línea 32... Línea 40...
32
class admin_setting_managemfa_test extends \advanced_testcase {
40
        // Disable email factor (enabled by default).
33
 
41
        $this->set_factor_state('email', 0);
34
    use tool_mfa_trait;
-
 
35
 
-
 
36
    /**
42
    }
37
     * Tests getting the factor combinations
43
 
38
     *
44
    /**
39
     * @covers ::get_factor_combinations
45
     * Tests getting the factor combinations
40
     */
46
     */
41
    public function test_get_factor_combinations_default(): void {
47
    public function test_get_factor_combinations_default(): void {
42
        $namagemfa = new \tool_mfa\local\admin_setting_managemfa();
48
        $namagemfa = new \tool_mfa\table\admin_setting_managemfa();
43
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
49
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
Línea 49... Línea 55...
49
    /**
55
    /**
50
     * Data provider for test_get_factor_combinations_with_data_provider().
56
     * Data provider for test_get_factor_combinations_with_data_provider().
51
     *
57
     *
52
     * @return array
58
     * @return array
53
     */
59
     */
54
    public function get_factor_combinations_provider() {
60
    public static function get_factor_combinations_provider(): array {
55
        $provider = [];
61
        $provider = [];
Línea 56... Línea 62...
56
 
62
 
57
        $factors = [];
63
        $factors = [];
Línea 134... Línea 140...
134
    }
140
    }
Línea 135... Línea 141...
135
 
141
 
136
    /**
142
    /**
137
     * Tests getting the factor combinations with data provider
143
     * Tests getting the factor combinations with data provider
138
     *
-
 
139
     * @covers ::get_factor_combinations
144
     *
140
     * @dataProvider get_factor_combinations_provider
145
     * @dataProvider get_factor_combinations_provider
141
     * @param array $factorset configured factors
146
     * @param array $factorset configured factors
142
     * @param int $combinationscount expected count of available combinations
147
     * @param int $combinationscount expected count of available combinations
143
     */
148
     */
144
    public function test_get_factor_combinations_with_data_provider($factorset, $combinationscount): void {
-
 
145
        $this->resetAfterTest();
149
    public function test_get_factor_combinations_with_data_provider(array $factorset, int $combinationscount): void {
Línea 146... Línea 150...
146
        $enabledcount = 0;
150
        $enabledcount = 0;
147
 
151
 
148
        foreach ($factorset as $factor) {
152
        foreach ($factorset as $factor) {
149
            $this->set_factor_state($factor['name'], $factor['enabled'], $factor['weight']);
153
            $this->set_factor_state($factor['name'], $factor['enabled'], $factor['weight']);
150
            if ($factor['enabled'] == 1) {
154
            if ($factor['enabled'] == 1) {
151
                $enabledcount++;
155
                $enabledcount++;
Línea 152... Línea 156...
152
            }
156
            }
153
        }
157
        }
154
 
158
 
Línea 155... Línea 159...
155
        $managemfa = new \tool_mfa\local\admin_setting_managemfa();
159
        $managemfa = new \tool_mfa\table\admin_setting_managemfa();
156
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
160
        $factors = \tool_mfa\plugininfo\factor::get_enabled_factors();
Línea 169... Línea 173...
169
        $this->assertEquals($combinationscount, count($combinations));
173
        $this->assertEquals($combinationscount, count($combinations));
170
    }
174
    }
Línea 171... Línea 175...
171
 
175
 
172
    /**
176
    /**
173
     * Tests checking the factor combinations
-
 
174
     *
-
 
175
     * @covers ::get_factor_combinations
177
     * Tests checking the factor combinations
176
     */
178
     */
177
    public function test_factor_combination_checker(): void {
-
 
178
        $this->resetAfterTest();
179
    public function test_factor_combination_checker(): void {
179
        $managemfa = new \tool_mfa\local\admin_setting_managemfa();
180
        $managemfa = new \tool_mfa\table\admin_setting_managemfa();
180
        $user = $this->getDataGenerator()->create_user();
181
        $user = $this->getDataGenerator()->create_user();
Línea 181... Línea 182...
181
        $this->setUser($user);
182
        $this->setUser($user);
182
 
183