File: HtmlEditor.php

package info (click to toggle)
roundcube 1.6.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,888 kB
  • sloc: javascript: 195,591; php: 76,917; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (97 lines) | stat: -rw-r--r-- 2,231 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php

namespace Tests\Browser\Components;

use App;
use Tests\Browser\Browser;
use Laravel\Dusk\Component;

class HtmlEditor extends Component
{
    const MODE_PLAIN = 'plain';
    const MODE_HTML  = 'html';

    public $id;

    /**
     * Class constructor
     */
    public function __construct($id)
    {
        $this->id = trim($id);
    }

    /**
     * Get the root selector for the component.
     *
     * @return string
     */
    public function selector()
    {
        return '#' . $this->id;
    }

    /**
     * Assert that the browser page contains the component.
     *
     * @param Browser $browser
     *
     * @return void
     */
    public function assert($browser)
    {
        $browser->waitFor($this->selector() . '.html-editor');
    }

    /**
     * Get the element shortcuts for the component.
     *
     * @return array
     */
    public function elements()
    {
        return [
            '@plain-toolbar' => '.editor-toolbar',
            '@plain-body' => 'textarea',
            '@html-editor' => '.tox-tinymce',
            '@html-toolbar' => '.tox-tinymce .tox-editor-header',
            '@html-body' => 'iframe',
        ];
    }

    /**
     * Assert editor mode
     */
    public function assertMode($browser, $mode)
    {
        if ($mode == self::MODE_PLAIN) {
            $browser->assertVisible('@plain-toolbar')
                ->assertMissing('@html-body');
        }
        else {
            $browser->assertMissing('@plain-toolbar')
                ->assertVisible('@html-body');
        }
    }

    /**
     * Switch editor mode
     */
    public function switchMode($browser, $mode, $accept_warning = false)
    {
        if ($mode == self::MODE_HTML) {
            $browser->click('@plain-toolbar a.mce-i-html');
            if ($accept_warning) {
                $browser->waitForDialog()->acceptDialog();
            }
            $browser->waitFor('@html-body')->waitFor('@html-toolbar');
        }
        else {
            $browser->click('.tox-toolbar__group:first-child button');
            if ($accept_warning) {
                $browser->waitForDialog()->acceptDialog();
            }
            $browser->waitFor('@plain-body');
        }
    }
}