Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AttachmentRename.php « Mail « Actions « tests - github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8474cd4516d9e7425d42c143fe72d0c6ad0eb128 (plain)
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
<?php

/**
 * Test class to test rcmail_action_mail_attachment_rename
 *
 * @package Tests
 */
class Actions_Mail_AttachmentRename extends ActionTestCase
{
    /**
     * Test uploaded attachment rename
     */
    function test_run()
    {
        $rcmail = rcube::get_instance();
        $action = new rcmail_action_mail_attachment_rename;
        $output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'rename-attachment');

        $this->assertInstanceOf('rcmail_action', $action);
        $this->assertTrue($action->checks());

        // First we create the upload record
        $file = $this->fileUpload('100');

        $_SERVER['REQUEST_METHOD'] = 'POST';
        $_SESSION = ['compose_data_100' => ['test' => 'test']];

        // Invoke the rename action
        $_POST = ['_id' => '100', '_file' => 'rcmfile' . $file['id'], '_name' => 'mod.gif'];
        $this->runAndAssert($action, OutputJsonMock::E_EXIT);

        $result = $output->getOutput();

        $this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
        $this->assertSame('rename-attachment', $result['action']);
        $this->assertSame('this.rename_attachment_handler("rcmfile' . $file['id'] . '","mod.gif");', trim($result['exec']));

        $upload = rcube::get_instance()->get_uploaded_file($file['id']);
        $this->assertSame($_POST['_name'], $upload['name']);
        $this->assertSame($_POST['_id'], $upload['group']);
    }
}