File: BaseReplacer.php

package info (click to toggle)
roundcube 1.6.11%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,868 kB
  • sloc: javascript: 195,588; php: 76,818; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (67 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace Roundcube\Tests\Framework;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
 * Test class to test rcube_base_replacer class
 */
class Framework_BaseReplacer extends TestCase
{

    /**
     * Class constructor
     */
    function test_class()
    {
        $object = new \rcube_base_replacer('test');

        $this->assertInstanceOf(\rcube_base_replacer::class, $object, "Class constructor");
    }

    /**
     * Test replace()
     */
    function test_replace()
    {
        $base = 'http://thisshouldntbetheurl.bob.com/';
        $html = '<A href=http://shouldbethislink.com>Test URL</A>';

        $replacer = new \rcube_base_replacer($base);
        $response = $replacer->replace($html);

        $this->assertSame('<A href="http://shouldbethislink.com">Test URL</A>', $response);
    }

    /**
     * Data for absolute_url() test
     */
    static function data_absolute_url()
    {
        return [
            ['', 'http://test', 'http://test/'],
            ['http://test', 'http://anything', 'http://test'],
            ['cid:test', 'http://anything', 'cid:test'],
            ['/test', 'http://test', 'http://test/test'],
            ['./test', 'http://test', 'http://test/test'],
            ['../test1', 'http://test/test2', 'http://test1'],
            ['../test1', 'http://test/test2/', 'http://test/test1'],
        ];
    }

    /**
     * Test absolute_url()
     * @dataProvider data_absolute_url
     */

    #[DataProvider('data_absolute_url')]
    function test_absolute_url($path, $base, $expected)
    {
        $replacer = new \rcube_base_replacer('test');
        $result   = $replacer->absolute_url($path, $base);

        $this->assertSame($expected, $result);
    }
}