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
|
<?php
namespace Roundcube\Tests\Actions\Contacts;
use Roundcube\Tests\ActionTestCase;
use Roundcube\Tests\OutputJsonMock;
/**
* Test class to test rcmail_action_contacts_mailto
*/
class Actions_Contacts_Mailto extends ActionTestCase
{
/**
* Test run() method
*/
function test_run()
{
$action = new \rcmail_action_contacts_mailto();
$output = $this->initOutput(\rcmail_action::MODE_AJAX, 'contacts', 'mailto');
$this->assertInstanceOf(\rcmail_action::class, $action);
$this->assertTrue($action->checks());
self::initDB('contacts');
$db = \rcmail::get_instance()->get_dbh();
$query = $db->query('SELECT `contact_id` FROM `contacts` WHERE `email` = ?', 'johndoe@example.org');
$result = $db->fetch_assoc($query);
$cid = $result['contact_id'];
$_POST = ['_cid' => $cid, '_source' => '0'];
$this->runAndAssert($action, OutputJsonMock::E_EXIT);
$result = $output->getOutput();
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
$this->assertSame('mailto', $result['action']);
$this->assertTrue(strpos($result['exec'], 'this.open_compose_step({"_mailto":"') !== false);
preg_match('/_mailto":"([0-9a-z]+)/', $result['exec'], $m);
$this->assertSame('John+Doe+%3Cjohndoe%40example.org%3E', $_SESSION['mailto'][$m[1]]);
}
}
|