protected function TermWeightWidgetOrderProcessorTest::setUp in Facets 8
Creates a new processor object for use in the tests.
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ processor/ TermWeightWidgetOrderProcessorTest.php, line 65
Class
- TermWeightWidgetOrderProcessorTest
- Unit test for processor.
Namespace
Drupal\Tests\facets\Unit\Plugin\processorCode
protected function setUp() {
parent::setUp();
// Build up a chain of mocks that we will have the processor use to fetch
// the weight of the terms that are being compared.
$this->termStorage = $this
->getMockBuilder(EntityStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$this->entityTypeManager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->willReturn($this->termStorage);
// Instantiate the processor and load it up with our mock chain.
$this->processor = new TermWeightWidgetOrderProcessor([], 'term_weight_widget_order', [], $this->entityTypeManager);
// Setup two mock terms that will be set up to have specific weights before
// the processor is used to compare them.
// The mocks are used in the individual tests.
$this->termA = $this
->getMockBuilder(Term::class)
->disableOriginalConstructor()
->getMock();
$this->termB = $this
->getMockBuilder(Term::class)
->disableOriginalConstructor()
->getMock();
// Prepare the terms that will be returned when the processor loads its list
// of term-ids from the Results raw values.
$terms = [
1 => $this->termA,
2 => $this->termB,
];
// Setup the termStorage mock to return our terms. As we keep a reference to
// the terms via $this the individual tests can set up the weights later.
$this->termStorage
->expects($this
->any())
->method('loadMultiple')
->willReturn($terms);
// Prepare the results that we use the processor to sort, the raw_value has
// to match the term_id keys used above in $terms. Display_value and count
// is not used.
$facet = new Facet([], 'facets_facet');
$this->originalResults = [
new Result($facet, 1, 10, 100),
new Result($facet, 2, 20, 200),
];
}