1<?php
2/**
3 * Copyright 2013-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @category   Horde
9 * @copyright  2013 Horde LLC
10 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @package    Smtp
12 * @subpackage UnitTests
13 */
14
15/**
16 * Test for the SMTP DATA filter.
17 *
18 * @author     Michael Slusarz <slusarz@horde.org>
19 * @category   Horde
20 * @copyright  2013 Horde LLC
21 * @ignore
22 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
23 * @package    Smtp
24 * @subpackage UnitTests
25 */
26class Horde_Smtp_FilterDataTest extends Horde_Test_Case
27{
28    const FILTER_ID = 'horde_smtp_data';
29
30    public function setUp()
31    {
32        stream_filter_register(self::FILTER_ID, 'Horde_Smtp_Filter_Data');
33    }
34
35    /**
36     * @dataProvider escapeProvider
37     */
38    public function testEscape($in, $expected)
39    {
40        $stream = fopen('php://temp', 'r+');
41        stream_filter_append($stream, self::FILTER_ID, STREAM_FILTER_READ);
42
43        fwrite($stream, $in);
44        rewind($stream);
45
46        $this->assertEquals(
47            $expected,
48            stream_get_contents($stream)
49        );
50    }
51
52    public function escapeProvider()
53    {
54        return array(
55            array(
56                "Foo\nBar",
57                "Foo\r\nBar"
58            ),
59            array(
60                "Foo\rBar",
61                "Foo\r\nBar"
62            ),
63            array(
64                "Foo\r\nBar",
65                "Foo\r\nBar"
66            ),
67            array(
68                "Foo\r\n.\r\nBar\r\n",
69                "Foo\r\n..\r\nBar\r\n"
70            ),
71            array(
72                "Foo\r.\r\n\n .Foo\n\r\nBaz",
73                "Foo\r\n..\r\n\r\n .Foo\r\n\r\nBaz"
74            )
75        );
76    }
77
78}
79