LinkTest.php 39.8 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
34
35
36
37
38
39
40
41
42
43
44
45
    /**
     * @throws SyntaxReportException
     */
    public function testLinkUrlBasic() {
        $link = new Link(null, $this->sip, true);

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

        $result = $link->renderLink('u');
        $this->assertEquals('', $result);

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

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

46
47
48
49
50
51
        $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);

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

        $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);
57
58
59
60
61
62
63
64
65
66
67
68
69
    }

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

        $result = $link->renderLink('u:http://example.com|u:http://new.org');
    }


70
    /**
71
     * @throws SyntaxReportException
72
     */
73
    public function testLinkPageBasic() {
Carsten  Rose's avatar
Carsten Rose committed
74
        $link = new Link(null, $this->sip, true);
75
76
77
78
79
80
81
82
83
84
        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);
85

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

89
90
91
        $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);

92
93
        $result = $link->renderLink('p:secondPage|t:Hello world');
        $this->assertEquals('<a href="?id=secondPage" class="internal" >Hello world</a>', $result);
94
95
96
97
98
    }

    /**
     * @throws SyntaxReportException
     */
99
100
101
102
    public function testLinkMailBasic() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('m:john@doe.com');
103
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);
104
105

        $result = $link->renderLink('m:john@doe.com|t:John Doe');
106
        $this->assertEquals('<a href="mailto:john@doe.com" >John Doe</a>', $result);
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    }

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

        $result = $link->renderLink('m');
    }

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

        $result = $link->renderLink('m:');
    }

Carsten  Rose's avatar
Carsten Rose committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    /**
     * @throws SyntaxReportException
     */
    public function testMailEncryption() {
        $link = new Link(null, $this->sip, true);

        $result = $link->renderLink('m:john@doe.com|e');
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);

        $result = $link->renderLink('m:john@doe.com|e:');
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);

        $result = $link->renderLink('m:john@doe.com|e:0');
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);

        //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
     */
152
    public function testRenderModeUrl() {
153
        $link = new Link(null, $this->sip, true);
154

155
        // r: default (0)
156
        $result = $link->renderLink('u');
157
        $this->assertEquals('', $result);
158

159
160
161
162
        $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');
163
        $this->assertEquals('', $result);
164

165
166
167
168
169
170
171
172
        $result = $link->renderLink('u:http://example.com|t:Example');
        $this->assertEquals('<a href="http://example.com" class="external" >Example</a>', $result);

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

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

175
176
177
178
179
180
181
182
183
184
185
186
187
188
        $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|r:1');
        $this->assertEquals('', $result);

        $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');
189
190
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
191
192
193
194
195
196
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|r:2');
        $this->assertEquals('', $result);

        $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|r:3');
        $this->assertEquals('', $result);

        $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
226
227
228

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

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

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

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

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

        $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
254
255
256
257
258
    /**
     * @throws CodeException
     * @throws UserFormException
     * @throws UserReportException
     */
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
291
292
293
294
295
296
    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');
297
298
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317

        $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');
318
319
//        $this->assertEquals('<span >?id=firstPage</span>', $result);
        $this->assertEquals('?id=firstPage', $result);
320
321

        $result = $link->renderLink('p:secondPage|r:3');
322
323
//        $this->assertEquals('<span >?id=secondPage</span>', $result);
        $this->assertEquals('?id=secondPage', $result);
324
325

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

        $result = $link->renderLink('p:secondPage|t:Example|r:3');
330
331
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
332
333
334

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

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

        $result = $link->renderLink('t:Example|r:4');
343
344
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
345
346

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

350
351
352
353
354
355
356
357
358
359
360
361
        // 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);
362
363
    }

Carsten  Rose's avatar
Carsten Rose committed
364
365
366
    /**
     * @throws UserReportException
     */
367
368
369
370
371
372
373
374
    public function testRenderModeMail() {
        $link = new Link(null, $this->sip, true);

        // r: default (0)
        $result = $link->renderLink('u');
        $this->assertEquals('', $result);

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

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

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

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

        $result = $link->renderLink('m:john@doe.com|r:0');
388
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);
389
390
391
392
393

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

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

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

        $result = $link->renderLink('m:john@doe.com|r:1');
401
        $this->assertEquals('<a href="mailto:john@doe.com" >mailto:john@doe.com</a>', $result);
402
403

        $result = $link->renderLink('t:Example|r:1');
404
405
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
406
407

        $result = $link->renderLink('m:john@doe.com|t:Example|r:1');
408
        $this->assertEquals('<a href="mailto:john@doe.com" >Example</a>', $result);
409
410
411
412
413
414
415
416
417
418
419
420

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

        $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');
421
        $this->assertEquals('<a href="mailto:john@doe.com" >Example</a>', $result);
422
423
424
425
426
427

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

        $result = $link->renderLink('m:john@doe.com|r:3');
428
429
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
430
431

        $result = $link->renderLink('t:Example|r:3');
432
433
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
434
435

        $result = $link->renderLink('m:john@doe.com|t:Example|r:3');
436
437
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
438
439
440
441
442
443

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

        $result = $link->renderLink('m:john@doe.com|r:4');
444
445
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
446
447

        $result = $link->renderLink('t:Example|r:4');
448
449
//        $this->assertEquals('<span >Example</span>', $result);
        $this->assertEquals('Example', $result);
450
451

        $result = $link->renderLink('m:john@doe.com|t:Example|r:4');
452
453
//        $this->assertEquals('<span >mailto:john@doe.com</span>', $result);
        $this->assertEquals('mailto:john@doe.com', $result);
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

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

        $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
469
470
471
    /**
     * @throws UserReportException
     */
472
473
474
475
476
477
478
479
    public function testRenderModeUrlPicture() {
        $link = new Link(null, $this->sip, true);

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

        $result = $link->renderLink('u:http://example.com|P:picture.gif');
480
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </a>', $result);
481
482
483
484
485

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

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

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

        $result = $link->renderLink('u:http://example.com|r:0|P:picture.gif');
493
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </a>', $result);
494
495
496
497
498

        $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');
499
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
500
501
502

        // r: 1
        $result = $link->renderLink('u|r:1|P:picture.gif');
503
504
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > ', $result);
505
506

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

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

        $result = $link->renderLink('u:http://example.com|t:Example|r:1|P:picture.gif');
514
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
515
516
517
518
519
520
521

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

        //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');
522
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </a>', $result);
523
524
525
526
527

        $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');
528
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</a>', $result);
529
530
531

        // r: 3:
        $result = $link->renderLink('u|r:3|P:picture.gif');
532
533
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > ', $result);
534
535

        $result = $link->renderLink('u:http://example.com|r:3|P:picture.gif');
536
537
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > ', $result);
538
539

        $result = $link->renderLink('t:Example|r:3|P:picture.gif');
540
541
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
542
543

        $result = $link->renderLink('u:http://example.com|t:Example|r:3|P:picture.gif');
544
545
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
546
547
548

        // r: 4
        $result = $link->renderLink('u|r:4|P:picture.gif');
549
550
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > </span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > ', $result);
551
552

        $result = $link->renderLink('u:http://example.com|r:4|P:picture.gif');
553
554
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
555
556

        $result = $link->renderLink('t:Example|r:4|P:picture.gif');
557
558
//        $this->assertEquals('<span ><img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example</span>', $result);
        $this->assertEquals('<img alt="Grafic: picture.gif" src="picture.gif" title="picture.gif" > Example', $result);
559
560

        $result = $link->renderLink('u:http://example.com|t:Example|r:4|P:picture.gif');
561
562
//        $this->assertEquals('<span >http://example.com</span>', $result);
        $this->assertEquals('http://example.com', $result);
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

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

        $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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
    /**
     * @throws UserReportException
     */
    public function testIcons() {
        $link = new Link(null, $this->sip, true);

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

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

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

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

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

        $result = $link->renderLink('u:http://example.com|S');
        $this->assertEquals('<a href="http://example.com" class="btn btn-default" title="Details" ><span class="glyphicon glyphicon glyphicon-search" ></span> </a>', $result);
    }

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

        $result = $link->renderLink('u:http://example.com|B');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:green');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:blue');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-blue.gif" title="blue" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:gray');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-gray.gif" title="gray" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:pink');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-pink.gif" title="pink" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:red');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-red.gif" title="red" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|B:yellow');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-yellow.gif" title="yellow" > </a>', $result);

    }

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

        $result = $link->renderLink('u:http://example.com|C');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|C:green');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-green.gif" title="green" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|C:blue');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-blue.gif" title="blue" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|C:gray');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-gray.gif" title="gray" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|C:pink');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-pink.gif" title="pink" > </a>', $result);

        $result = $link->renderLink('u:http://example.com|C:red');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/checked-red.gif" title="red" > </a>', $result);

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

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
    /**
     * @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
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
    /**
     * @throws SyntaxReportException
     */
    public function testLinkUrlParam() {
        $link = new Link(null, $this->sip, true);

        $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);
    }

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

        $result = $link->renderLink('u:http://example.com|U');
    }

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

        $result = $link->renderLink('u:http://example.com|U:');
734
735
    }

Carsten  Rose's avatar
Carsten Rose committed
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
    /**
     * @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');
        $this->assertEquals('<a href="http://example.com" ><img alt="hello world" src="image.gif" title="image.gif" > </a>', $result);

        // alt text empty
        $result = $link->renderLink('u:http://example.com|a:|P:image.gif');
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: image.gif" src="image.gif" title="image.gif" > </a>', $result);

        // 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);
    }

    /**
     * @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);
    }

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

        $result = $link->renderLink('u:http://example.com|c');
    }

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

        $result = $link->renderLink('u:http://example.com|c:');
    }

    /**
     * @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');
        $this->assertEquals('<a href="http://example.com" ><img src="typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif" title="green" > Hello World</a>', $result);

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

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

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

        // Picture, LEFT (Standard)
        $result = $link->renderLink('u:http://example.com|t:Hello World|P:image.gif');
        $this->assertEquals('<a href="http://example.com" ><img alt="Grafic: image.gif" src="image.gif" title="image.gif" > Hello World</a>', $result);

        // Picture, RIGHT
        $result = $link->renderLink('u:http://example.com|t:Hello World|P:image.gif|R');
        $this->assertEquals('<a href="http://example.com" >Hello World <img alt="Grafic: image.gif" src="image.gif" title="image.gif" ></a>', $result);

        // swapped param
        $result = $link->renderLink('R|P:image.gif|t:Hello World|u:http://example.com');
        $this->assertEquals('<a href="http://example.com" class="external" >Hello World <img alt="Grafic: image.gif" src="image.gif" title="image.gif" ></a>', $result);
    }


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

        // Sip: URL
903
904
        $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
905
906

        // Sip: Page
907
908
        $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
909
910
911
912
913
914
915

    }


    /**
     *
     */
Carsten  Rose's avatar
Carsten Rose committed
916
917
918
919
920
921
922
923
    protected function setUp() {
        parent::setUp();

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

    }
924
}