ProcessorPluginManagerTest.php 3.74 KB
Newer Older
1
2
3
<?php

/**
Joris Vercammen's avatar
Joris Vercammen committed
4
5
 * @file
 * Contains \Drupal\Tests\facets\Unit\Processor\ProcessorPluginManagerTest.
6
7
 */

8
namespace Drupal\Tests\facets\Unit\Processor;
9
10
11
12
13
14

use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
Joris Vercammen's avatar
Joris Vercammen committed
15
use Drupal\facets\Processor\ProcessorInterface;
16
use Drupal\facets\Processor\ProcessorPluginManager;
17
18
19
20
use Drupal\Tests\UnitTestCase;
use Zend\Stdlib\ArrayObject;

/**
Joris Vercammen's avatar
Joris Vercammen committed
21
22
 * Unit test for Processor plugin manager.
 *
23
 * @group facets
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
 */
class ProcessorPluginManagerTest extends UnitTestCase {

  /**
   * The cache backend.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $cache;

  /**
   * The plugin discovery.
   *
   * @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $discovery;

  /**
   * The plugin factory.
   *
   * @var \Drupal\Component\Plugin\Factory\DefaultFactory|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $factory;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $moduleHandler;

  /**
   * The translator interface.
   *
   * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $translator;

  /**
   * The plugin manager under test.
   *
65
   * @var \Drupal\facets\Processor\ProcessorPluginManager
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
   */
  public $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $this->discovery = $this->getMock(DiscoveryInterface::class);

    $this->factory = $this->getMockBuilder(DefaultFactory::class)
      ->disableOriginalConstructor()
      ->getMock();

    $this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);

    $this->cache = $this->getMock(CacheBackendInterface::class);

    $this->translator = $this->getMock(TranslationInterface::class);

    $namespaces = new ArrayObject();

    $this->sut = new ProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
    $discovery_property = new \ReflectionProperty($this->sut, 'discovery');
    $discovery_property->setAccessible(TRUE);
    $discovery_property->setValue($this->sut, $this->discovery);
    $factory_property = new \ReflectionProperty($this->sut, 'factory');
    $factory_property->setAccessible(TRUE);
    $factory_property->setValue($this->sut, $this->factory);
  }

  /**
   * Tests plugin manager constructor.
   */
  public function testConstruct() {
    $namespaces = new ArrayObject();
101
102
    $sut = new ProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);
    $this->assertInstanceOf('\Drupal\facets\Processor\ProcessorPluginManager', $sut);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  }

  /**
   * Tests plugin manager's getDefinitions method.
   */
  public function testGetDefinitions() {
    $definitions = array(
      'foo' => array(
        'label' => $this->randomMachineName(),
      ),
    );
    $this->discovery->expects($this->once())
      ->method('getDefinitions')
      ->willReturn($definitions);
    $this->assertSame($definitions, $this->sut->getDefinitions());
  }

Joris Vercammen's avatar
Joris Vercammen committed
120
121
122
123
124
125
126
127
128
129
  /**
   * Tests processing stages.
   */
  public function testGetProcessingStages() {
    $namespaces = new ArrayObject();
    $sut = new ProcessorPluginManager($namespaces, $this->cache, $this->moduleHandler, $this->translator);

    $stages = [
      ProcessorInterface::STAGE_PRE_QUERY,
      ProcessorInterface::STAGE_POST_QUERY,
Joris Vercammen's avatar
Joris Vercammen committed
130
      ProcessorInterface::STAGE_BUILD,
Joris Vercammen's avatar
Joris Vercammen committed
131
132
133
134
135
    ];

    $this->assertEquals($stages, array_keys($sut->getProcessingStages()));
  }

136
}