LinkTest.php 38.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 3/31/16
 * Time: 10:06 PM
 */

namespace qfq;

require_once(__DIR__ . '/../../qfq/report/Link.php');
Carsten  Rose's avatar
Carsten Rose committed
12
13
require_once(__DIR__ . '/../../qfq/store/Store.php');
require_once(__DIR__ . '/../../qfq/store/Sip.php');
14
15
16
17


class LinkTest extends \PHPUnit_Framework_TestCase {

Carsten  Rose's avatar
Carsten Rose committed
18
19
20
21
22
23
24
25
26
    /**
     * @var Sip
     */
    private $sip = null;

    /**
     * @var Store
     */
    private $store = null;
27

28
29
30
31
32
33
    /**
     * @throws SyntaxReportException
     */
    public function testLinkUrlBasic() {
        $link = new Link(null, $this->sip, true);

34
        Store::setVar(TYPO3_PAGE_ID, 'firstPage', STORE_TYPO3);
35

36
        $result = $link->renderLink('');
37
38
39
40
41
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

42
43
44
45
46
47
        $result = $link->renderLink('u:http://example.com?id=100&t=2&param=hello');
        $this->assertEquals('<a href="http://example.com?id=100&t=2&param=hello" class="external" >http://example.com?id=100&t=2&param=hello</a>', $result);

        $result = $link->renderLink('u:example.com');
        $this->assertEquals('<a href="example.com" class="external" >example.com</a>', $result);

48
49
        $result = $link->renderLink('u:http://example.com|t:Hello world');
        $this->assertEquals('<a href="http://example.com" class="external" >Hello world</a>', $result);
50
51
52

        $result = $link->renderLink('u:http://example.com?id=100&t=2&param=hello|t:Hello world');
        $this->assertEquals('<a href="http://example.com?id=100&t=2&param=hello" class="external" >Hello world</a>', $result);
53
54
55
56
57
58
59
60
61
    }

    /**
     * @expectedException \qfq\UserReportException
     *
     */
    public function testLinkUrlBasicExceptionDouble() {
        $link = new Link(null, $this->sip, true);

62
63
64
65
66
67
68
69
70
71
72
        $link->renderLink('u:http://example.com|u:http://new.org');
    }

    /**
     * @expectedException \qfq\UserReportException
     *
     */
    public function testLinkUrlBasicExceptionEmpty1() {
        $link = new Link(null, $this->sip, true);

        $link->renderLink('u');
73
74
    }

75
76
77
78
79
80
81
82
83
    /**
     * @expectedException \qfq\UserReportException
     *
     */
    public function testLinkUrlBasicExceptionEmpty2() {
        $link = new Link(null, $this->sip, true);

        $link->renderLink('u:');
    }
84

85
    /**
86
     * @throws SyntaxReportException
87
     */
88
    public function testLinkPageBasic() {
Carsten  Rose's avatar
Carsten Rose committed
89
        $link = new Link(null, $this->sip, true);
90
91
92
93
94
95
96
97
98
99
        Store::setVar(TYPO3_PAGE_ID, 'firstPage', STORE_TYPO3);

        $result = $link->renderLink('p');
        $this->assertEquals('<a href="?id=firstPage" class="internal" >?id=firstPage</a>', $result);

        $result = $link->renderLink('p:');
        $this->assertEquals('<a href="?id=firstPage" class="internal" >?id=firstPage</a>', $result);

        $result = $link->renderLink('p:secondPage');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);
100

101
102
103
        $result = $link->renderLink('p:id=secondPage');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);

104
105
106
        $result = $link->renderLink('p:id=secondPage&id=100&t=2&param=hello');
        $this->assertEquals('<a href="?id=secondPage&id=100&t=2&param=hello" class="internal" >?id=secondPage&id=100&t=2&param=hello</a>', $result);

107
108
        $result = $link->renderLink('p:secondPage|t:Hello world');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Hello world</a>', $result);
109
110
111
112
113
    }

    /**
     * @throws SyntaxReportException
     */
114
115
116
117
    public function testLinkMailBasic() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('m:john@doe.com');
118
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
119
120

        $result = $link->renderLink('m:john@doe.com|t:John Doe');
121
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >John Doe</a>', $result);
122
123
124
125
126
127
128
129
130
    }

    /**
     * @expectedException \qfq\UserReportException
     *
     */
    public function testLinkMailBasicExceptionMissing1() {
        $link = new Link(null, $this->sip, true);

131
        $link->renderLink('m');
132
133
134
135
136
137
138
139
140
    }

    /**
     * @expectedException \qfq\UserReportException
     *
     */
    public function testLinkMailBasicExceptionMissing2() {
        $link = new Link(null, $this->sip, true);

141
        $link->renderLink('m:');
142
143
    }

Carsten  Rose's avatar
Carsten Rose committed
144
145
146
147
148
149
150
    /**
     * @throws SyntaxReportException
     */
    public function testMailEncryption() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('m:john@doe.com|e');
151
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
152
153

        $result = $link->renderLink('m:john@doe.com|e:');
154
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
155
156

        $result = $link->renderLink('m:john@doe.com|e:0');
157
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
158
159
160
161
162
163
164
165
166

        //TODO: aktivieren sobald encrypted Mails implemented.
//        $result = $link->renderLink('m:john@doe.com|e:1');
//        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);
    }

    /**
     * @throws UserReportException
     */
167
    public function testRenderModeUrl() {
168
        $link = new Link(null, $this->sip, true);
169

170
        Store::setVar(TYPO3_PAGE_ID, 'firstPage', STORE_TYPO3);
171

172
173
174
175
        $result = $link->renderLink('u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('t:Example');
176
        $this->assertEquals('', $result);
177

178
179
180
181
        $result = $link->renderLink('u:http://example.com|t:Example');
        $this->assertEquals('<a href="http://example.com" class="external" >Example</a>', $result);

        $result = $link->renderLink('u:http://example.com|r:0');
182
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);
183

184
185
186
187
188
189
190
191
192
193
194
        $result = $link->renderLink('t:Example|r:0');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:0');
        $this->assertEquals('<a href="http://example.com" class="external" >Example</a>', $result);

        // r: 1
        $result = $link->renderLink('u:http://example.com|r:1');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('t:Example|r:1');
195
196
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

        $result = $link->renderLink('u:http://example.com|t:Example|r:1');
        $this->assertEquals('<a href="http://example.com" class="external" >Example</a>', $result);

        // r: 2
        $result = $link->renderLink('u:http://example.com|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:2');
        $this->assertEquals('<a href="http://example.com" class="external" >Example</a>', $result);

        // r: 3
        $result = $link->renderLink('u:http://example.com|r:3');
213
214
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
215
216

        $result = $link->renderLink('t:Example|r:3');
217
218
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
219
220

        $result = $link->renderLink('u:http://example.com|t:Example|r:3');
221
222
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
223
224
225

        // r: 4
        $result = $link->renderLink('u:http://example.com|r:4');
226
227
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
228
229

        $result = $link->renderLink('t:Example|r:4');
230
231
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
232
233

        $result = $link->renderLink('u:http://example.com|t:Example|r:4');
234
235
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
236
237
238
239
240
241
242
243
244
245
246
247

        // r: 5
        $result = $link->renderLink('u:http://example.com|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:5');
        $this->assertEquals('', $result);
    }

Carsten  Rose's avatar
Carsten Rose committed
248
249
250
251
252
    /**
     * @throws CodeException
     * @throws UserFormException
     * @throws UserReportException
     */
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
    public function testRenderModePage() {
        $link = new Link(null, $this->sip, true);
        Store::setVar(TYPO3_PAGE_ID, 'firstPage', STORE_TYPO3);

        // r: default (0)
        $result = $link->renderLink('p');
        $this->assertEquals('<a href="?id=firstPage" class="internal" >?id=firstPage</a>', $result);

        $result = $link->renderLink('p:secondPage');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);

        $result = $link->renderLink('t:Example');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|t:Example');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Example</a>', $result);

        // r: 0
        $result = $link->renderLink('p|r:0');
        $this->assertEquals('<a href="?id=firstPage" class="internal" >?id=firstPage</a>', $result);

        $result = $link->renderLink('p:secondPage|r:0');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);

        $result = $link->renderLink('t:Example|r:0');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|t:Example|r:0');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Example</a>', $result);

        // r: 1
        $result = $link->renderLink('p|r:1');
        $this->assertEquals('<a href="?id=firstPage" class="internal" >?id=firstPage</a>', $result);

        $result = $link->renderLink('p:secondPage|r:1');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >?id=secondPage</a>', $result);

        $result = $link->renderLink('t:Example|r:1');
291
292
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

        $result = $link->renderLink('p:secondPage|t:Example|r:1');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Example</a>', $result);

        // r: 2
        $result = $link->renderLink('p|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|t:Example|r:2');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Example</a>', $result);

        // r: 3
        $result = $link->renderLink('p|r:3');
312
313
//        $this->assertEquals('<span >?id=firstPage</span>', $result);
        $this->assertEquals('?id=firstPage', $result);
314
315

        $result = $link->renderLink('p:secondPage|r:3');
316
317
//        $this->assertEquals('<span >?id=secondPage</span>', $result);
        $this->assertEquals('?id=secondPage', $result);
318
319

        $result = $link->renderLink('t:Example|r:3');
320
321
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
322
323

        $result = $link->renderLink('p:secondPage|t:Example|r:3');
324
325
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
326
327
328

        // r: 4
        $result = $link->renderLink('p|r:4');
329
330
//        $this->assertEquals('<span >?id=firstPage</span>', $result);
        $this->assertEquals('?id=firstPage', $result);
331
332

        $result = $link->renderLink('p:secondPage|r:4');
333
334
//        $this->assertEquals('<span >?id=secondPage</span>', $result);
        $this->assertEquals('?id=secondPage', $result);
335
336

        $result = $link->renderLink('t:Example|r:4');
337
338
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
339
340

        $result = $link->renderLink('p:secondPage|t:Example|r:4');
341
342
//        $this->assertEquals('<span >?id=secondPage</span>', $result);
        $this->assertEquals('?id=secondPage', $result);
343

344
345
346
347
348
349
350
351
352
353
354
355
        // r: 5
        $result = $link->renderLink('p|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('p:secondPage|t:Example|r:5');
        $this->assertEquals('', $result);
356
357
    }

Carsten  Rose's avatar
Carsten Rose committed
358
359
360
    /**
     * @throws UserReportException
     */
361
362
363
364
365
    public function testRenderModeMail() {
        $link = new Link(null, $this->sip, true);

        // r: default (0)
        $result = $link->renderLink('m:john@doe.com');
366
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
367
368
369
370
371

        $result = $link->renderLink('t:Example');
        $this->assertEquals('', $result);

        $result = $link->renderLink('m:john@doe.com|t:Example');
372
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >Example</a>', $result);
373
374
375

        // r: 0
        $result = $link->renderLink('m:john@doe.com|r:0');
376
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
377
378
379
380
381

        $result = $link->renderLink('t:Example|r:0');
        $this->assertEquals('', $result);

        $result = $link->renderLink('m:john@doe.com|t:Example|r:0');
382
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >Example</a>', $result);
383
384
385

        // r: 1
        $result = $link->renderLink('m:john@doe.com|r:1');
386
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >mailto:john@doe.com</a>', $result);
387
388

        $result = $link->renderLink('t:Example|r:1');
389
390
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
391
392

        $result = $link->renderLink('m:john@doe.com|t:Example|r:1');
393
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >Example</a>', $result);
394
395
396
397
398
399
400
401
402

        // r: 2
        $result = $link->renderLink('m:john@doe.com|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:2');
        $this->assertEquals('', $result);

        $result = $link->renderLink('m:john@doe.com|t:Example|r:2');
403
        $this->assertEquals('<a href="mailto:john@doe.com" class="external" >Example</a>', $result);
404
405
406

        // r: 3
        $result = $link->renderLink('m:john@doe.com|r:3');
407
408
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
409
410

        $result = $link->renderLink('t:Example|r:3');
411
412
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
413
414

        $result = $link->renderLink('m:john@doe.com|t:Example|r:3');
415
416
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
417
418
419

        // r: 4
        $result = $link->renderLink('m:john@doe.com|r:4');
420
421
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
422
423

        $result = $link->renderLink('t:Example|r:4');
424
425
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
426
427

        $result = $link->renderLink('m:john@doe.com|t:Example|r:4');
428
429
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
430
431
432
433
434
435
436
437
438
439
440
441

        // r: 5
        $result = $link->renderLink('m:john@doe.com|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:5');
        $this->assertEquals('', $result);

        $result = $link->renderLink('m:john@doe.com|t:Example|r:5');
        $this->assertEquals('', $result);
    }

Carsten  Rose's avatar
Carsten Rose committed
442
443
444
    /**
     * @throws UserReportException
     */
445
446
447
448
449
    public function testRenderModeUrlPicture() {
        $link = new Link(null, $this->sip, true);

        // r: default (0)
        $result = $link->renderLink('u:http://example.com|P:picture.gif');
450
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" ></a>', $result);
451
452
453
454
455

        $result = $link->renderLink('t:Example|P:picture.gif');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|P:picture.gif');
456
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
457
458
459

        // r: 0
        $result = $link->renderLink('u:http://example.com|r:0|P:picture.gif');
460
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" ></a>', $result);
461
462
463
464
465

        $result = $link->renderLink('t:Example|r:0|P:picture.gif');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:0|P:picture.gif');
466
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
467
468
469

        // r: 1
        $result = $link->renderLink('u:http://example.com|r:1|P:picture.gif');
470
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" ></a>', $result);
471
472

        $result = $link->renderLink('t:Example|r:1|P:picture.gif');
473
474
//        $this->assertEquals('<span ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
475
476

        $result = $link->renderLink('u:http://example.com|t:Example|r:1|P:picture.gif');
477
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
478
479
480
481

        // r: 2
        //TODO: no link if text is empty - image is linked here: this is not what the user expects.
        $result = $link->renderLink('u:http://example.com|r:2|P:picture.gif');
482
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" ></a>', $result);
483
484
485
486
487

        $result = $link->renderLink('t:Example|r:2|P:picture.gif');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:2|P:picture.gif');
488
        $this->assertEquals('<a href="http://example.com" ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
489
490
491

        // r: 3:
        $result = $link->renderLink('u:http://example.com|r:3|P:picture.gif');
492
493
//        $this->assertEquals('<span ><img alt="picture.gif" src="picture.gif" title="picture.gif" > </span>', $result);
        $this->assertEquals('<img alt="picture.gif" src="picture.gif" title="picture.gif" >', $result);
494
495

        $result = $link->renderLink('t:Example|r:3|P:picture.gif');
496
497
//        $this->assertEquals('<span ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
498
499

        $result = $link->renderLink('u:http://example.com|t:Example|r:3|P:picture.gif');
500
501
//        $this->assertEquals('<span ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
502
503
504

        // r: 4
        $result = $link->renderLink('u:http://example.com|r:4|P:picture.gif');
505
506
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
507
508

        $result = $link->renderLink('t:Example|r:4|P:picture.gif');
509
510
//        $this->assertEquals('<span ><img alt="picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
511
512

        $result = $link->renderLink('u:http://example.com|t:Example|r:4|P:picture.gif');
513
514
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
515
516
517
518
519
520
521
522
523
524
525
526

        // r: 5
        $result = $link->renderLink('u:http://example.com|r:5|P:picture.gif');
        $this->assertEquals('', $result);

        $result = $link->renderLink('t:Example|r:5|P:picture.gif');
        $this->assertEquals('', $result);

        $result = $link->renderLink('u:http://example.com|t:Example|r:5|P:picture.gif');
        $this->assertEquals('', $result);
    }

Carsten  Rose's avatar
Carsten Rose committed
527
528
529
530
531
532
533
    /**
     * @throws UserReportException
     */
    public function testIcons() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('u:http://example.com|E');
534
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Edit" ><span class="glyphicon glyphicon-pencil" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
535
536

        $result = $link->renderLink('u:http://example.com|N');
537
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="New" ><span class="glyphicon glyphicon-plus" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
538
539

        $result = $link->renderLink('u:http://example.com|D');
540
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Delete" ><span class="glyphicon glyphicon-trash" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
541
542

        $result = $link->renderLink('u:http://example.com|H');
543
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Help" ><span class="glyphicon glyphicon glyphicon-question-sign" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
544
545

        $result = $link->renderLink('u:http://example.com|I');
546
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Information" ><span class="glyphicon glyphicon glyphicon-info-sign" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
547
548

        $result = $link->renderLink('u:http://example.com|S');
549
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Details" ><span class="glyphicon glyphicon glyphicon-search" ></span></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
550
551
552
553
554
555
556
557
558
    }

    /**
     * @throws UserReportException
     */
    public function testBullet() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('u:http://example.com|B');
559
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet green" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
560
561

        $result = $link->renderLink('u:http://example.com|B:green');
562
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet green" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
563
564

        $result = $link->renderLink('u:http://example.com|B:blue');
565
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet blue" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-blue.gif" title="blue" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
566
567

        $result = $link->renderLink('u:http://example.com|B:gray');
568
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet gray" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-gray.gif" title="gray" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
569
570

        $result = $link->renderLink('u:http://example.com|B:pink');
571
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet pink" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-pink.gif" title="pink" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
572
573

        $result = $link->renderLink('u:http://example.com|B:red');
574
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet red" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-red.gif" title="red" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
575
576

        $result = $link->renderLink('u:http://example.com|B:yellow');
577
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet yellow" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-yellow.gif" title="yellow" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
578
579
580
581
582
583
584
585
586
587

    }

    /**
     * @throws UserReportException
     */
    public function testChecked() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('u:http://example.com|C');
588
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked green" src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
589
590

        $result = $link->renderLink('u:http://example.com|C:green');
591
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked green" src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
592
593

        $result = $link->renderLink('u:http://example.com|C:blue');
594
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked blue" src="typo3conf/ext/qfq/Resources/Public/icons/checked-blue.gif" title="blue" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
595
596

        $result = $link->renderLink('u:http://example.com|C:gray');
597
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked gray" src="typo3conf/ext/qfq/Resources/Public/icons/checked-gray.gif" title="gray" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
598
599

        $result = $link->renderLink('u:http://example.com|C:pink');
600
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked pink" src="typo3conf/ext/qfq/Resources/Public/icons/checked-pink.gif" title="pink" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
601
602

        $result = $link->renderLink('u:http://example.com|C:red');
603
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked red" src="typo3conf/ext/qfq/Resources/Public/icons/checked-red.gif" title="red" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
604
605

        $result = $link->renderLink('u:http://example.com|C:yellow');
606
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked yellow" src="typo3conf/ext/qfq/Resources/Public/icons/checked-yellow.gif" title="yellow" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
607
608
    }

609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
    /**
     * @expectedException \qfq\UserReportException
     */
    public function testPictureException1() {
        $link = new Link(null, $this->sip, true);

        // r: default (0)
        $result = $link->renderLink('u:http://www.example.com|P:picture.gif|B');
    }

    /**
     * @expectedException \qfq\UserReportException
     */
    public function testPictureException2() {
        $link = new Link(null, $this->sip, true);

        // r: default (0)
        $result = $link->renderLink('u:http://www.example.com|C|B');
    }


Carsten  Rose's avatar
Carsten Rose committed
630
631
632
633
634
635
    /**
     * @throws SyntaxReportException
     */
    public function testLinkUrlParam() {
        $link = new Link(null, $this->sip, true);

636
637
638
639
640
641
        $result = $link->renderLink('u:http://example.com|U:');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('u:http://example.com|U:');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

Carsten  Rose's avatar
Carsten Rose committed
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
        $result = $link->renderLink('u:http://example.com|U:a=1234');
        $this->assertEquals('<a href="http://example.com?a=1234" class="external" >http://example.com?a=1234</a>', $result);

        $result = $link->renderLink('u:http://example.com|U:a=1234&b=abcd');
        $this->assertEquals('<a href="http://example.com?a=1234&b=abcd" class="external" >http://example.com?a=1234&b=abcd</a>', $result);

        $result = $link->renderLink('u:http://example.com|U:a');
        $this->assertEquals('<a href="http://example.com?a" class="external" >http://example.com?a</a>', $result);

        $result = $link->renderLink('u:http://example.com|U:a=');
        $this->assertEquals('<a href="http://example.com?a=" class="external" >http://example.com?a=</a>', $result);

        $result = $link->renderLink('u:http://example.com?A=hello|U:a=world');
        $this->assertEquals('<a href="http://example.com?A=hello&a=world" class="external" >http://example.com?A=hello&a=world</a>', $result);

        $result = $link->renderLink('u:http://example.com?A=hello&B=nice|U:a=world');
        $this->assertEquals('<a href="http://example.com?A=hello&B=nice&a=world" class="external" >http://example.com?A=hello&B=nice&a=world</a>', $result);

        $result = $link->renderLink('p:form|U:a=1234');
        $this->assertEquals('<a href="?id=form&a=1234" class="internal" >?id=form&a=1234</a>', $result);

        $result = $link->renderLink('p:form|U:a=1234&b=abcd');
        $this->assertEquals('<a href="?id=form&a=1234&b=abcd" class="internal" >?id=form&a=1234&b=abcd</a>', $result);

        $result = $link->renderLink('p:form|U:a');
        $this->assertEquals('<a href="?id=form&a" class="internal" >?id=form&a</a>', $result);

        $result = $link->renderLink('p:form|U:a=');
        $this->assertEquals('<a href="?id=form&a=" class="internal" >?id=form&a=</a>', $result);
    }

    /**
     * @throws SyntaxReportException
     */
    public function testTooltip() {
        $link = new Link(null, $this->sip, true);

        // standard case
        $result = $link->renderLink('u:http://example.com|o:hello world');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world" >http://example.com</a>', $result);

        // standard case, swapped parameter
        $result = $link->renderLink('o:hello world|u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world" >http://example.com</a>', $result);

        // no text: this is ok
        $result = $link->renderLink('u:http://example.com|o');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        // no text: this is ok
        $result = $link->renderLink('u:http://example.com|o:');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        // some text, with double ticks inside
        $result = $link->renderLink('u:http://example.com|o:hello world "some more text" end');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world \\"some more text\\" end" >http://example.com</a>', $result);

        // some text, with already escaped  double ticks inside
        $result = $link->renderLink('u:http://example.com|o:hello world \\"some more text\\" end');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world \\"some more text\\" end" >http://example.com</a>', $result);

        // some text with single ticks
        $result = $link->renderLink('u:http://example.com|o:hello world \'some more text\' end');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world \'some more text\' end" >http://example.com</a>', $result);

        // some text with already escaped single ticks
        $result = $link->renderLink('u:http://example.com|o:hello world \\\'some more text\\\' end');
        $this->assertEquals('<a href="http://example.com" class="external" title="hello world \\\'some more text\\\' end" >http://example.com</a>', $result);
    }

    /**
     * @throws SyntaxReportException
     */
    public function testAltText() {
        $link = new Link(null, $this->sip, true);

        // standard case
        $result = $link->renderLink('u:http://example.com|a:hello world|P:image.gif');
720
        $this->assertEquals('<a href="http://example.com" ><img alt="hello world" src="image.gif" title="image.gif" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
721
722
723

        // alt text empty
        $result = $link->renderLink('u:http://example.com|a:|P:image.gif');
724
        $this->assertEquals('<a href="http://example.com" ><img alt="image.gif" src="image.gif" title="image.gif" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

        // TODO: alttext has to be specified prior to 'P' - if not, there is an error generated. This should be fixed.
    }

    /**
     * @throws SyntaxReportException
     */
    public function testClass() {
        $link = new Link(null, $this->sip, true);

        // no class
        $result = $link->renderLink('u:http://example.com|c:n');
        $this->assertEquals('<a href="http://example.com" >http://example.com</a>', $result);

        // internal class
        $result = $link->renderLink('u:http://example.com|c:i');
        $this->assertEquals('<a href="http://example.com" class="internal" >http://example.com</a>', $result);

        // internal class
        $result = $link->renderLink('u:http://example.com|c:e');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        // specific class
        $result = $link->renderLink('u:http://example.com|c:myClass');
        $this->assertEquals('<a href="http://example.com" class="myClass" >http://example.com</a>', $result);
750
751
752
753
754
755
756
757
758
759
760
761

        $result = $link->renderLink('u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('u:http://example.com|c');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('u:http://example.com|c:');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        $result = $link->renderLink('p:form');
        $this->assertEquals('<a href="?id=form" class="internal" >?id=form</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
    }

    /**
     * @throws SyntaxReportException
     */
    public function testTarget() {
        $link = new Link(null, $this->sip, true);

        // no target
        $result = $link->renderLink('u:http://example.com|g');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        // no target
        $result = $link->renderLink('u:http://example.com|g:');
        $this->assertEquals('<a href="http://example.com" class="external" >http://example.com</a>', $result);

        // target _blank
        $result = $link->renderLink('u:http://example.com|g:_blank');
        $this->assertEquals('<a href="http://example.com" class="external" target="_blank" >http://example.com</a>', $result);

        // target someName
        $result = $link->renderLink('u:http://example.com|g:someName');
        $this->assertEquals('<a href="http://example.com" class="external" target="someName" >http://example.com</a>', $result);

        // target someName, swapped parameter
        $result = $link->renderLink('g:someName|u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" target="someName" >http://example.com</a>', $result);
    }

    /**
     * @throws SyntaxReportException
     */
    public function testRight() {
        $link = new Link(null, $this->sip, true);

        // Bullet, LEFT (Standard)
        $result = $link->renderLink('u:http://example.com|t:Hello World|B');
799
        $this->assertEquals('<a href="http://example.com" ><img alt="Bullet green" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" > Hello World</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
800
801
802

        // Bullet, RIGHT
        $result = $link->renderLink('u:http://example.com|t:Hello World|B|R');
803
        $this->assertEquals('<a href="http://example.com" >Hello World <img alt="Bullet green" src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
804
805
806

        // Checked, LEFT (Standard)
        $result = $link->renderLink('u:http://example.com|t:Hello World|C');
807
        $this->assertEquals('<a href="http://example.com" ><img alt="Checked green" src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > Hello World</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
808
809
810

        // Checked, RIGHT
        $result = $link->renderLink('u:http://example.com|t:Hello World|C|R');
811
        $this->assertEquals('<a href="http://example.com" >Hello World <img alt="Checked green" src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
812
813
814

        // Picture, LEFT (Standard)
        $result = $link->renderLink('u:http://example.com|t:Hello World|P:image.gif');
815
        $this->assertEquals('<a href="http://example.com" ><img alt="image.gif" src="image.gif" title="image.gif" > Hello World</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
816
817
818

        // Picture, RIGHT
        $result = $link->renderLink('u:http://example.com|t:Hello World|P:image.gif|R');
819
        $this->assertEquals('<a href="http://example.com" >Hello World <img alt="image.gif" src="image.gif" title="image.gif" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
820
821
822

        // swapped param
        $result = $link->renderLink('R|P:image.gif|t:Hello World|u:http://example.com');
823
        $this->assertEquals('<a href="http://example.com" class="external" >Hello World <img alt="image.gif" src="image.gif" title="image.gif" ></a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
824
825
826
827
828
829
830
831
832
833
    }


    /**
     * @throws SyntaxReportException
     */
    public function testSip() {
        $link = new Link(null, $this->sip, true);

        // Sip: URL
834
835
        $result = $link->renderLink('u:?form&r=12&xId=2345&L=1&type=99&gId=55|s');
        $this->assertEquals('<a href="index.php?id=form&L=1&type=99&s=badcaffee1234" class="external" >index.php?id=form&L=1&type=99&s=badcaffee1234</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
836
837

        // Sip: Page
838
839
        $result = $link->renderLink('p:form&r=12&xId=2345&L=1&type=99&gId=55|s');
        $this->assertEquals('<a href="index.php?id=form&L=1&type=99&s=badcaffee1234" class="internal" >index.php?id=form&L=1&type=99&s=badcaffee1234</a>', $result);
Carsten  Rose's avatar
Carsten Rose committed
840
841
842
843
844
845
    }


    /**
     *
     */
Carsten  Rose's avatar
Carsten Rose committed
846
847
848
849
850
851
852
853
    protected function setUp() {
        parent::setUp();

        $this->store = Store::getInstance('', true);
        $this->sip = new Sip('fakesessionname', true);
        $this->sip->sipUniqId('badcaffee1234');

    }
854
}