Projet

Général

Profil

Révision 4003efde

Ajouté par Assos Assos il y a environ 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/tests/handlers/views_handler_filter_numeric.test
19 19
    );
20 20
  }
21 21

  
22
  function setUp() {
23
    parent::setUp();
22
  /**
23
   * {@inheritdoc}
24
   */
25
  protected function dataSet() {
26
    $data_set = parent::dataSet();
27
    $data_set[] = array(
28
      'name' => 'Charles',
29
      'age' => NULL,
30
      'job' => 'Bassist',
31
        'created' => gmmktime(6, 30, 10, 1, 1, 2001),
32
    );
33
    return $data_set;
34
  }
35

  
36
  /**
37
   * {@inheritdoc}
38
   */
39
  protected function schemaDefinition() {
40
    $schema = parent::schemaDefinition();
41
    $schema['views_test']['fields']['age']['not null'] = FALSE;
42
    $schema['views_test']['indexes'] = array();
43
    return $schema;
44
  }
45

  
46
  /**
47
   * {@inheritdoc}
48
   */
49
  public function setUp(array $modules = array()) {
50
    parent::setUp($modules);
51

  
24 52
    $this->column_map = array(
25 53
      'views_test_name' => 'name',
26 54
      'views_test_age' => 'age',
......
114 142
    );
115 143
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
116 144

  
117
    // test not between.
145
    // Test not between.
118 146
    $view->delete();
119 147
    $view = $this->getBasicView();
120 148

  
......
182 210
    $filters = $this->getGroupedExposedFilters();
183 211
    $view = $this->getBasicPageView();
184 212

  
185
    // Filter: Age, Operator: between, Value: 26 and 29
213
    // Filter: Age, Operator: not between, Value: 26 and 29
186 214
    $filters['age']['group_info']['default_group'] = 3;
187 215
    $view->set_display('page_1');
188 216
    $view->display['page_1']->handler->override_option('filters', $filters);
......
221 249
    ));
222 250

  
223 251
    $this->executeView($view);
224
    $resultset = array();
252
    $resultset = array(
253
      array(
254
        'name' => 'Charles',
255
        'age' => NULL,
256
      ),
257
    );
225 258
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
226 259

  
227 260
    $view->delete();
......
275 308
    $view->display['page_1']->handler->override_option('filters', $filters);
276 309

  
277 310
    $this->executeView($view);
278
    $resultset = array();
311
    $resultset = array(
312
      array(
313
        'name' => 'Charles',
314
        'age' => NULL,
315
      ),
316
    );
279 317
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
280 318
  }
281 319

  
......
346 384
    }
347 385
  }
348 386

  
387
  /**
388
   * Tests exposed numeric filter with exposed operator.
389
   */
390
  public function testFilterNumericExposedOperator() {
391
    $this->applyFilterNumericExposedOperator('=', array('value' => '27'), array(
392
      array(
393
        'name' => 'George',
394
        'age' => 27,
395
      ),
396
    ));
397
    $this->applyFilterNumericExposedOperator('<', array('value' => '27'), array(
398
      array(
399
        'name' => 'John',
400
        'age' => 25,
401
      ),
402
      array(
403
        'name' => 'Paul',
404
        'age' => 26,
405
      ),
406
    ));
407
    $this->applyFilterNumericExposedOperator('<=', array(
408
      'value' => '27',
409
    ), array(
410
      array(
411
        'name' => 'John',
412
        'age' => 25,
413
      ),
414
      array(
415
        'name' => 'George',
416
        'age' => 27,
417
      ),
418
      array(
419
        'name' => 'Paul',
420
        'age' => 26,
421
      ),
422
    ));
423
    $this->applyFilterNumericExposedOperator('!=', array(
424
      'value' => '27',
425
    ), array(
426
      array(
427
        'name' => 'John',
428
        'age' => 25,
429
      ),
430
      array(
431
        'name' => 'Ringo',
432
        'age' => 28,
433
      ),
434
      array(
435
        'name' => 'Paul',
436
        'age' => 26,
437
      ),
438
      array(
439
        'name' => 'Meredith',
440
        'age' => 30,
441
      ),
442
    ));
443
    $this->applyFilterNumericExposedOperator('>=', array(
444
      'value' => '27',
445
    ), array(
446
      array(
447
        'name' => 'George',
448
        'age' => 27,
449
      ),
450
      array(
451
        'name' => 'Ringo',
452
        'age' => 28,
453
      ),
454
      array(
455
        'name' => 'Meredith',
456
        'age' => 30,
457
      ),
458
    ));
459
    $this->applyFilterNumericExposedOperator('>', array('value' => '27'), array(
460
      array(
461
        'name' => 'Ringo',
462
        'age' => 28,
463
      ),
464
      array(
465
        'name' => 'Meredith',
466
        'age' => 30,
467
      ),
468
    ));
469
    $this->applyFilterNumericExposedOperator('between', array(
470
      'min' => '28',
471
      'max' => '31',
472
    ), array(
473
      array(
474
        'name' => 'Ringo',
475
        'age' => 28,
476
      ),
477
      array(
478
        'name' => 'Meredith',
479
        'age' => 30,
480
      ),
481
    ));
482
    $this->applyFilterNumericExposedOperator('not between', array(
483
      'min' => '28',
484
      'max' => '31',
485
    ), array(
486
      array(
487
        'name' => 'John',
488
        'age' => 25,
489
      ),
490
      array(
491
        'name' => 'George',
492
        'age' => 27,
493
      ),
494
      array(
495
        'name' => 'Ringo',
496
        'age' => 28,
497
      ),
498
      array(
499
        'name' => 'Paul',
500
        'age' => 26,
501
      ),
502
    ));
503
    $this->applyFilterNumericExposedOperator('empty', array(), array(
504
      array(
505
        'name' => 'Charles',
506
        'age' => NULL,
507
      ),
508
    ));
509
    $this->applyFilterNumericExposedOperator('not empty', array(), array(
510
      array(
511
        'name' => 'John',
512
        'age' => 25,
513
      ),
514
      array(
515
        'name' => 'George',
516
        'age' => 27,
517
      ),
518
      array(
519
        'name' => 'Ringo',
520
        'age' => 28,
521
      ),
522
      array(
523
        'name' => 'Paul',
524
        'age' => 26,
525
      ),
526
      array(
527
        'name' => 'Meredith',
528
        'age' => 30,
529
      ),
530
    ));
531
    $this->applyFilterNumericExposedOperator('regular_expression', array(
532
      'value' => '^(0|[1-9][0-9]*)$',
533
    ), array(
534
      array(
535
        'name' => 'John',
536
        'age' => 25,
537
      ),
538
      array(
539
        'name' => 'George',
540
        'age' => 27,
541
      ),
542
      array(
543
        'name' => 'Ringo',
544
        'age' => 28,
545
      ),
546
      array(
547
        'name' => 'Paul',
548
        'age' => 26,
549
      ),
550
      array(
551
        'name' => 'Meredith',
552
        'age' => 30,
553
      ),
554
    ));
555
    $this->applyFilterNumericExposedOperator('not_regular_expression', array(
556
      'value' => '^(0|[1-9][0-9]*)$',
557
    ), array());
558
  }
559

  
560
  /**
561
   * Tests exposed numeric filter with an individual exposed operator.
562
   *
563
   * @param string $operator
564
   *   Operator to test.
565
   * @param array $value
566
   *   Filter value to use in exposed input. Keys might be 'value', 'min' or
567
   *   'max'. If one of those keys doesn't exist, an empty string is used as the
568
   *   key's value.
569
   * @param array $resultset
570
   *   The expected result set.
571
   */
572
  protected function applyFilterNumericExposedOperator($operator, array $value, array $resultset) {
573
    $exposed_input = array(
574
      'age' => ($value += array(
575
        'value' => '',
576
        'min' => '',
577
        'max' => '',
578
      )),
579
      'age_op' => $operator,
580
    );
581
    $filters = array(
582
      'age' => array(
583
        'id' => 'age',
584
        'table' => 'views_test',
585
        'field' => 'age',
586
        'relationship' => 'none',
587
        'exposed' => TRUE,
588
        'expose' => array(
589
          'operator' => 'age_op',
590
          'label' => 'age',
591
          'identifier' => 'age',
592
          'use_operator' => TRUE,
593
        ),
594
      ),
595
    );
596
    $view = $this->getBasicPageView();
597
    $view->set_display('page_1');
598
    $view->display['page_1']->handler->override_option('filters', $filters);
599
    $view->set_exposed_input($exposed_input);
600
    $this->executeView($view);
601
    $this->assertIdenticalResultset($view, $resultset, $this->column_map, 'Identical result set for ' . $operator . ' with untouched values.');
602
    $view->destroy();
603

  
604
    // Min, max and value fields are shown/hidden only via JS, so they might
605
    // still be set from a previous operation. Assert that this doesn't change
606
    // the expected result set.
607
    $exposed_input['age'] += array(
608
      'value' => '25',
609
      'min' => '28',
610
      'max' => '30',
611
    );
612
    $view = $this->getBasicPageView();
613
    $view->set_display('page_1');
614
    $view->display['page_1']->handler->override_option('filters', $filters);
615
    $view->set_exposed_input($exposed_input);
616
    $this->executeView($view);
617
    $this->assertIdenticalResultset($view, $resultset, $this->column_map, 'Identical result set for ' . $operator . ' with leftover values from previous operation.');
618
  }
349 619

  
350 620
  public function testAllowEmpty() {
351 621
    $view = $this->getBasicView();

Formats disponibles : Unified diff