Completed
Push — staging ( d71a8f...4368fa )
by Woeler
41s queued 32s
created

testObjectInArrayIsDetectedOrIgnored()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * @copyright   2018 Mautic Contributors. All rights reserved
5
 * @author      Mautic, Inc.
6
 *
7
 * @link        https://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CoreBundle\Tests\Unit\Helper;
13
14
use Mautic\CoreBundle\Helper\ClickthroughHelper;
15
use Mautic\CoreBundle\Tests\Unit\Helper\TestResources\WakeupCall;
16
17
class ClickthroughHelperTest extends \PHPUnit_Framework_TestCase
18
{
19
    public function testEncodingCanBeDecoded()
20
    {
21
        $array = ['foo' => 'bar'];
22
23
        $this->assertEquals($array, ClickthroughHelper::decodeArrayFromUrl(ClickthroughHelper::encodeArrayForUrl($array)));
24
    }
25
26
    /**
27
     * @covers \Mautic\CoreBundle\Helper\Serializer::decode
28
     */
29
    public function testObjectInArrayIsDetectedOrIgnored()
30
    {
31
        $this->expectException(\InvalidArgumentException::class);
32
33
        $array = ['foo' => new WakeupCall()];
34
35
        ClickthroughHelper::decodeArrayFromUrl(ClickthroughHelper::encodeArrayForUrl($array));
36
    }
37
38
    public function testOnlyArraysCanBeDecodedToPreventObjectWakeupVulnerability()
39
    {
40
        $this->expectException(\InvalidArgumentException::class);
41
42
        ClickthroughHelper::decodeArrayFromUrl(urlencode(base64_encode(serialize(new \stdClass()))));
43
    }
44
45
    public function testEmptyStringDoesNotThrowException()
46
    {
47
        $array = [];
48
49
        $this->assertEquals($array, ClickthroughHelper::decodeArrayFromUrl(''));
50
    }
51
}
52