Projet

Général

Profil

Paste
Télécharger (22 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / handlers / views_handler_filter_string.test @ 651307cd

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Definition of ViewsHandlerFilterStringTest.
6
 */
7
8
/**
9
 * Tests the core views_handler_filter_string handler.
10
 */
11
class ViewsHandlerFilterStringTest extends ViewsSqlTest {
12
  var $column_map = array();
13
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Filter: String',
17
      'description' => 'Tests the core views_handler_filter_string handler.',
18
      'group' => 'Views Handlers',
19
    );
20
  }
21
22
  function setUp() {
23
    parent::setUp();
24
    $this->column_map = array(
25
      'views_test_name' => 'name',
26
    );
27
  }
28
29
  function viewsData() {
30
    $data = parent::viewsData();
31
    $data['views_test']['name']['filter']['allow empty'] = TRUE;
32
    $data['views_test']['job']['filter']['allow empty'] = FALSE;
33
    $data['views_test']['description'] = $data['views_test']['name'];
34
35
    return $data;
36
  }
37
38
  protected function schemaDefinition() {
39
    $schema = parent::schemaDefinition();
40
    $schema['views_test']['fields']['description'] = array(
41
      'description' => "A person's description",
42
      'type' => 'text',
43
      'not null' => FALSE,
44
      'size' => 'big',
45
    );
46
47
    return $schema;
48
  }
49
50
  /**
51
   * An extended test dataset.
52
   */
53
  protected function dataSet() {
54
    $dataset = parent::dataSet();
55
    $dataset[0]['description'] = 'John Winston Ono Lennon, MBE (9 October 1940 – 8 December 1980) was an English musician and singer-songwriter who rose to worldwide fame as one of the founding members of The Beatles, one of the most commercially successful and critically acclaimed acts in the history of popular music. Along with fellow Beatle Paul McCartney, he formed one of the most successful songwriting partnerships of the 20th century.';
56
    $dataset[1]['description'] = 'George Harrison,[1] MBE (25 February 1943 – 29 November 2001)[2] was an English rock guitarist, singer-songwriter, actor and film producer who achieved international fame as lead guitarist of The Beatles.';
57
    $dataset[2]['description'] = 'Richard Starkey, MBE (born 7 July 1940), better known by his stage name Ringo Starr, is an English musician, singer-songwriter, and actor who gained worldwide fame as the drummer for The Beatles.';
58
    $dataset[3]['description'] = 'Sir James Paul McCartney, MBE (born 18 June 1942) is an English musician, singer-songwriter and composer. Formerly of The Beatles (1960–1970) and Wings (1971–1981), McCartney is the most commercially successful songwriter in the history of popular music, according to Guinness World Records.[1]';
59
    $dataset[4]['description'] = NULL;
60
61
    return $dataset;
62
  }
63
64
  protected function getBasicView() {
65
    $view = parent::getBasicView();
66
    $view->display['default']->options['fields']['description'] = array(
67
      'id' => 'description',
68
      'table' => 'views_test',
69
      'field' => 'description',
70
      'relationship' => 'none',
71
    );
72
    return $view;
73
  }
74
75
  function testFilterStringEqual() {
76
    $view = $this->getBasicView();
77
78
    // Change the filtering
79
    $view->display['default']->handler->override_option('filters', array(
80
      'name' => array(
81
        'id' => 'name',
82
        'table' => 'views_test',
83
        'field' => 'name',
84
        'relationship' => 'none',
85
        'operator' => '=',
86
        'value' => 'Ringo',
87
      ),
88
    ));
89
90
    $this->executeView($view);
91
    $resultset = array(
92
      array(
93
        'name' => 'Ringo',
94
      ),
95
    );
96
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
97
  }
98
99
  function testFilterStringGroupedExposedEqual() {
100
    $filters = $this->getGroupedExposedFilters();
101
    $view = $this->getBasicPageView();
102
103
    // Filter: Name, Operator: =, Value: Ringo
104
    $filters['name']['group_info']['default_group'] = 1;
105
    $view->set_display('page_1');
106
    $view->display['page_1']->handler->override_option('filters', $filters);
107
108
    $this->executeView($view);
109
110
    $resultset = array(
111
      array(
112
        'name' => 'Ringo',
113
      ),
114
    );
115
116
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
117
  }
118
119
  function testFilterStringNotEqual() {
120
    $view = $this->getBasicView();
121
122
    // Change the filtering
123
    $view->display['default']->handler->override_option('filters', array(
124
      'name' => array(
125
        'id' => 'name',
126
        'table' => 'views_test',
127
        'field' => 'name',
128
        'relationship' => 'none',
129
        'operator' => '!=',
130
        'value' => array('value' => 'Ringo'),
131
      ),
132
    ));
133
134
    $this->executeView($view);
135
    $resultset = array(
136
      array(
137
        'name' => 'John',
138
      ),
139
      array(
140
        'name' => 'George',
141
      ),
142
      array(
143
        'name' => 'Paul',
144
      ),
145
      array(
146
        'name' => 'Meredith',
147
      ),
148
    );
149
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
150
  }
151
152
  function testFilterStringGroupedExposedNotEqual() {
153
    $filters = $this->getGroupedExposedFilters();
154
    $view = $this->getBasicPageView();
155
156
    // Filter: Name, Operator: !=, Value: Ringo
157
    $filters['name']['group_info']['default_group'] = '2';
158
159
    $view->set_display('page_1');
160
    $view->display['page_1']->handler->override_option('filters', $filters);
161
162
    $this->executeView($view);
163
164
    $resultset = array(
165
      array(
166
        'name' => 'John',
167
      ),
168
      array(
169
        'name' => 'George',
170
      ),
171
      array(
172
        'name' => 'Paul',
173
      ),
174
      array(
175
        'name' => 'Meredith',
176
      ),
177
    );
178
179
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
180
  }
181
182
  function testFilterStringContains() {
183
    $view = $this->getBasicView();
184
185
    // Change the filtering
186
    $view->display['default']->handler->override_option('filters', array(
187
      'name' => array(
188
        'id' => 'name',
189
        'table' => 'views_test',
190
        'field' => 'name',
191
        'relationship' => 'none',
192
        'operator' => 'contains',
193
        'value' => 'ing',
194
      ),
195
    ));
196
197
    $this->executeView($view);
198
    $resultset = array(
199
      array(
200
        'name' => 'Ringo',
201
      ),
202
    );
203
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
204
  }
205
206
207
  function testFilterStringGroupedExposedContains() {
208
    $filters = $this->getGroupedExposedFilters();
209
    $view = $this->getBasicPageView();
210
211
    // Filter: Name, Operator: contains, Value: ing
212
    $filters['name']['group_info']['default_group'] = '3';
213
    $view->set_display('page_1');
214
    $view->display['page_1']->handler->override_option('filters', $filters);
215
216
    $this->executeView($view);
217
218
    $resultset = array(
219
      array(
220
        'name' => 'Ringo',
221
      ),
222
    );
223
224
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
225
  }
226
227
228
  function testFilterStringWord() {
229
    $view = $this->getBasicView();
230
231
    // Change the filtering
232
    $view->display['default']->handler->override_option('filters', array(
233
      'description' => array(
234
        'id' => 'description',
235
        'table' => 'views_test',
236
        'field' => 'description',
237
        'relationship' => 'none',
238
        'operator' => 'word',
239
        'value' => 'actor',
240
      ),
241
    ));
242
243
    $this->executeView($view);
244
    $resultset = array(
245
      array(
246
        'name' => 'George',
247
      ),
248
      array(
249
        'name' => 'Ringo',
250
      ),
251
    );
252
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
253
    $view->destroy();
254
255
    $view = $this->getBasicView();
256
257
    // Change the filtering
258
    $view->display['default']->handler->override_option('filters', array(
259
      'description' => array(
260
        'id' => 'description',
261
        'table' => 'views_test',
262
        'field' => 'description',
263
        'relationship' => 'none',
264
        'operator' => 'allwords',
265
        'value' => 'Richard Starkey',
266
      ),
267
    ));
268
269
    $this->executeView($view);
270
    $resultset = array(
271
      array(
272
        'name' => 'Ringo',
273
      ),
274
    );
275
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
276
  }
277
278
279
  function testFilterStringGroupedExposedWord() {
280
      $filters = $this->getGroupedExposedFilters();
281
    $view = $this->getBasicPageView();
282
283
    // Filter: Name, Operator: contains, Value: ing
284
    $filters['name']['group_info']['default_group'] = '3';
285
    $view->set_display('page_1');
286
    $view->display['page_1']->handler->override_option('filters', $filters);
287
288
    $this->executeView($view);
289
290
    $resultset = array(
291
      array(
292
        'name' => 'Ringo',
293
      ),
294
    );
295
296
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
297
    $view->destroy();
298
299
    $filters = $this->getGroupedExposedFilters();
300
    $view = $this->getBasicPageView();
301
302
    // Filter: Description, Operator: contains, Value: actor
303
    $filters['description']['group_info']['default_group'] = '1';
304
    $view->set_display('page_1');
305
    $view->display['page_1']->handler->override_option('filters', $filters);
306
307
    $this->executeView($view);
308
    $resultset = array(
309
      array(
310
        'name' => 'George',
311
      ),
312
      array(
313
        'name' => 'Ringo',
314
      ),
315
    );
316
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
317
  }
318
319
  function testFilterStringStarts() {
320
    $view = $this->getBasicView();
321
322
    // Change the filtering
323
    $view->display['default']->handler->override_option('filters', array(
324
      'description' => array(
325
        'id' => 'description',
326
        'table' => 'views_test',
327
        'field' => 'description',
328
        'relationship' => 'none',
329
        'operator' => 'starts',
330
        'value' => 'George',
331
      ),
332
    ));
333
334
    $this->executeView($view);
335
    $resultset = array(
336
      array(
337
        'name' => 'George',
338
      ),
339
    );
340
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
341
  }
342
343
  function testFilterStringGroupedExposedStarts() {
344
    $filters = $this->getGroupedExposedFilters();
345
    $view = $this->getBasicPageView();
346
347
    // Filter: Name, Operator: starts, Value: George
348
    $filters['description']['group_info']['default_group'] = 2;
349
    $view->set_display('page_1');
350
    $view->display['page_1']->handler->override_option('filters', $filters);
351
352
    $this->executeView($view);
353
354
    $resultset = array(
355
      array(
356
        'name' => 'George',
357
      ),
358
    );
359
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
360
  }
361
362
  function testFilterStringNotStarts() {
363
    $view = $this->getBasicView();
364
365
    // Change the filtering
366
    $view->display['default']->handler->override_option('filters', array(
367
      'description' => array(
368
        'id' => 'description',
369
        'table' => 'views_test',
370
        'field' => 'description',
371
        'relationship' => 'none',
372
        'operator' => 'not_starts',
373
        'value' => 'George',
374
      ),
375
    ));
376
377
    $this->executeView($view);
378
    $resultset = array(
379
      array(
380
        'name' => 'John',
381
      ),
382
      array(
383
        'name' => 'Ringo',
384
      ),
385
      array(
386
        'name' => 'Paul',
387
      ),
388
      // There is no Meredith returned because his description is empty
389
    );
390
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
391
  }
392
393
  function testFilterStringGroupedExposedNotStarts() {
394
    $filters = $this->getGroupedExposedFilters();
395
    $view = $this->getBasicPageView();
396
397
    // Filter: Name, Operator: not_starts, Value: George
398
    $filters['description']['group_info']['default_group'] = 3;
399
    $view->set_display('page_1');
400
    $view->display['page_1']->handler->override_option('filters', $filters);
401
402
    $this->executeView($view);
403
404
    $resultset = array(
405
      array(
406
        'name' => 'John',
407
      ),
408
      array(
409
        'name' => 'Ringo',
410
      ),
411
      array(
412
        'name' => 'Paul',
413
      ),
414
      // There is no Meredith returned because his description is empty
415
    );
416
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
417
  }
418
419
  function testFilterStringEnds() {
420
    $view = $this->getBasicView();
421
422
    // Change the filtering
423
    $view->display['default']->handler->override_option('filters', array(
424
      'description' => array(
425
        'id' => 'description',
426
        'table' => 'views_test',
427
        'field' => 'description',
428
        'relationship' => 'none',
429
        'operator' => 'ends',
430
        'value' => 'Beatles.',
431
      ),
432
    ));
433
434
    $this->executeView($view);
435
    $resultset = array(
436
      array(
437
        'name' => 'George',
438
      ),
439
      array(
440
        'name' => 'Ringo',
441
      ),
442
    );
443
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
444
  }
445
446
  function testFilterStringGroupedExposedEnds() {
447
    $filters = $this->getGroupedExposedFilters();
448
    $view = $this->getBasicPageView();
449
450
    // Filter: Descriptino, Operator: ends, Value: Beatles
451
    $filters['description']['group_info']['default_group'] = 4;
452
    $view->set_display('page_1');
453
    $view->display['page_1']->handler->override_option('filters', $filters);
454
455
    $this->executeView($view);
456
457
    $resultset = array(
458
      array(
459
        'name' => 'George',
460
      ),
461
      array(
462
        'name' => 'Ringo',
463
      ),
464
    );
465
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
466
  }
467
468
  function testFilterStringNotEnds() {
469
    $view = $this->getBasicView();
470
471
    // Change the filtering
472
    $view->display['default']->handler->override_option('filters', array(
473
      'description' => array(
474
        'id' => 'description',
475
        'table' => 'views_test',
476
        'field' => 'description',
477
        'relationship' => 'none',
478
        'operator' => 'not_ends',
479
        'value' => 'Beatles.',
480
      ),
481
    ));
482
483
    $this->executeView($view);
484
    $resultset = array(
485
      array(
486
        'name' => 'John',
487
      ),
488
      array(
489
        'name' => 'Paul',
490
      ),
491
      // There is no Meredith returned because his description is empty
492
    );
493
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
494
  }
495
496
  function testFilterStringGroupedExposedNotEnds() {
497
    $filters = $this->getGroupedExposedFilters();
498
    $view = $this->getBasicPageView();
499
500
    // Filter: Description, Operator: not_ends, Value: Beatles
501
    $filters['description']['group_info']['default_group'] = 5;
502
    $view->set_display('page_1');
503
    $view->display['page_1']->handler->override_option('filters', $filters);
504
505
    $this->executeView($view);
506
507
    $resultset = array(
508
      array(
509
        'name' => 'John',
510
      ),
511
      array(
512
        'name' => 'Paul',
513
      ),
514
      // There is no Meredith returned because his description is empty
515
    );
516
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
517
  }
518
519
  function testFilterStringNot() {
520
    $view = $this->getBasicView();
521
522
    // Change the filtering
523
    $view->display['default']->handler->override_option('filters', array(
524
      'description' => array(
525
        'id' => 'description',
526
        'table' => 'views_test',
527
        'field' => 'description',
528
        'relationship' => 'none',
529
        'operator' => 'not',
530
        'value' => 'Beatles.',
531
      ),
532
    ));
533
534
    $this->executeView($view);
535
    $resultset = array(
536
      array(
537
        'name' => 'John',
538
      ),
539
      array(
540
        'name' => 'Paul',
541
      ),
542
      // There is no Meredith returned because his description is empty
543
    );
544
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
545
  }
546
547
548
  function testFilterStringGroupedExposedNot() {
549
    $filters = $this->getGroupedExposedFilters();
550
    $view = $this->getBasicPageView();
551
552
    // Filter: Description, Operator: not (does not contains), Value: Beatles
553
    $filters['description']['group_info']['default_group'] = 6;
554
    $view->set_display('page_1');
555
    $view->display['page_1']->handler->override_option('filters', $filters);
556
557
    $this->executeView($view);
558
559
    $resultset = array(
560
      array(
561
        'name' => 'John',
562
      ),
563
      array(
564
        'name' => 'Paul',
565
      ),
566
      // There is no Meredith returned because his description is empty
567
    );
568
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
569
570
  }
571
572
  function testFilterStringShorter() {
573
    $view = $this->getBasicView();
574
575
    // Change the filtering
576
    $view->display['default']->handler->override_option('filters', array(
577
      'name' => array(
578
        'id' => 'name',
579
        'table' => 'views_test',
580
        'field' => 'name',
581
        'relationship' => 'none',
582
        'operator' => 'shorterthan',
583
        'value' => 5,
584
      ),
585
    ));
586
587
    $this->executeView($view);
588
    $resultset = array(
589
      array(
590
        'name' => 'John',
591
      ),
592
      array(
593
        'name' => 'Paul',
594
      ),
595
    );
596
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
597
  }
598
599
  function testFilterStringGroupedExposedShorter() {
600
    $filters = $this->getGroupedExposedFilters();
601
    $view = $this->getBasicPageView();
602
603
    // Filter: Name, Operator: shorterthan, Value: 5
604
    $filters['name']['group_info']['default_group'] = 4;
605
    $view->set_display('page_1');
606
    $view->display['page_1']->handler->override_option('filters', $filters);
607
608
    $this->executeView($view);
609
    $resultset = array(
610
      array(
611
        'name' => 'John',
612
      ),
613
      array(
614
        'name' => 'Paul',
615
      ),
616
    );
617
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
618
  }
619
620
  function testFilterStringLonger() {
621
    $view = $this->getBasicView();
622
623
    // Change the filtering
624
    $view->display['default']->handler->override_option('filters', array(
625
      'name' => array(
626
        'id' => 'name',
627
        'table' => 'views_test',
628
        'field' => 'name',
629
        'relationship' => 'none',
630
        'operator' => 'longerthan',
631
        'value' => 7,
632
      ),
633
    ));
634
635
    $this->executeView($view);
636
    $resultset = array(
637
      array(
638
        'name' => 'Meredith',
639
      ),
640
    );
641
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
642
  }
643
644
  function testFilterStringGroupedExposedLonger() {
645
    $filters = $this->getGroupedExposedFilters();
646
    $view = $this->getBasicPageView();
647
648
    // Filter: Name, Operator: longerthan, Value: 4
649
    $filters['name']['group_info']['default_group'] = 5;
650
    $view->set_display('page_1');
651
    $view->display['page_1']->handler->override_option('filters', $filters);
652
653
    $this->executeView($view);
654
    $resultset = array(
655
      array(
656
        'name' => 'Meredith',
657
      ),
658
    );
659
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
660
  }
661
662
663
  function testFilterStringEmpty() {
664
    $view = $this->getBasicView();
665
666
    // Change the filtering
667
    $view->display['default']->handler->override_option('filters', array(
668
      'description' => array(
669
        'id' => 'description',
670
        'table' => 'views_test',
671
        'field' => 'description',
672
        'relationship' => 'none',
673
        'operator' => 'empty',
674
      ),
675
    ));
676
677
    $this->executeView($view);
678
    $resultset = array(
679
      array(
680
        'name' => 'Meredith',
681
      ),
682
    );
683
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
684
  }
685
686
  function testFilterStringGroupedExposedEmpty() {
687
    $filters = $this->getGroupedExposedFilters();
688
    $view = $this->getBasicPageView();
689
690
    // Filter: Description, Operator: empty, Value:
691
    $filters['description']['group_info']['default_group'] = 7;
692
    $view->set_display('page_1');
693
    $view->display['page_1']->handler->override_option('filters', $filters);
694
695
    $this->executeView($view);
696
    $resultset = array(
697
      array(
698
        'name' => 'Meredith',
699
      ),
700
    );
701
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
702
  }
703
704
  protected function getGroupedExposedFilters() {
705
    $filters = array(
706
      'name' => array(
707
        'id' => 'name',
708
        'table' => 'views_test',
709
        'field' => 'name',
710
        'relationship' => 'none',
711
        'exposed' => TRUE,
712
        'expose' => array(
713
          'operator' => 'name_op',
714
          'label' => 'name',
715
          'identifier' => 'name',
716
        ),
717
        'is_grouped' => TRUE,
718
        'group_info' => array(
719
          'label' => 'name',
720
          'identifier' => 'name',
721
          'default_group' => 'All',
722
          'group_items' => array(
723
            1 => array(
724
              'title' => 'Is Ringo',
725
              'operator' => '=',
726
              'value' => 'Ringo',
727
            ),
728
            2 => array(
729
              'title' => 'Is not Ringo',
730
              'operator' => '!=',
731
              'value' => array('value' => 'Ringo'),
732
            ),
733
            3 => array(
734
              'title' => 'Contains ing',
735
              'operator' => 'contains',
736
              'value' => 'ing',
737
            ),
738
            4 => array(
739
              'title' => 'Shorter than 5 letters',
740
              'operator' => 'shorterthan',
741
              'value' => 5,
742
            ),
743
            5 => array(
744
              'title' => 'Longer than 7 letters',
745
              'operator' => 'longerthan',
746
              'value' => 7,
747
            ),
748
          ),
749
        ),
750
      ),
751
      'description' => array(
752
        'id' => 'description',
753
        'table' => 'views_test',
754
        'field' => 'description',
755
        'relationship' => 'none',
756
        'exposed' => TRUE,
757
        'expose' => array(
758
          'operator' => 'description_op',
759
          'label' => 'description',
760
          'identifier' => 'description',
761
        ),
762
        'is_grouped' => TRUE,
763
        'group_info' => array(
764
          'label' => 'description',
765
          'identifier' => 'description',
766
          'default_group' => 'All',
767
          'group_items' => array(
768
            1 => array(
769
              'title' => 'Contains the word: Actor',
770
              'operator' => 'word',
771
              'value' => 'actor',
772
            ),
773
            2 => array(
774
              'title' => 'Starts with George',
775
              'operator' => 'starts',
776
              'value' => 'George',
777
            ),
778
            3 => array(
779
              'title' => 'Not Starts with: George',
780
              'operator' => 'not_starts',
781
              'value' => 'George',
782
            ),
783
            4 => array(
784
              'title' => 'Ends with: Beatles',
785
              'operator' => 'ends',
786
              'value' => 'Beatles.',
787
            ),
788
            5 => array(
789
              'title' => 'Not Ends with: Beatles',
790
              'operator' => 'not_ends',
791
              'value' => 'Beatles.',
792
            ),
793
            6 => array(
794
              'title' => 'Does not contain: Beatles',
795
              'operator' => 'not',
796
              'value' => 'Beatles.',
797
            ),
798
            7 => array(
799
              'title' => 'Empty description',
800
              'operator' => 'empty',
801
              'value' => '',
802
            ),
803
          ),
804
        ),
805
      ),
806
    );
807
    return $filters;
808
  }
809
810
}