CountWidgetOrderProcessorTest.php 2.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php

/**
 * @file
 * Contains \Drupal\Tests\facetapi\Plugin\Processor\CountWidgetOrderProcessorTest.
 */

namespace Drupal\Tests\facetapi\Unit\Plugin\Processor;

use Drupal\facetapi\Plugin\facetapi\processor\CountWidgetOrderProcessor;
use Drupal\facetapi\Result\Result;
use Drupal\Tests\UnitTestCase;

/**
 * @group facetapi
 */
class CountWidgetOrderProcessorTest extends UnitTestCase {

  /**
   * The processor to be tested.
   *
22
   * @var \Drupal\facetapi\processor\WidgetOrderProcessorInterface
23 24 25
   */
  protected $processor;

26 27 28 29 30 31 32
  /**
   * An array containing the results before the processor has ran.
   *
   * @var \Drupal\facetapi\Result\Result[]
   */
  protected $original_results;

33 34 35 36 37 38
  /**
   * Creates a new processor object for use in the tests.
   */
  protected function setUp() {
    parent::setUp();

39
    $this->original_results = [
40 41 42
      new Result('llama', 'llama', 10),
      new Result('badger', 'badger', 5),
      new Result('duck', 'duck', 15),
43 44
    ];

45 46 47 48 49 50 51 52
    $this->processor = new CountWidgetOrderProcessor([], 'count_widget_order', []);
  }

  /**
   * Test sorting ascending.
   */
  public function testAscending() {

53
    $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
54 55

    $this->assertEquals(5, $sorted_results[0]->getCount());
56
    $this->assertEquals('badger', $sorted_results[0]->getDisplayValue());
57
    $this->assertEquals(10, $sorted_results[1]->getCount());
58
    $this->assertEquals('llama', $sorted_results[1]->getDisplayValue());
59
    $this->assertEquals(15, $sorted_results[2]->getCount());
60
    $this->assertEquals('duck', $sorted_results[2]->getDisplayValue());
61 62 63 64 65 66 67
  }

  /**
   * Test sorting descending.
   */
  public function testDescending() {

68
    $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
69 70

    $this->assertEquals(15, $sorted_results[0]->getCount());
71
    $this->assertEquals('duck', $sorted_results[0]->getDisplayValue());
72
    $this->assertEquals(10, $sorted_results[1]->getCount());
73
    $this->assertEquals('llama', $sorted_results[1]->getDisplayValue());
74
    $this->assertEquals(5, $sorted_results[2]->getCount());
75
    $this->assertEquals('badger', $sorted_results[2]->getDisplayValue());
76 77 78
  }

}