1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\ticket\tests\_support\Page\ticket; |
4
|
|
|
|
5
|
|
|
use hipanel\tests\_support\AcceptanceTester; |
6
|
|
|
use hipanel\tests\_support\Page\Authenticated; |
7
|
|
|
use yii\helpers\Url; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class View |
11
|
|
|
* |
12
|
|
|
* @author Dmytro Naumenko <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class View extends Authenticated |
15
|
|
|
{ |
16
|
|
|
const THREAD_ID_SELECTOR = '.leave-comment-form input[name="Thread[id]"]'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string|int |
20
|
|
|
*/ |
21
|
|
|
private $ticketId; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* View constructor. |
25
|
|
|
* @param \AcceptanceTester $I |
26
|
|
|
* @param string|int $ticketId |
27
|
|
|
*/ |
28
|
|
|
public function __construct(AcceptanceTester $I, $ticketId) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($I); |
31
|
|
|
|
32
|
|
|
$this->ticketId = $ticketId; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function visitTicket() |
36
|
|
|
{ |
37
|
|
|
$I = $this->tester; |
38
|
|
|
|
39
|
|
|
$I->amOnPage(Url::to(['@ticket/view', 'id' => $this->ticketId])); |
40
|
|
|
$I->seeInField(self::THREAD_ID_SELECTOR, $this->ticketId); |
41
|
|
|
|
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function postComment($message) |
46
|
|
|
{ |
47
|
|
|
$I = $this->tester; |
48
|
|
|
|
49
|
|
|
$I->fillField('#thread-message', $message); |
50
|
|
|
$this->seePreviewWorks($message); |
51
|
|
|
|
52
|
|
|
$I->click('Answer', '#leave-comment-form'); |
53
|
|
|
$I->waitForText('Ticket changed'); |
54
|
|
|
$this->seePageContainsComment($message); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function seePreviewWorks($message) |
58
|
|
|
{ |
59
|
|
|
$I = $this->tester; |
60
|
|
|
|
61
|
|
|
$I->click('a[href="#preview-leave-comment-form"]'); |
62
|
|
|
$I->waitForText($message, 10, '#preview-leave-comment-form'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function seePageContainsComment($message) |
66
|
|
|
{ |
67
|
|
|
$I = $this->tester; |
68
|
|
|
|
69
|
|
|
$I->see($message, '.comment .comment-text .body'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function closeTicket() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$I = $this->tester; |
75
|
|
|
|
76
|
|
|
$I->see('Close ticket'); |
77
|
|
|
$I->click('Close ticket'); |
78
|
|
|
$I->waitForText('Ticket closed'); |
79
|
|
|
$I->waitForText('Open ticket', 3); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function openTicket() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$I = $this->tester; |
85
|
|
|
|
86
|
|
|
$I->see('Open ticket'); |
87
|
|
|
$I->click('Open ticket'); |
88
|
|
|
$I->waitForText('Ticket opened'); |
89
|
|
|
$I->waitForText('Close ticket', 3); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.