Passed
Push — develop ( cc5787...6bfba2 )
by Nikolay
05:46
created

ChangeCallQueueTest::additionProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 29
rs 9.568
cc 1
nc 1
nop 0
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, 8 2020
7
 *
8
 */
9
10
namespace MikoPBX\Tests\AdminCabinet\Tests;
11
12
13
use Facebook\WebDriver\WebDriverBy;
14
use MikoPBX\Tests\AdminCabinet\Lib\MikoPBXTestsBase;
15
16
class ChangeCallQueueTest extends MikoPBXTestsBase
17
{
18
    /**
19
     * @depends      testLogin
20
     * @dataProvider additionProvider
21
     *
22
     * @param array $params ;
23
     */
24
    public function testChangeCallQueueExtension($params): void
25
    {
26
        $this->clickSidebarMenuItemByHref('/admin-cabinet/call-queues/index/');
27
        $this->clickModifyButtonOnRowWithText($params['OldExtension']);
28
        $this->changeTextAreaValue('description', $params['description']);
29
        $this->changeInputField('name', $params['name']);
30
31
        // Удаляем старых агентов
32
        $xpath         = ('//div[contains(@class,"delete-row-button")]');
33
        $deleteButtons = self::$driver->findElements(WebDriverBy::xpath($xpath));
34
        foreach ($deleteButtons as $deleteButton) {
35
            $deleteButton->click();
36
            sleep(2);
37
        }
38
39
        // Добавляем агентов очереди
40
        foreach ($params['agents'] as $agent) {
41
            $this->selectDropdownItem('extensionselect', $agent);
42
        }
43
44
        $this->selectDropdownItem('strategy', $params['strategy']);
45
46
        // Раскрываем расширенные опции
47
        $this->openAccordionOnThePage();
48
49
        // Заполняем поля из базы данных с исходными данными
50
        $this->changeInputField('extension', $params['extension']);
51
        $this->changeInputField('seconds_to_ring_each_member', $params['seconds_to_ring_each_member']);
52
        $this->changeInputField('seconds_for_wrapup', $params['seconds_for_wrapup']);
53
        $this->changeCheckBoxState('recive_calls_while_on_a_call', $params['recive_calls_while_on_a_call']);
54
55
        $this->selectDropdownItem('caller_hear', $params['caller_hear']);
56
        $this->changeCheckBoxState('announce_position', $params['announce_position']);
57
        $this->changeCheckBoxState('announce_hold_time', $params['announce_hold_time']);
58
59
        $this->selectDropdownItem('periodic_announce_sound_id', $params['periodic_announce_sound_id']);
60
61
        $this->changeInputField('periodic_announce_frequency', $params['periodic_announce_frequency']);
62
        $this->changeInputField('timeout_to_redirect_to_extension', $params['timeout_to_redirect_to_extension']);
63
64
        $this->selectDropdownItem('timeout_extension', $params['timeout_extension']);
65
        $this->selectDropdownItem('redirect_to_extension_if_empty', $params['redirect_to_extension_if_empty']);
66
67
        $this->submitForm('queue-form');
68
        $this->clickSidebarMenuItemByHref('/admin-cabinet/call-queues/index/');
69
70
        $this->clickModifyButtonOnRowWithText($params['name']);
71
        $this->assertInputFieldValueEqual('name', $params['name']);
72
        $this->assertInputFieldValueEqual('extension', $params['extension']);
73
        $this->assertTextAreaValueIsEqual('description', $params['description']);
74
75
        // Обойдем всех членов очереди, проверим что они есть
76
        foreach ($params['agents'] as $agent) {
77
            $xpath   = '//table[@id="extensionsTable"]//td[contains(text(), "' . $agent . '")]';
78
            $members = self::$driver->findElements(WebDriverBy::xpath($xpath));
79
            if (count($members) === 0) {
80
                $this->assertTrue(false, 'Not found agent ' . $agent . ' in queue agents list');
81
            }
82
        }
83
        $this->assertMenuItemSelected('strategy', $params['strategy']);
84
85
        // Раскрываем расширенные опции
86
        $this->openAccordionOnThePage();
87
88
        $this->assertInputFieldValueEqual('seconds_to_ring_each_member', $params['seconds_to_ring_each_member']);
89
        $this->assertInputFieldValueEqual('seconds_for_wrapup', $params['seconds_for_wrapup']);
90
        $this->assertCheckBoxStageIsEqual('recive_calls_while_on_a_call', $params['recive_calls_while_on_a_call']);
91
92
        $this->assertMenuItemSelected('caller_hear', $params['caller_hear']);
93
        $this->assertCheckBoxStageIsEqual('announce_position', $params['announce_position']);
94
        $this->assertCheckBoxStageIsEqual('announce_hold_time', $params['announce_hold_time']);
95
96
        $this->assertMenuItemSelected('periodic_announce_sound_id', $params['periodic_announce_sound_id']);
97
98
        $this->assertInputFieldValueEqual('periodic_announce_frequency', $params['periodic_announce_frequency']);
99
        $this->assertInputFieldValueEqual(
100
            'timeout_to_redirect_to_extension',
101
            $params['timeout_to_redirect_to_extension']
102
        );
103
104
        $this->assertMenuItemSelected('timeout_extension', $params['timeout_extension']);
105
        $this->assertMenuItemSelected('redirect_to_extension_if_empty', $params['redirect_to_extension_if_empty']);
106
    }
107
108
    /**
109
     * Dataset provider
110
     *
111
     * @return array
112
     */
113
    public function additionProvider(): array
114
    {
115
        $params   = [];
116
        $params[] = [
117
            [
118
                'description'                      => 'Sales department queue, the first line of agents2',
119
                'name'                             => 'Sales department2',
120
                'OldExtension'                     => 20020,
121
                'extension'                        => 20021,
122
                'seconds_to_ring_each_member'      => 15,
123
                'seconds_for_wrapup'               => 14,
124
                'recive_calls_while_on_a_call'     => false,
125
                'caller_hear'                      => 'moh',
126
                'announce_position'                => false,
127
                'announce_hold_time'               => true,
128
                'periodic_announce_sound_id'       => '1',
129
                'periodic_announce_frequency'      => 25,
130
                'timeout_to_redirect_to_extension' => 19,
131
                'timeout_extension'                => '202',
132
                'redirect_to_extension_if_empty'   => '201',
133
                'agents'                           => [
134
                    '202',
135
                    '203',
136
                ],
137
                'strategy'                         => 'random',
138
            ],
139
        ];
140
141
        return $params;
142
    }
143
}