Files
roundcubemail/tests/Browser/Contacts/ImportTest.php
Michael Voříšek 54f4aa33f9 Fix CS - imports (#9316)
* fix Tests\Browser\TestCase imports

* fix remaining imports

* fix PHPUnit\Framework\TestCase imports

* import GuzzleHttp\Client

* fix remaining

* "php_unit_method_casing" is not todo

* fix "single_line_comment_spacing"

* fix 2nd commit done using older fixer
2024-01-21 19:13:31 +01:00

118 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Browser\Contacts;
use Tests\Browser\Components\App;
use Tests\Browser\Components\Dialog;
use Tests\Browser\TestCase;
class ImportTest extends TestCase
{
public static function setUpBeforeClass(): void
{
\bootstrap::init_db();
}
/**
* Test basic elements of contacts import UI
*/
public function testImportUI()
{
$this->browse(static function ($browser) {
$browser->go('addressbook');
$browser->clickToolbarMenuItem('import');
$browser->with(new Dialog(), static function ($browser) {
$browser->assertDialogTitle('Import contacts')
->assertButton('mainaction.import', 'Import')
->assertButton('cancel', 'Cancel');
});
$browser->withinFrame('.ui-dialog iframe', static function ($browser) {
// check task and action
$browser->with(new App(), static function ($browser) {
$browser->assertEnv('task', 'addressbook');
$browser->assertEnv('action', 'import');
// these objects should be there always
$browser->assertObjects(['importform']);
});
$browser->assertSee('You can upload');
$browser->assertVisible('#rcmImportForm');
$browser->assertVisible('#rcmImportForm select');
$browser->assertVisible('#rcmImportForm .custom-switch');
// FIXME: selecting the file input directly does not work
$browser->assertVisible('#rcmImportForm .custom-file');
$browser->assertSelected('#rcmImportForm select', 0);
});
// Close the dialog
$browser->with(new Dialog(), static function ($browser) {
$browser->clickButton('cancel');
});
});
}
/**
* Import contacts from a vCard file
*
* @depends testImportUI
*/
public function testImportProcess()
{
$this->browse(static function ($browser) {
// Open the dialog again
$browser->clickToolbarMenuItem('import');
$browser->with(new Dialog(), static function ($browser) {
$browser->assertDialogTitle('Import contacts')
->clickButton('import');
});
// Submit the form with no file attached
$browser->with(new Dialog(2), static function ($browser) {
$browser->assertDialogTitle('Attention')
->assertDialogContent('Please select a file')
->assertButton('save.mainaction', 'OK')
->pressESC();
});
$browser->with(new Dialog(), static function ($browser) {
$browser->withinDialogFrame(static function ($browser) {
$browser->attach('.custom-file input', TESTS_DIR . 'data/contacts.vcf');
})
->clickButton('import')
->withinDialogFrame(static function ($browser) {
$browser->waitForText('Successfully imported 2 contacts:');
})
->closeDialog();
});
// Expected existing contacts + imported
$browser->waitFor('#contacts-table tr')
->assertElementsCount('#contacts-table tbody tr', 4)
->assertSeeIn('#rcmcountdisplay', '1 4 of 4');
});
}
/**
* Test imported contact
*
* @depends testImportProcess
*/
public function testImportResult()
{
$this->browse(static function ($browser) {
// Open the dialog again
$browser->click('#contacts-table tr:last-child');
$browser->withinFrame('#contact-frame', static function ($browser) {
$browser->waitFor('a.email'); // wait for iframe to load
$browser->assertSeeIn('.names', 'Sylvester Stalone');
$browser->assertSeeIn('a.email', 's.stalone@rambo.tv');
});
});
}
}