Passed
Push — develop ( 6bfba2...d35452 )
by Nikolay
05:12
created

InstallModulesTest::testInstallModule()   B

Complexity

Conditions 6
Paths 90

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 34
rs 8.9297
cc 6
nc 90
nop 1
1
<?php
2
/**
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 5 2020
7
 *
8
 */
9
10
namespace MikoPBX\Tests\AdminCabinet\Tests;
11
12
13
use Exception;
14
use Facebook\WebDriver\Exception\NoSuchElementException;
15
use Facebook\WebDriver\WebDriverBy;
16
use MikoPBX\Tests\AdminCabinet\Lib\MikoPBXTestsBase as MikoPBXTestsBaseAlias;
17
18
class InstallModulesTest extends MikoPBXTestsBaseAlias
19
{
20
    /**
21
     * @depends testLogin
22
     * @dataProvider additionProvider
23
     *
24
     * @param array $params
25
     */
26
    public function testInstallModule(array $params): void
27
    {
28
        $this->clickSidebarMenuItemByHref("/admin-cabinet/pbx-extension-modules/index/");
29
30
        // Delete old module
31
        $xpath = '//tr[@id="'.$params['moduleId'].'"]//a[contains(@href,"delete")]';
32
        try {
33
            $tableButtonModify = self::$driver->findElement(WebDriverBy::xpath($xpath));
34
            $tableButtonModify->click();
35
            sleep(2);
36
            $tableButtonModify->click();
37
38
        } catch (NoSuchElementException $e) {
39
            echo('Not found row with module =' . $params['moduleId'] . ' on this page' . PHP_EOL);
40
        } catch (Exception $e) {
41
            echo('Unknown error ' . $e->getMessage() . PHP_EOL);
42
        }
43
        // Install new
44
45
        $xpath = '//a[contains(@data-uniqid,"'.$params['moduleId'].'")]';
46
        try {
47
            $tableButtonInstall = self::$driver->findElement(WebDriverBy::xpath($xpath));
48
            $tableButtonInstall->click();
49
        } catch (NoSuchElementException $e) {
50
            echo('Not found row with module =' . $params['moduleId'] . ' to install' . PHP_EOL);
51
        } catch (Exception $e) {
52
            echo('Unknown error ' . $e->getMessage() . PHP_EOL);
53
        }
54
55
        // assets
56
        $xpath = '//tr[@id="'.$params['moduleId'].'"]//a[contains(@href,"delete")]';
57
        $els = self::$driver->findElements((WebDriverBy::xpath($xpath)));
58
        if (count($els)===0) {
59
            $this->fail("Not found element by " .$xpath. PHP_EOL);
60
        }
61
62
    }
63
64
    public function additionProvider(): array
65
    {
66
        $params=[];
67
        $params[] = [[
68
            'moduleId'=>'ModuleAutoprovision',
69
        ]];
70
        $params[] = [[
71
            'moduleId'=>'ModuleBackup',
72
        ]];
73
        $params[] = [[
74
            'moduleId'=>'ModuleBitrix24Integration',
75
        ]];
76
        $params[] = [[
77
            'moduleId'=>'ModuleBitrix24Notify',
78
        ]];
79
        $params[] = [[
80
            'moduleId'=>'ModuleCallTracking',
81
        ]];
82
        $params[] = [[
83
            'moduleId'=>'ModuleCTIClient',
84
        ]];
85
        $params[] = [[
86
            'moduleId'=>'ModuleDocker',
87
        ]];
88
        $params[] = [[
89
            'moduleId'=>'ModulePhoneBook',
90
        ]];
91
        $params[] = [[
92
            'moduleId'=>'ModuleSmartIVR',
93
        ]];
94
        $params[] = [[
95
            'moduleId'=>'ModuleTelegramNotify',
96
        ]];
97
        $params[] = [[
98
            'moduleId'=>'ModuleUsersGroups',
99
        ]];
100
101
        return $params;
102
    }
103
}