Skip to content

Commit 2803464

Browse files
committed
Tests for external window
1 parent 88569eb commit 2803464

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/Browser/Mail/ExtwinTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Roundcube\Tests\Browser\Mail;
4+
5+
use Roundcube\Tests\Browser\Bootstrap;
6+
use Roundcube\Tests\Browser\Components\App;
7+
use Roundcube\Tests\Browser\Components\Popupmenu;
8+
use Roundcube\Tests\Browser\TestCase;
9+
use PHPUnit\Framework\Assert;
10+
11+
class ExtwinTest extends TestCase
12+
{
13+
#[\Override]
14+
public static function setUpBeforeClass(): void
15+
{
16+
Bootstrap::init_imap(true);
17+
Bootstrap::purge_mailbox('INBOX');
18+
19+
// import email messages
20+
foreach (glob(TESTS_DIR . 'data/mail/list_00.eml') as $f) {
21+
Bootstrap::import_message($f, 'INBOX');
22+
}
23+
}
24+
25+
/**
26+
* Test opening mime parts in an external window.
27+
*/
28+
public function testExtwin()
29+
{
30+
$this->browse(function ($browser) {
31+
$current_window = null;
32+
$new_window = null;
33+
$browser->go('mail');
34+
35+
$browser->waitFor('#messagelist tbody tr:first-child')
36+
->click('#messagelist tbody tr:first-child');
37+
38+
// TODO: Does all of this work on phone-sized screens, too?
39+
40+
$browser->waitFor('#messagecontframe');
41+
$browser->withinFrame('#messagecontframe', function ($browser) use (&$current_window, &$new_window) {
42+
$browser->waitFor('#message-content');
43+
[$current_window, $new_window] = $browser->openWindow(static function ($browser) {
44+
$browser->click('ul#attachment-list li:first-of-type a.filename');
45+
});
46+
});
47+
$browser->driver->switchTo()->window($new_window);
48+
$browser->waitUntilMissing('.loading');
49+
50+
# Test file content
51+
$browser->waitFor('#messagepartframe');
52+
$browser->withinFrame('#messagepartframe', static function ($browser) {
53+
$browser->waitFor('pre');
54+
$browser->assertElementsCount('*', 1);
55+
$browser->assertSeeIn('pre', "foo\nbar\ngna");
56+
});
57+
58+
# Test toolbar to have 3 buttons.
59+
$browser->assertElementsCount('.header .toolbar > *', 3);
60+
61+
# Test info popup
62+
$filename = 'lines.txt';
63+
64+
$browser->click('.header .toolbar li:nth-child(1) a.info');
65+
$browser->waitFor('.ui-dialog');
66+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(1) .title', "Name:");
67+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(1) .header', "lines.txt");
68+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(2) .title', "Type:");
69+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(2) .header', "text/plain");
70+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(3) .title', "Size:");
71+
$browser->assertSeeIn('.ui-dialog .ui-dialog-content table.listing tr:nth-child(3) .header', "~13 B");
72+
$browser->click('.ui-dialog .ui-dialog-titlebar-close');
73+
$browser->waitUntilMissing('.ui-dialog');
74+
75+
# Test download
76+
$browser->click('.header .toolbar li:nth-child(2) a.download');
77+
$file_contents = $browser->readDownloadedFile($filename);
78+
$browser->removeDownloadedFile($filename);
79+
$this->assertEquals($file_contents, "foo\r\nbar\r\ngna");
80+
81+
# Click the "print" button to check if it works. Unfortunately we can't test the actual printing dialog.
82+
$browser->click('.header .toolbar li:nth-child(3) a.print');
83+
84+
$browser->driver->close();
85+
$browser->driver->switchTo()->window($current_window);
86+
});
87+
}
88+
}

0 commit comments

Comments
 (0)