Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractHelperTest.php
Go to the documentation of this file.
1 <?php
9 
10 class AbstractHelperTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
20  protected $_resourceMock;
21 
25  protected $_adapterMock;
26 
27  protected function setUp()
28  {
29  $this->_adapterMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
30 
31  $this->_resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
32  $this->_resourceMock->expects($this->any())
33  ->method('getConnection')
34  ->with('prefix')
35  ->will($this->returnValue($this->_adapterMock));
36 
37  $this->_model = $this->getMockForAbstractClass(
38  \Magento\Framework\DB\Helper\AbstractHelper::class,
39  [$this->_resourceMock, 'prefix'],
40  '',
41  true,
42  true,
43  true,
44  ['addLikeEscape']
45  );
46  }
47 
53  public function testEscapeLikeValue($expected, array $data)
54  {
55  $this->assertEquals($expected, $this->_model->escapeLikeValue($data['value'], $data['options']));
56  }
57 
58  public function testGetCILike()
59  {
60  $field = 'field';
61  $value = 'value';
62  $options = [];
63 
64  $this->_adapterMock->expects($this->once())
65  ->method('quoteIdentifier')
66  ->with($field)
67  ->will($this->returnArgument(0));
68 
69  $this->_model->expects($this->once())
70  ->method('addLikeEscape')
71  ->with($value, $options)
72  ->will($this->returnArgument(0));
73 
74  $result = $this->_model->getCILike($field, $value, $options);
75  $this->assertInstanceOf('Zend_Db_Expr', $result);
76  $this->assertEquals($field . ' LIKE ' . $value, (string)$result);
77  }
78 
82  public function escapeLikeValueDataProvider()
83  {
84  return [
85  [
86  '',
87  [
88  'value' => '',
89  'options' => []
90  ],
91  ],
92  [
93  'LIKE \%string\_end',
94  [
95  'value' => 'LIKE %string_end',
96  'options' => []
97  ]
98  ],
99  [
100  'LIKE \%string_end',
101  [
102  'value' => 'LIKE %string_end',
103  'options' => [
104  'allow_symbol_mask' => true,
105  ]
106  ]
107  ],
108  [
109  'LIKE %string\_end',
110  [
111  'value' => 'LIKE %string_end',
112  'options' => [
113  'allow_string_mask' => true,
114  ]
115  ]
116  ],
117  [
118  'LIKE %string_end',
119  [
120  'value' => 'LIKE %string_end',
121  'options' => [
122  'allow_symbol_mask' => true,
123  'allow_string_mask' => true,
124  ]
125  ]
126  ],
127  [
128  '%string%',
129  [
130  'value' => 'string',
131  'options' => [
132  'position' => 'any',
133  ]
134  ]
135  ],
136  [
137  'string%',
138  [
139  'value' => 'string',
140  'options' => [
141  'position' => 'start',
142  ]
143  ]
144  ],
145  [
146  '%string',
147  [
148  'value' => 'string',
149  'options' => [
150  'position' => 'end',
151  ]
152  ]
153  ]
154  ];
155  }
156 }
$value
Definition: gender.phtml:16