testConvertWithWindows()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\Tests\Helper;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use WBW\Bundle\JQuery\DataTablesBundle\Helper\DataTablesExportHelper;
16
use WBW\Bundle\JQuery\DataTablesBundle\Tests\AbstractTestCase;
17
18
/**
19
 * DataTables export helper test.
20
 *
21
 * @author webeweb <https://github.com/webeweb>
22
 * @package WBW\Bundle\JQuery\DataTablesBundle\Tests\Helper
23
 */
24
class DataTablesExportHelperTest extends AbstractTestCase {
25
26
    /**
27
     * Test convert()
28
     *
29
     * @return void
30
     */
31
    public function testConvert(): void {
32
33
        $arg = ["é"];
34
        $res = ["é"];
35
        $this->assertEquals($res, DataTablesExportHelper::convert($arg));
36
    }
37
38
    /**
39
     * Test convert()
40
     *
41
     * @return void
42
     */
43
    public function testConvertWithWindows(): void {
44
45
        $arg = ["é"];
46
        $res = ["\xe9"];
47
        $this->assertEquals($res, DataTablesExportHelper::convert($arg, true));
48
    }
49
50
    /**
51
     * Test isWindows()
52
     *
53
     * @return void
54
     */
55
    public function testIsWindows(): void {
56
57
        // Set a Request mock.
58
        $request = new Request([], [], [], [], [], ["HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0"]);
59
60
        $this->assertTrue(DataTablesExportHelper::isWindows($request));
61
    }
62
63
    /**
64
     * Test isWindows()
65
     *
66
     * @return void
67
     */
68
    public function testIsWindowsWithLinuxUserAgent(): void {
69
70
        // Set a Request mock.
71
        $request = new Request([], [], [], [], [], ["HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"]);
72
73
        $this->assertFalse(DataTablesExportHelper::isWindows($request));
74
    }
75
76
    /**
77
     * Test isWindows()
78
     *
79
     * @return void
80
     */
81
    public function testIsWindowsWithoutUserAgent(): void {
82
83
        // Set a Request mock.
84
        $request = new Request();
85
86
        $this->assertFalse(DataTablesExportHelper::isWindows($request));
87
    }
88
}
89