Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayFilterTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Filter\ArrayFilter;
10 
11 class ArrayFilterTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testFilter()
14  {
15  $arrayFilter = new ArrayFilter();
16 
19  $filterMock = $this->createMock(\Zend_Filter_Interface::class);
20  $filterMock->expects($this->exactly(3))->method('filter')->will(
21  $this->returnCallback(
22  function ($input) {
23  return '(' . $input . ')';
24  }
25  )
26  );
27  $arrayFilter->addFilter($filterMock);
28 
31  $fieldFilterMock = $this->createMock(\Zend_Filter_Interface::class);
32  $fieldFilterMock->expects($this->exactly(1))->method('filter')->will(
33  $this->returnCallback(
34  function ($input) {
35  return '[' . $input . ']';
36  }
37  )
38  );
39  $arrayFilter->addFilter($fieldFilterMock, 'field2');
40 
42  $inputArray = ['field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3'];
43  $expectedOutput = ['field1' => '(value1)', 'field2' => '[(value2)]', 'field3' => '(value3)'];
44  $this->assertEquals($expectedOutput, $arrayFilter->filter($inputArray), 'Array was filtered incorrectly.');
45  }
46 }