File: myComponentTest.php

package info (click to toggle)
awl 0.64-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: php: 6,291; sql: 109; sh: 70; makefile: 55
file content (450 lines) | stat: -rw-r--r-- 16,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?php
/**
 * Created by JetBrains PhpStorm.
 * User: milan
 * Date: 7/5/13
 * Time: 2:01 PM
 * To change this template use File | Settings | File Templates.
 */
require_once 'inc/vComponent.php';

// compatibility with phpunit 6
if (!class_exists('\PHPUnit_Framework_TestCase') &&
    class_exists('\PHPUnit\Framework\TestCase')) {
    class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}

class myComponentTest extends PHPUnit_Framework_TestCase {
    public $testdata = <<<EOBODY1
BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
EOBODY1;

    public $simpledata1 = <<<EOSIMPLEDATA1
BEGIN:VCALENDAR
SUMARY:12234567890122345678901223456789012234567890122345678901223467890
 122345678901223456789012
END:VCALENDAR
EOSIMPLEDATA1;

    function testParseComponents() {

       // $lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/tzid_data.test');
        $component = new vComponent($data);

        $this->assertEquals(8, $component->ComponentCount());
        $type = $component->GetType();
        $this->assertStringStartsWith('VCALENDAR', $type );
        $child = $component->getComponentAt(0);
        $this->assertNotNull($child);

        $childtype = $child->GetType();

        $this->assertStringStartsWith('VEVENT', $childtype );
        $this->assertEquals(1, $child->ComponentCount());
    }


    function testParseProperties(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);
        //$component = new vComponent();

        $this->assertEquals(4, $component->propertiesCount());
        $property1 = $component->getPropertyAt(0);
        $this->assertNotNull($property1);
    }


    function testGetNameProperties(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $this->assertEquals(4, $component->propertiesCount());
    }

    function te1stGetNameProperties2(){
        $lines = new HeapLines((new bigtestdata)->data);
        for($i = 0; $i < 100; $i++)
            $component = new vComponent($lines);

        //$this->assertEquals(4, $component->propertiesCount());
    }

    function testCollectParameterValues(){
//        /$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/tzid_data.test');
        $component = new vComponent($data);

        $parameters = $component->CollectParameterValues('TZID');

        $this->equalTo(4, count($parameters));
        $this->assertArrayHasKey('America/Los_Angeles', $parameters );
    }

    function testGetProperty(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $property = $component->GetProperty("VERSION");
        $this->assertNotNull($property);
        $this->assertInstanceOf('vProperty', $property);
    }

    function testGetPropertyAndChange(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);
        $this->assertTrue($component->isValid());
        $property = $component->GetProperty("VERSION");
        $this->assertTrue($component->isValid());
        $this->assertNotNull($property);
        $this->assertInstanceOf('vProperty', $property);
        $this->assertTrue($component->isValid());
        $property->Name("ahoj");
        $this->assertFalse($component->isValid());
    }


    function testGetNestedPropertyAndChange(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $nestedComponent = $component->getComponentAt(0);
        $nestedProperty = $nestedComponent->getPropertyAt(0);

        $name = $nestedProperty->Name();
        $this->assertTrue($component->isValid());
        $nestedProperty->Name($name . "TEST");
        $this->assertFalse($component->isValid());


    }

    function testGetPValue(){
//        /$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $property = $component->GetPValue("VERSION");
        $this->assertNotNull($property);
        $this->assertStringStartsWith('2.0', $property);
    }

    function testGetPropertiesWithName(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $properties = $component->GetProperties("VERSION");
        $this->assertNotNull($properties);
        $this->assertCount(1, $properties);
        $this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testGetPropertiesWithArray(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $properties = $component->GetProperties(["VERSION" => true, "CALSCALE" => true]);
        $this->assertNotNull($properties);
        $this->assertCount(2, $properties);
        $this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testGetPropertiesNoParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $properties = $component->GetProperties();
        $this->assertNotNull($properties);
        $this->assertCount(4, $properties);
        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }



    function testClearPropertiesNoParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $this->assertEquals(4, $component->propertiesCount());
        $component->ClearProperties();
        $this->assertEquals(0, $component->propertiesCount());
        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testClearPropertiesStringParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $this->assertEquals(4, $component->propertiesCount());
        $component->ClearProperties('VERSION');
        $this->assertEquals(3, $component->propertiesCount());
        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testClearPropertiesArrayParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $this->assertEquals(4, $component->propertiesCount());
        $component->ClearProperties(["VERSION" => true, "CALSCALE" => true]);
        $this->assertEquals(2, $component->propertiesCount());
        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }


    function testAddPropertyLikeProperty(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $property = new vProperty('HELLO');

        $this->assertEquals(4, $component->propertiesCount());
        $component->AddProperty($property);
        $this->assertEquals(5, $component->propertiesCount());
        $this->assertFalse($component->isValid());
        $p = $component->GetProperties(["HELLO" => true ]);
        $this->assertNotNull($p);

        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testAddPropertyLikeNameAndValue(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);


        $this->assertEquals(4, $component->propertiesCount());
        $component->AddProperty("HELLO", "WORLD");
        $this->assertEquals(5, $component->propertiesCount());
        $this->assertFalse($component->isValid());
        $p = $component->GetProperties(["HELLO" => true ]);
        $this->assertNotNull($p);

        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testComponentsNoParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/tzid_data.test');
        $component = new vComponent($data);


        $p = $component->GetComponents();
        $this->assertNotNull($p);
        $this->assertCount(8, $p);

        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testComponentsByName(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/tzid_data.test');
        $component = new vComponent($data);


        $p = $component->GetComponents("VEVENT");
        $this->assertNotNull($p);
        $this->assertCount(8, $p);
        foreach($p as $item){
            $this->assertStringStartsWith("VEVENT", $item->GetType());
        }

        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }

    function testComponentsByArray(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/tzid_data.test');
        $component = new vComponent($data);


        $p = $component->GetComponents(["VEVENT" => true]);
        $this->assertNotNull($p);
        $this->assertCount(8, $p);
        foreach($p as $item){
            $this->assertStringStartsWith("VEVENT", $item->GetType());
        }

        //$this->assertStringStartsWith('2.0', $properties[0]->Value());
    }


    function testClearComponentsNoParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);


        $component->ClearComponents();
        $this->assertEquals(0, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testClearComponentsArrayParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);


        $component->ClearComponents(["VEVENT" => true]);
        $this->assertEquals(0, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testClearComponentsStringParam(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);


        $component->ClearComponents("VEVENT");
        $this->assertEquals(0, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testSetComponent(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $newcomponent = new vComponent("BEGIN:VEVENT");
        $newcomponent2 = new vComponent("BEGIN:VEVENT");

        $component->SetComponents([$newcomponent, $newcomponent2]);
        $this->assertEquals(2, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testAddComponents(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $component = new vComponent($data);

        $newcomponent = new vComponent("BEGIN:VEVENT");
        $newcomponent2 = new vComponent("BEGIN:VEVENT");
        $newcomponent3 = new vComponent("BEGIN:VEVENT");


        $component->SetComponents([$newcomponent]);
        $component->AddComponent([$newcomponent2, $newcomponent3]);
        $this->assertEquals(3, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testAddComponentsWithEmptyComponents(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $component = new vComponent("VCALENDAR");

        $newcomponent = new vComponent("VEVENT");
        $newcomponent2 = new vComponent("VEVENT");
        $newcomponent3 = new vComponent("VEVENT");

        $this->assertEquals(0, $component->ComponentCount());
        $component->AddComponent([$newcomponent]);
        $this->assertEquals(1, $component->ComponentCount());

        $component->AddComponent([$newcomponent2, $newcomponent3]);
        $this->assertEquals(3, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }

    function testMaskComponents(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $component = new vComponent("VCALENDAR");

        $newcomponent = new vComponent("BEGIN:VEVENT");
        $newcomponent2 = new vComponent("BEGIN:MASK");
        $newcomponent3 = new vComponent("BEGIN:VEVENT");

        $component->AddComponent([$newcomponent, $newcomponent2, $newcomponent3]);
        $this->assertEquals(3, $component->ComponentCount());
        $component->MaskComponents(["MASK" => true]);
        $this->assertEquals(1, $component->ComponentCount());
        $this->assertFalse($component->isValid());

    }


    function testMaskProperties(){
        //$lines = new HeapLines((new bigtestdata)->testdata2);
        $component = new vComponent("BEGIN:VCALENDAR\nEND:VCALENDAR");

        $newcomponent = new vProperty("VEVENT");
        $newcomponent2 = new vProperty("MASK");
        $newcomponent3 = new vProperty("VEVENT");

        $component->AddProperty($newcomponent);
        $component->AddProperty($newcomponent2);
        $component->AddProperty($newcomponent3);
        $this->assertEquals(3, $component->propertiesCount());
        $component->MaskProperties(["MASK" => true]);
        $this->assertEquals(1, $component->propertiesCount());
        $this->assertFalse($component->isValid());

    }



    function te2stRenderCreated(){

        $component = new vComponent("BEGIN:VCALENDAR");
        $component->AddProperty("SUMARY", "12234567890122345678901223456789012234567890122345678901223467890122345678901223456789012");
        $text = $component->Render();

        //$this->assertStringStartsWith($this->simpledata1, $text);
    }

    function testRenderNoChanges2(){
//        $testdata = new bigtestdata();
//        //$lines = new HeapLines($this->simpledata1);
//        $component = new vComponent((new bigtestdata)->testdata2);
//        //$component->AddProperty("SUMARY", "12234567890122345678901223456789012234567890122345678901223467890122345678901223456789012");
//        $text = $component->Render();

        //$this->assertStringStartsWith($this->simpledata1, $text);
    }

    function getData($filename){
        $file = fopen($filename, 'r');
        $data = fread($file, filesize($filename));
        fclose($file);
        return $data;
    }

    function testInnerAlarmPresent(){
        $data = $this->getData('tests/data/inner_valarmdata.test');
        $vComponent = new vComponent($data);
        $this->assertEquals(4, $vComponent->propertiesCount());
        $components = $vComponent->GetComponents();

        $this->assertEquals(1, count($components));
        $inner = $components[0];
        $this->assertEquals(1, $inner->ComponentCount());
        $this->assertEquals(20, $inner->propertiesCount());
        $this->assertEquals(5, $inner->GetComponents()[0]->propertiesCount());
    }

}