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

CreateCallQueue::testCreateCallQueue()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 75
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 45
c 0
b 0
f 0
dl 0
loc 75
rs 9.2
cc 4
nc 6
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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