SipTest.php 5.55 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
<?php

3
4
namespace qfq;

Carsten  Rose's avatar
Carsten Rose committed
5
6
7
8
9
10
11
12
13
require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/store/Sip.php');

/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/10/16
 * Time: 10:55 PM
 */
14
15
16
17
18
19
20
21
22
23

use PHPUnit\Framework\TestCase;

//class SipTest extends \PHPUnit_Framework_TestCase {

/**
 * Class SipTest
 * @package qfq
 */
class SipTest extends TestCase {
Carsten  Rose's avatar
Carsten Rose committed
24
25
26

    public function testUrlparamToSip() {

27
        $sip = new Sip(true);
Carsten  Rose's avatar
Carsten Rose committed
28
29
        $sip->sipUniqId('badcaffee1234');

30
        $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL);
Carsten  Rose's avatar
Carsten Rose committed
31
32
        $this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result);

33
        $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person");
Carsten  Rose's avatar
Carsten Rose committed
34
35
        $this->assertEquals('http://example.com/index.php?id=input&s=badcaffee1234', $result);

36
        $result = $sip->queryStringToSip("index.php?id=input&r=1&form=person", RETURN_URL);
Carsten  Rose's avatar
Carsten Rose committed
37
38
        $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);

39
        $result = $sip->queryStringToSip("?id=input&r=1&form=person", RETURN_URL);
40
        $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
41

42
        $result = $sip->queryStringToSip("id=input&r=1&form=person", RETURN_URL);
43
        $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
44

45
        $result = $sip->queryStringToSip("input&r=1&form=person", RETURN_URL);
46
        $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
47

48
        $result = $sip->queryStringToSip("id=input&r=1&form=person&keySemId=23", RETURN_URL);
49
        $this->assertEquals('index.php?id=input&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
50

51
        $result = $sip->queryStringToSip("id=input&r=1&form=person&type=99", RETURN_URL);
52
        $this->assertEquals('index.php?id=input&type=99&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
53

54
        $result = $sip->queryStringToSip("id=input&r=1&form=person&L=1", RETURN_URL);
55
        $this->assertEquals('index.php?id=input&L=1&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
56

57
        $result = $sip->queryStringToSip("id=input&r=1&L=2&form=person&type=99", RETURN_URL);
58
        $this->assertEquals('index.php?id=input&L=2&type=99&s=badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
59

60
        $result = $sip->queryStringToSip("id=input&r=1&L=2&form=person&type=99", RETURN_SIP);
Carsten  Rose's avatar
Carsten Rose committed
61
62
        $this->assertEquals('badcaffee1234', $result);

63
        $result = $sip->queryStringToSip("id=input&r=10&L=2&form=person&type=99", RETURN_SIP);
64
        $this->assertEquals('badcaffee1234', $result);
Carsten  Rose's avatar
Carsten Rose committed
65
66
67

    }

68
69
70
    /**
     * @throws CodeException
     * @throws UserFormException
Carsten  Rose's avatar
Carsten Rose committed
71
     * @throws UserReportException
72
     */
Carsten  Rose's avatar
Carsten Rose committed
73
    public function testGetVarsFromSip() {
74
        $sip = new Sip(true);
Carsten  Rose's avatar
Carsten Rose committed
75
76
        $sip->sipUniqId('badcaffee1234');

77
        $sip2 = $sip->queryStringToSip("http://example.com/index.php?a=1&b=2&c=3", RETURN_SIP);
Carsten  Rose's avatar
Carsten Rose committed
78
        $arr = $sip->getVarsFromSip($sip2);
Carsten  Rose's avatar
Carsten Rose committed
79
        $this->assertEquals(['a' => 1, 'b' => 2, 'c' => 3, 'r' => 0], $arr);
Carsten  Rose's avatar
Carsten Rose committed
80
81
        $this->assertEquals('badcaffee1234', $sip2);

82
        $sip2 = $sip->queryStringToSip("http://example.com/index.php?e=1&f=2&g=3", RETURN_SIP);
Carsten  Rose's avatar
Carsten Rose committed
83
        $arr = $sip->getVarsFromSip($sip2);
Carsten  Rose's avatar
Carsten Rose committed
84
        $this->assertEquals(['e' => 1, 'f' => 2, 'g' => 3, 'r' => 0], $arr);
Carsten  Rose's avatar
Carsten Rose committed
85
86
87
88
89
90
        $this->assertEquals('badcaffee1234', $sip2);

        $sip->sipUniqId('badcaffee0000');
        $sip2 = $sip->sipUniqId();
        $this->assertEquals('badcaffee0000', $sip2);

91
        $sip2 = $sip->queryStringToSip("http://example.com/index.php?aa=hello&bb=world", RETURN_SIP);
Carsten  Rose's avatar
Carsten Rose committed
92
        $arr = $sip->getVarsFromSip($sip2);
Carsten  Rose's avatar
Carsten Rose committed
93
        $this->assertEquals(['aa' => 'hello', 'bb' => 'world', 'r' => 0], $arr);
94
        $this->assertEquals('badcaffee1234', $sip2);
Carsten  Rose's avatar
Carsten Rose committed
95

96
        $sip2 = $sip->queryStringToSip("aaa=Don&bbb=John", RETURN_SIP);
Carsten  Rose's avatar
Carsten Rose committed
97
        $arr = $sip->getVarsFromSip($sip2);
Carsten  Rose's avatar
Carsten Rose committed
98
        $this->assertEquals(['aaa' => 'Don', 'bbb' => 'John', 'r' => 0], $arr);
Carsten  Rose's avatar
Carsten Rose committed
99
100
101

    }

102
103
104
    /**
     *
     */
105
    public function testFakeUniqId() {
106
        $sip = new Sip(true);
107
108
        $this->assertEquals('badcaffee1234', $sip->sipUniqId('badcaffee1234'));

109
        $sip = new Sip(true);
110
111
112
        $this->assertEquals('badcaffee5678', $sip->sipUniqId('badcaffee5678'));
    }

113
114
    /**
     * @throws CodeException
115
     * @throws UserFormException
116
     */
Carsten  Rose's avatar
Carsten Rose committed
117
118
    public function testGetSipFromUrlParam() {

119
        $sip = new Sip(true);
Carsten  Rose's avatar
Carsten Rose committed
120
121
        $sip->sipUniqId('badcaffee1234');

122
123
        $result = $sip->queryStringToSip("http://example.com/index.php?id=input&r=1&form=person", RETURN_URL);
        $s = $sip->getSipFromQueryString('form=person&r=1');
Carsten  Rose's avatar
Carsten Rose committed
124
125
        $this->assertEquals('badcaffee1234', $s);

126
        $s = $sip->getSipFromQueryString('UnknwonParameter=1234');
Carsten  Rose's avatar
Carsten Rose committed
127
128
        $this->assertFalse($s);

Carsten  Rose's avatar
Carsten Rose committed
129
        // TODO : Test wieder reinnehmen:
Carsten  Rose's avatar
Carsten Rose committed
130
131
132
133
//        $sip->sipUniqId('badcaffee1111');
//        $url = $sip->queryStringToSip("a=10&b=20&c=30", RETURN_SIP);
//        $s = $sip->getSipFromQueryString('a=10&b=20&c=30');
//        $this->assertEquals('badcaffee1111', $s);
Carsten  Rose's avatar
Carsten Rose committed
134
135
136

    }

137
138
139
    /**
     *
     */
Carsten  Rose's avatar
Carsten Rose committed
140
    public function testSipUniqId() {
141
        $sip = new Sip(true);
Carsten  Rose's avatar
Carsten Rose committed
142
143
144
145
146
147
        $sip->sipUniqId('badcaffee1234');

        $s = $sip->sipUniqId('badcaffee1234');
        $this->assertEquals('badcaffee1234', $s);
    }

148
149
    /**
     * @throws CodeException
150
     * @throws UserFormException
151
     */
152
    public function testGetQueryStringFromSip() {
153
        $sip = new Sip(true);
154
155
        $sip->sipUniqId('badcaffee1234');

156
        $s = $sip->queryStringToSip("http://example.com/index.php?id=input&r=20&form=person", RETURN_SIP);
157
158

        $result = $sip->getQueryStringFromSip($s);
159
        $this->assertEquals('form=person&r=20', $result);
160
    }
Carsten  Rose's avatar
Carsten Rose committed
161
}