Completed
Push — master ( 4859e1...c3d3e1 )
by
unknown
11:17
created

ValidationUtilsTest::testSanitizeSecureInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Tests\Unit\Utils;
4
5
use OroCRM\Bundle\MagentoBundle\Utils\ValidationUtils;
6
7
class ValidationUtilsTest extends \PHPUnit_Framework_TestCase
8
{
9
    const TEST_INCREMENT_ID    = '1000001232';
10
    const TEST_ORIGIN_ID       = 12;
11
    const TEST_DEFAULT_MESSAGE = 'Validation error';
12
13
    /**
14
     * @dataProvider entityProvider
15
     *
16
     * @param object $entity
17
     * @param string $shouldContain
18
     */
19
    public function testErrorPrefixGuess($entity, $shouldContain)
20
    {
21
        $this->assertContains((string)$shouldContain, ValidationUtils::guessValidationMessagePrefix($entity));
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public function entityProvider()
28
    {
29
        $order = $this->getMock('OroCRM\Bundle\MagentoBundle\Entity\Order');
30
        $order->expects($this->any())->method('getIncrementId')->will($this->returnValue(self::TEST_INCREMENT_ID));
31
        $cart = $this->getMock('OroCRM\Bundle\MagentoBundle\Entity\Cart');
32
        $cart->expects($this->any())->method('getOriginId')->will($this->returnValue(self::TEST_ORIGIN_ID));
33
        $cartStatus = $this->getMock('OroCRM\Bundle\MagentoBundle\Entity\CartStatus', [], ['test']);
34
35
        return [
36
            'should take increment ID'                       => [$order, self::TEST_INCREMENT_ID],
37
            'should take origin ID'                          => [$cart, self::TEST_ORIGIN_ID],
38
            'should not provoke error, show default message' => [$cartStatus, self::TEST_DEFAULT_MESSAGE]
39
        ];
40
    }
41
42
    /**
43
     * @dataProvider messageProvider
44
     *
45
     * @param string $exceptionMessage
46
     * @param string $expectedMessage
47
     */
48
    public function testSanitizeSecureInfo($exceptionMessage, $expectedMessage)
49
    {
50
        $sanitisedMessage = ValidationUtils::sanitizeSecureInfo($exceptionMessage);
51
        $this->assertEquals($expectedMessage, $sanitisedMessage);
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function messageProvider()
58
    {
59
        return [
60
            'some other text' => [
61
                '$exceptionMessage' => 'some message text',
62
                '$expectedMessage'  => 'some message text'
63
            ],
64
            'sanitized exception message'       => [
65
                '$exceptionMessage' => '<?xml version="1.0" encoding="UTF-8"?>' .
66
                    '<SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">abc</username>' .
67
                    '<apiKey xsi:type="xsd:string">abcabc1</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>',
68
                '$expectedMessage'  => '<?xml version="1.0" encoding="UTF-8"?>' .
69
                    '<SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">abc</username>' .
70
                    '<apiKey xsi:type="xsd:string">***</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>'
71
            ]
72
        ];
73
    }
74
}
75