synonyms_commerce.test 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the Synonyms Commerce module.
  5. */
  6. /**
  7. * Test synonyms autocomplete widget for commerce product reference field type.
  8. */
  9. class CommerceProductReferenceAutocompleteSynonymsWebTestCase extends AbstractAutocompleteSynonymsWebTestCase {
  10. /**
  11. * GetInfo method.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Commerce product reference synonyms autocomplete',
  16. 'description' => 'Ensure that the "synonym friendly autocomplete" widget works correctly with commerce product reference field type.',
  17. 'group' => 'Synonyms',
  18. );
  19. }
  20. public function setUp($modules = array()) {
  21. $modules[] = 'commerce_product_reference';
  22. $modules[] = 'commerce_product_ui';
  23. $modules[] = 'synonyms_commerce';
  24. $this->fields['enabled']['instance']['entity_type'] = 'commerce_product';
  25. $this->fields['enabled']['instance']['bundle'] = 'product';
  26. $this->fields['disabled']['instance']['entity_type'] = 'commerce_product';
  27. $this->fields['disabled']['instance']['bundle'] = 'product';
  28. $this->behavior_implementation['entity_type'] = $this->fields['enabled']['instance']['entity_type'];
  29. parent::setUp($modules);
  30. $this->reference_field = array(
  31. 'type' => 'commerce_product_reference',
  32. 'field_name' => 'synonyms_commerce',
  33. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  34. 'settings' => array(),
  35. );
  36. $this->reference_field = field_create_field($this->reference_field);
  37. $this->reference_instance = array(
  38. 'field_name' => $this->reference_field['field_name'],
  39. 'entity_type' => $this->entity_type,
  40. 'bundle' => $this->bundle,
  41. 'label' => 'Synonym Commerce Autocomplete',
  42. 'settings' => array(
  43. 'referenceable_types' => drupal_map_assoc(array('product')),
  44. ),
  45. 'widget' => array(
  46. 'type' => 'synonyms_commerce_autocomplete',
  47. ),
  48. );
  49. $this->reference_instance = field_create_instance($this->reference_instance);
  50. $this->reference_instance = field_info_instance($this->reference_instance['entity_type'], $this->reference_instance['field_name'], $this->reference_instance['bundle']);
  51. }
  52. protected function createTerms() {
  53. $name = $this->randomName();
  54. $product = (object) array(
  55. 'type' => 'product',
  56. 'title' => $name,
  57. 'sku' => 'a' . drupal_strtolower($this->randomName()),
  58. $this->fields['disabled']['field']['field_name'] => array(
  59. LANGUAGE_NONE => array(
  60. array('value' => $this->randomName()),
  61. ),
  62. ),
  63. );
  64. commerce_product_save($product);
  65. $this->terms['term1'] = $product;
  66. $name .= $this->randomName();
  67. $product = (object) array(
  68. 'type' => 'product',
  69. 'title' => $name,
  70. 'sku' => 'z' . drupal_strtolower($this->randomName()),
  71. $this->fields['disabled']['field']['field_name'] => array(
  72. LANGUAGE_NONE => array(
  73. array('value' => $this->randomName()),
  74. ),
  75. ),
  76. );
  77. commerce_product_save($product);
  78. $this->terms['term1_longer_name'] = $product;
  79. $product = (object) array(
  80. 'type' => 'product',
  81. 'title' => $this->randomName(),
  82. 'sku' => drupal_strtolower($this->randomName()),
  83. $this->fields['disabled']['field']['field_name'] => array(
  84. LANGUAGE_NONE => array(
  85. array('value' => $this->randomName()),
  86. ),
  87. ),
  88. );
  89. commerce_product_save($product);
  90. $this->terms['no_synonyms'] = $product;
  91. $product = (object) array(
  92. 'type' => 'product',
  93. 'title' => $this->randomName(),
  94. 'sku' => drupal_strtolower($this->randomName()),
  95. $this->fields['enabled']['field']['field_name'] => array(
  96. LANGUAGE_NONE => array(
  97. array('value' => $this->randomName()),
  98. ),
  99. ),
  100. $this->fields['disabled']['field']['field_name'] => array(
  101. LANGUAGE_NONE => array(
  102. array('value' => $this->randomName()),
  103. ),
  104. ),
  105. );
  106. commerce_product_save($product);
  107. $this->terms['one_synonym'] = $product;
  108. $product = (object) array(
  109. 'type' => 'product',
  110. 'title' => $this->randomName(),
  111. 'sku' => drupal_strtolower($this->randomName()),
  112. $this->fields['enabled']['field']['field_name'] => array(
  113. LANGUAGE_NONE => array(
  114. array('value' => $this->randomName()),
  115. array('value' => $this->randomName()),
  116. ),
  117. ),
  118. $this->fields['disabled']['field']['field_name'] => array(
  119. LANGUAGE_NONE => array(
  120. array('value' => $this->randomName()),
  121. ),
  122. ),
  123. );
  124. commerce_product_save($product);
  125. $this->terms['two_synonyms'] = $product;
  126. $name = $this->randomName();
  127. $product = (object) array(
  128. 'type' => 'product',
  129. 'title' => $name,
  130. 'sku' => drupal_strtolower($this->randomName()),
  131. $this->fields['enabled']['field']['field_name'] => array(
  132. LANGUAGE_NONE => array(
  133. array('value' => $name . $this->randomName()),
  134. ),
  135. ),
  136. $this->fields['disabled']['field']['field_name'] => array(
  137. LANGUAGE_NONE => array(
  138. array('value' => $this->randomName()),
  139. ),
  140. ),
  141. );
  142. commerce_product_save($product);
  143. $this->terms['name_similar_synonym'] = $product;
  144. $name = 'similar_synonyms_';
  145. $product = (object) array(
  146. 'type' => 'product',
  147. 'title' => $this->randomName(),
  148. 'sku' => drupal_strtolower($this->randomName()),
  149. $this->fields['enabled']['field']['field_name'] => array(
  150. LANGUAGE_NONE => array(
  151. array('value' => $name . $this->randomName()),
  152. array('value' => $name . $this->randomName()),
  153. ),
  154. ),
  155. $this->fields['disabled']['field']['field_name'] => array(
  156. LANGUAGE_NONE => array(
  157. array('value' => $this->randomName()),
  158. ),
  159. ),
  160. );
  161. commerce_product_save($product);
  162. $this->terms['similar_synonyms'] = $product;
  163. $name = 'one_term_name_another_synonym_';
  164. $product = (object) array(
  165. 'type' => 'product',
  166. 'title' => $name . $this->randomName(),
  167. 'sku' => drupal_strtolower($this->randomName()),
  168. $this->fields['disabled']['field']['field_name'] => array(
  169. LANGUAGE_NONE => array(
  170. array('value' => $this->randomName()),
  171. ),
  172. ),
  173. );
  174. commerce_product_save($product);
  175. $this->terms['name_another_synonym'] = $product;
  176. $product = (object) array(
  177. 'type' => 'product',
  178. 'title' => $this->randomName(),
  179. 'sku' => drupal_strtolower($this->randomName()),
  180. $this->fields['enabled']['field']['field_name'] => array(
  181. LANGUAGE_NONE => array(
  182. array('value' => $name . $this->randomName()),
  183. ),
  184. ),
  185. $this->fields['disabled']['field']['field_name'] => array(
  186. LANGUAGE_NONE => array(
  187. array('value' => $this->randomName()),
  188. ),
  189. ),
  190. );
  191. commerce_product_save($product);
  192. $this->terms['synonym_another_name'] = $product;
  193. $another_product_type = commerce_product_ui_product_type_new();
  194. $another_product_type['type'] = 'another_vocabulary';
  195. $another_product_type['name'] = $this->randomName();
  196. commerce_product_ui_product_type_save($another_product_type);
  197. $product_similar_product = (object) array(
  198. 'type' => $another_product_type['type'],
  199. 'title' => $this->entityLabel($this->terms['no_synonyms']),
  200. 'sku' => drupal_strtolower($this->randomName()),
  201. );
  202. commerce_product_save($product_similar_product);
  203. $product_similar_synonym = (object) array(
  204. 'type' => $another_product_type['type'],
  205. 'title' => $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  206. 'sku' => drupal_strtolower($this->randomName()),
  207. );
  208. commerce_product_save($product_similar_synonym);
  209. $synonym_similar_product = (object) array(
  210. 'type' => $another_product_type['type'],
  211. 'title' => $this->randomName(),
  212. 'sku' => drupal_strtolower($this->randomName()),
  213. $this->fields['enabled']['field']['field_name'] => array(LANGUAGE_NONE => array(
  214. $this->entityLabel($this->terms['no_synonyms']),
  215. )),
  216. );
  217. commerce_product_save($synonym_similar_product);
  218. $synonym_similar_synonym = (object) array(
  219. 'type' => $another_product_type['type'],
  220. 'title' => $this->randomName(),
  221. 'sku' => drupal_strtolower($this->randomName()),
  222. $this->fields['enabled']['field']['field_name'] => array(LANGUAGE_NONE => array(
  223. $this->terms['one_synonym']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  224. )),
  225. );
  226. commerce_product_save($synonym_similar_synonym);
  227. }
  228. }
  229. /**
  230. * Test synonyms-friendly select widget for commerce product reference field.
  231. */
  232. class CommerceProductReferenceSelectSynonymsWebTestCase extends AbstractSelectSynonymsWebTestCase {
  233. /**
  234. * Array of products on which the testing is held.
  235. *
  236. * @var array
  237. */
  238. protected $products = array();
  239. public static function getInfo() {
  240. return array(
  241. 'name' => 'Commerce product reference synonyms select',
  242. 'description' => 'Ensure that the "synonym friendly select" widget works correctly with commerce product reference field.',
  243. 'group' => 'Synonyms',
  244. );
  245. }
  246. public function setUp($modules = array()) {
  247. $modules[] = 'commerce_product_reference';
  248. $modules[] = 'synonyms_commerce';
  249. $this->fields['enabled']['instance']['entity_type'] = 'commerce_product';
  250. $this->fields['enabled']['instance']['bundle'] = 'product';
  251. $this->fields['disabled']['instance']['entity_type'] = 'commerce_product';
  252. $this->fields['disabled']['instance']['bundle'] = 'product';
  253. $this->behavior_implementation['entity_type'] = $this->fields['enabled']['instance']['entity_type'];
  254. parent::setUp($modules);
  255. $this->reference_field = array(
  256. 'type' => 'commerce_product_reference',
  257. 'field_name' => 'synonyms_commerce',
  258. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  259. 'settings' => array(),
  260. );
  261. $this->reference_field = field_create_field($this->reference_field);
  262. $this->reference_instance = array(
  263. 'field_name' => $this->reference_field['field_name'],
  264. 'entity_type' => $this->entity_type,
  265. 'bundle' => $this->bundle,
  266. 'label' => 'Synonym Commerce Select',
  267. 'widget' => array(
  268. 'type' => 'synonyms_commerce_select',
  269. ),
  270. );
  271. $this->reference_instance = field_create_instance($this->reference_instance);
  272. }
  273. public function testWidgetSorting() {
  274. $cardinality = array(
  275. 1 => 1,
  276. FIELD_CARDINALITY_UNLIMITED => 'unlimited',
  277. );
  278. $required = array(
  279. TRUE => 'required',
  280. FALSE => 'not required',
  281. );
  282. foreach ($cardinality as $cardinality_k => $cardinality_v) {
  283. foreach ($required as $required_k => $required_v) {
  284. $this->reference_field['cardinality'] = $cardinality_k;
  285. field_update_field($this->reference_field);
  286. $this->reference_instance['required'] = $required_k;
  287. field_update_instance($this->reference_instance);
  288. $options = array();
  289. $options[] = array(
  290. 'entity' => $this->terms['product3'],
  291. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  292. );
  293. $options[] = array(
  294. 'entity' => $this->terms['product3'],
  295. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  296. );
  297. $options[] = array(
  298. 'entity' => $this->terms['product1'],
  299. );
  300. $options[] = array(
  301. 'entity' => $this->terms['product1'],
  302. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  303. );
  304. $options[] = array(
  305. 'entity' => $this->terms['product1'],
  306. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  307. );
  308. $options[] = array(
  309. 'entity' => $this->terms['product2'],
  310. );
  311. $options[] = array(
  312. 'entity' => $this->terms['product2'],
  313. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  314. );
  315. $options[] = array(
  316. 'entity' => $this->terms['product2'],
  317. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  318. );
  319. $options[] = array(
  320. 'entity' => $this->terms['product3'],
  321. );
  322. $this->drupalGet('node/add/synonyms-test-content');
  323. $this->assertSynonymsSelect($options, 'Synonyms select sorting by name works for the cardinality of ' . $cardinality_v . ' and ' . $required_v);
  324. }
  325. }
  326. }
  327. public function testWidget() {
  328. $name = $this->randomName();
  329. $this->drupalPost('node/add/synonyms-test-content', array(
  330. 'title' => $name,
  331. $this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
  332. $this->synonymSelectKey($this->terms['product1'], $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  333. $this->terms['product2']->product_id,
  334. $this->terms['product3']->product_id,
  335. $this->synonymSelectKey($this->terms['product3'], $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  336. ),
  337. ), 'Save');
  338. $node = $this->drupalGetNodeByTitle($name);
  339. $this->drupalGet('node/' . $node->nid);
  340. $this->assertText($this->terms['product1']->title, 'Product is saved when its synonym is submitted through synonyms friendly select for the unlimited cardinality.');
  341. $this->assertText($this->terms['product2']->title, 'Product is saved when it is submitted through synonyms friendly select for the unlimited cardinality.');
  342. $this->assertText($this->terms['product3']->title, 'Product is saved only once when the term and its synonym are submitted through synonyms friendly select for the unlimited cardinality.');
  343. $options = array();
  344. $options[] = array(
  345. 'entity' => $this->terms['product3'],
  346. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  347. );
  348. $options[] = array(
  349. 'entity' => $this->terms['product3'],
  350. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  351. );
  352. $options[] = array(
  353. 'entity' => $this->terms['product1'],
  354. 'selected' => TRUE,
  355. );
  356. $options[] = array(
  357. 'entity' => $this->terms['product1'],
  358. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  359. );
  360. $options[] = array(
  361. 'entity' => $this->terms['product1'],
  362. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  363. );
  364. $options[] = array(
  365. 'entity' => $this->terms['product2'],
  366. 'selected' => TRUE,
  367. );
  368. $options[] = array(
  369. 'entity' => $this->terms['product2'],
  370. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  371. );
  372. $options[] = array(
  373. 'entity' => $this->terms['product2'],
  374. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  375. );
  376. $options[] = array(
  377. 'entity' => $this->terms['product3'],
  378. 'selected' => TRUE,
  379. );
  380. $this->drupalGet('node/' . $node->nid . '/edit');
  381. $this->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with field cardinality more than 1.');
  382. $this->reference_field['cardinality'] = 2;
  383. field_update_field($this->reference_field);
  384. $name = $this->randomName();
  385. $this->drupalPost('node/add/synonyms-test-content', array(
  386. 'title' => $name,
  387. $this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
  388. $this->synonymSelectKey($this->terms['product1'], $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  389. $this->terms['product2']->product_id,
  390. $this->terms['product3']->product_id,
  391. ),
  392. ), 'Save');
  393. $this->assertText('this field cannot hold more than 2 values.', 'Submitting 3 entries into a field with cardinality of 2, that refer to 3 products, results in a form error.');
  394. $this->drupalPost('node/add/synonyms-test-content', array(
  395. 'title' => $name,
  396. $this->reference_field['field_name'] . '[' . LANGUAGE_NONE . '][]' => array(
  397. $this->synonymSelectKey($this->terms['product1'], $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  398. $this->terms['product2']->product_id,
  399. $this->synonymSelectKey($this->terms['product2'], $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  400. ),
  401. ), 'Save');
  402. $node = $this->drupalGetNodeByTitle($name);
  403. $this->drupalGet('node/' . $node->nid);
  404. $this->assertText($this->terms['product1']->title, 'Submitting 3 entries into a field with cardinality of 2, that refer to only 2 products, results in form getting submitted. Product #1 is saved.');
  405. $this->assertText($this->terms['product2']->title, 'Product #2 is saved.');
  406. $this->reference_field['cardinality'] = 1;
  407. field_update_field($this->reference_field);
  408. // We need to invoke this one. Without it some caching within Entity
  409. // metadata wrappers interferes. See https://www.drupal.org/node/2717019 for
  410. // details.
  411. entity_flush_caches();
  412. $name = $this->randomName();
  413. $this->drupalPost('node/add/synonyms-test-content', array(
  414. 'title' => $name,
  415. $this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => $this->synonymSelectKey($this->terms['product1'], $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value']),
  416. ), 'Save');
  417. $node = $this->drupalGetNodeByTitle($name);
  418. $this->drupalGet('node/' . $node->nid);
  419. $this->assertText($this->terms['product1']->title, 'Product is saved when its synonym is submitted through synonyms friendly select for the cardinality of 1.');
  420. $options = array();
  421. $options[] = array(
  422. 'entity' => $this->terms['product3'],
  423. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  424. );
  425. $options[] = array(
  426. 'entity' => $this->terms['product3'],
  427. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  428. );
  429. $options[] = array(
  430. 'entity' => $this->terms['product1'],
  431. 'selected' => TRUE,
  432. );
  433. $options[] = array(
  434. 'entity' => $this->terms['product1'],
  435. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  436. );
  437. $options[] = array(
  438. 'entity' => $this->terms['product1'],
  439. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  440. );
  441. $options[] = array(
  442. 'entity' => $this->terms['product2'],
  443. );
  444. $options[] = array(
  445. 'entity' => $this->terms['product2'],
  446. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  447. );
  448. $options[] = array(
  449. 'entity' => $this->terms['product2'],
  450. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  451. );
  452. $options[] = array(
  453. 'entity' => $this->terms['product3'],
  454. );
  455. $this->drupalGet('node/' . $node->nid . '/edit');
  456. $this->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with the field cardinality of 1.');
  457. $this->drupalPost('node/' . $node->nid . '/edit', array(
  458. $this->reference_field['field_name'] . '[' . LANGUAGE_NONE . ']' => $this->terms['product2']->product_id,
  459. ), 'Save');
  460. $this->drupalGet('node/' . $node->nid);
  461. $this->assertNoText($this->terms['product1']->title, 'After updating entity the old product is removed.');
  462. $this->assertText($this->terms['product2']->title, 'Product is saved when it is submitted through synonyms friendly select for the cardinality of 1.');
  463. $options = array();
  464. $options[] = array(
  465. 'entity' => $this->terms['product3'],
  466. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  467. );
  468. $options[] = array(
  469. 'entity' => $this->terms['product3'],
  470. 'synonym' => $this->terms['product3']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  471. );
  472. $options[] = array(
  473. 'entity' => $this->terms['product1'],
  474. );
  475. $options[] = array(
  476. 'entity' => $this->terms['product1'],
  477. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  478. );
  479. $options[] = array(
  480. 'entity' => $this->terms['product1'],
  481. 'synonym' => $this->terms['product1']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  482. );
  483. $options[] = array(
  484. 'entity' => $this->terms['product2'],
  485. 'selected' => TRUE,
  486. );
  487. $options[] = array(
  488. 'entity' => $this->terms['product2'],
  489. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][1]['value'],
  490. );
  491. $options[] = array(
  492. 'entity' => $this->terms['product2'],
  493. 'synonym' => $this->terms['product2']->{$this->fields['enabled']['field']['field_name']}[LANGUAGE_NONE][0]['value'],
  494. );
  495. $options[] = array(
  496. 'entity' => $this->terms['product3'],
  497. );
  498. $this->drupalGet('node/' . $node->nid . '/edit');
  499. $this->assertSynonymsSelect($options, 'Default values are set correctly in the synonyms friendly select widget when working with the field cardinality of 1.');
  500. }
  501. protected function createTerms() {
  502. $this->terms['product1'] = (object) array(
  503. 'type' => $this->behavior_implementation['bundle'],
  504. 'title' => 'Product 1',
  505. 'sku' => drupal_strtolower($this->randomName()),
  506. $this->fields['enabled']['field']['field_name'] => array(
  507. LANGUAGE_NONE => array(
  508. array('value' => 'Product 1A' . $this->randomName()),
  509. array('value' => 'Product 1Z' . $this->randomName()),
  510. ),
  511. ),
  512. );
  513. commerce_product_save($this->terms['product1']);
  514. $this->terms['product2'] = (object) array(
  515. 'type' => $this->behavior_implementation['bundle'],
  516. 'title' => 'Product 2',
  517. 'sku' => drupal_strtolower($this->randomName()),
  518. $this->fields['enabled']['field']['field_name'] => array(
  519. LANGUAGE_NONE => array(
  520. array('value' => 'Product 2Z' . $this->randomName()),
  521. array('value' => 'Product 2A' . $this->randomName()),
  522. ),
  523. ),
  524. );
  525. commerce_product_save($this->terms['product2']);
  526. $this->terms['product3'] = (object) array(
  527. 'type' => $this->behavior_implementation['bundle'],
  528. 'title' => 'Product 3',
  529. 'sku' => drupal_strtolower($this->randomName()),
  530. $this->fields['enabled']['field']['field_name'] => array(
  531. LANGUAGE_NONE => array(
  532. array('value' => 'Another Product 3A' . $this->randomName()),
  533. array('value' => 'Another Product 3Z' . $this->randomName()),
  534. ),
  535. ),
  536. );
  537. commerce_product_save($this->terms['product3']);
  538. }
  539. }
  540. /**
  541. * Test CommerceProductReferenceSynonymsBehavior class.
  542. */
  543. class CommerceProductReferenceSynonymsBehaviorWebTestCase extends AbstractSynonymsProviderFieldWebTestCase {
  544. /**
  545. * GetInfo method.
  546. */
  547. public static function getInfo() {
  548. return array(
  549. 'name' => 'CommerceProductReferenceSynonymsBehavior',
  550. 'description' => 'Ensure that the synonyms module extracts synonyms from commerce product reference fields correctly.',
  551. 'group' => 'Synonyms',
  552. );
  553. }
  554. /**
  555. * SetUp method.
  556. */
  557. public function setUp($modules = array()) {
  558. $modules[] = 'commerce_product_reference';
  559. $modules[] = 'commerce_product_ui';
  560. $modules[] = 'synonyms_commerce';
  561. $this->fields['enabled']['field'] = array(
  562. 'field_name' => 'reference',
  563. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  564. 'type' => 'commerce_product_reference',
  565. );
  566. parent::setUp($modules);
  567. }
  568. /**
  569. * Test synonyms extraction for 'commerce_product_reference' field type.
  570. */
  571. public function testCommerceProductReference() {
  572. // Testing synonymsExtract().
  573. $this->assertSynonymsExtract(array(), array(), 'on empty field.');
  574. $synonym_entity = $this->createProduct();
  575. $this->assertSynonymsExtract(array(
  576. LANGUAGE_NONE => array(
  577. 0 => array(
  578. 'product_id' => entity_id('commerce_product', $synonym_entity),
  579. ),
  580. ),
  581. ), array(entity_label('commerce_product', $synonym_entity)), 'on a field that holds one value.');
  582. // Testing mergeEntityAsSynonym() method.
  583. $product = $this->createProduct();
  584. $this->assertMergeEntityAsSynonym(array(), $product, 'commerce_product', array(array('product_id' => $product->product_id)), 'on a product.');
  585. // Testing synonymFind() method.
  586. $this->assertSynonymsFind(array(), db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on empty field');
  587. $meta_data = array();
  588. $meta_data[] = array(
  589. 'items' => array(),
  590. 'found_synonyms' => array(),
  591. );
  592. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field without values');
  593. $meta_data = array();
  594. $meta_data[] = array(
  595. 'items' => array(
  596. LANGUAGE_NONE => array(
  597. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  598. ),
  599. ),
  600. 'found_synonyms' => array(),
  601. );
  602. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field with a value but searching for another string');
  603. $meta_data = array();
  604. $synonym_entity = $this->createProduct();
  605. $meta_data[] = array(
  606. 'items' => array(
  607. LANGUAGE_NONE => array(
  608. array('product_id' => entity_id('commerce_product', $synonym_entity)),
  609. ),
  610. ),
  611. 'found_synonyms' => array(entity_label('commerce_product', $synonym_entity)),
  612. );
  613. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity)), 'on a field with a single value searching for that string');
  614. $meta_data = array();
  615. $synonym_entity = $this->createProduct();
  616. $meta_data[] = array(
  617. 'items' => array(
  618. LANGUAGE_NONE => array(
  619. array('product_id' => entity_id('commerce_product', $synonym_entity)),
  620. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  621. ),
  622. ),
  623. 'found_synonyms' => array(entity_label('commerce_product', $synonym_entity)),
  624. );
  625. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity)), 'on a field with 2 values searching for one of those 2 values');
  626. $meta_data = array();
  627. $synonym_entity = $this->createProduct();
  628. $meta_data[] = array(
  629. 'items' => array(
  630. LANGUAGE_NONE => array(
  631. array('product_id' => entity_id('commerce_product', $synonym_entity)),
  632. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  633. ),
  634. ),
  635. 'found_synonyms' => array(entity_label('commerce_product', $synonym_entity)),
  636. );
  637. $meta_data[] = array(
  638. 'items' => array(
  639. LANGUAGE_NONE => array(
  640. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  641. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  642. ),
  643. ),
  644. 'found_synonyms' => array(),
  645. );
  646. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity)), 'on 2 fields with 2 values each searching for one of those values');
  647. $meta_data = array();
  648. $synonym_entity = $this->createProduct();
  649. $meta_data[] = array(
  650. 'items' => array(
  651. LANGUAGE_NONE => array(
  652. array('product_id' => entity_id('commerce_product', $synonym_entity)),
  653. ),
  654. ),
  655. 'found_synonyms' => array(entity_label('commerce_product', $synonym_entity)),
  656. );
  657. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('commerce_product', $synonym_entity), 1, -1)) . '%', 'LIKE'), 'on a field with a value searching for a string LIKE the %value%');
  658. $meta_data = array();
  659. $tag = $this->randomName();
  660. $synonym_entity1 = $this->createProduct($tag . $this->randomName());
  661. $synonym_entity2 = $this->createProduct($tag . $this->randomName());
  662. $meta_data[] = array(
  663. 'items' => array(
  664. LANGUAGE_NONE => array(
  665. array('product_id' => entity_id('commerce_product', $synonym_entity1)),
  666. array('product_id' => entity_id('commerce_product', $synonym_entity2)),
  667. ),
  668. ),
  669. 'found_synonyms' => array(
  670. entity_label('commerce_product', $synonym_entity1),
  671. entity_label('commerce_product', $synonym_entity2),
  672. ),
  673. );
  674. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, db_like($tag) . '%', 'LIKE'), 'on a field with 2 similar values searching a string like %both values%');
  675. $meta_data = array();
  676. $synonym_entity1 = $this->createProduct();
  677. $synonym_entity2 = $this->createProduct();
  678. $meta_data[] = array(
  679. 'items' => array(
  680. LANGUAGE_NONE => array(
  681. array('product_id' => entity_id('commerce_product', $synonym_entity1)),
  682. array('product_id' => entity_id('commerce_product', $synonym_entity2)),
  683. ),
  684. ),
  685. 'found_synonyms' => array(
  686. entity_label('commerce_product', $synonym_entity1),
  687. entity_label('commerce_product', $synonym_entity2),
  688. ),
  689. );
  690. $condition = db_or()
  691. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity1))
  692. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity2));
  693. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 or value2');
  694. $meta_data = array();
  695. $synonym_entity = $this->createProduct();
  696. $meta_data[] = array(
  697. 'items' => array(
  698. LANGUAGE_NONE => array(
  699. array('product_id' => entity_id('commerce_product', $synonym_entity)),
  700. array('product_id' => entity_id('commerce_product', $this->createProduct())),
  701. ),
  702. ),
  703. 'found_synonyms' => array(entity_label('commerce_product', $synonym_entity)),
  704. );
  705. $condition = db_and()
  706. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity))
  707. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('commerce_product', $synonym_entity), 1, -1)) . '%', 'LIKE');
  708. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 and LIKE value1%');
  709. $meta_data = array();
  710. $synonym_entity1 = $this->createProduct();
  711. $synonym_entity2 = $this->createProduct();
  712. $meta_data[] = array(
  713. 'items' => array(
  714. LANGUAGE_NONE => array(
  715. array('product_id' => entity_id('commerce_product', $synonym_entity1)),
  716. array('product_id' => entity_id('commerce_product', $synonym_entity2)),
  717. ),
  718. ),
  719. 'found_synonyms' => array(
  720. entity_label('commerce_product', $synonym_entity1),
  721. entity_label('commerce_product', $synonym_entity2),
  722. ),
  723. );
  724. $condition = db_or()
  725. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity1))
  726. ->condition(db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, entity_label('commerce_product', $synonym_entity2))->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(drupal_substr(entity_label('commerce_product', $synonym_entity2), 1, -1)) . '%', 'LIKE'));
  727. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for (value1 or (value2 AND value2%))');
  728. $meta_data = array();
  729. $synonym_entity1 = $this->createProduct($this->randomName() . ' ' . $this->randomName() . ' ' . $this->randomName());
  730. $synonym_entity2 = $this->createProduct(str_replace(' ', '-', entity_label('commerce_product', $synonym_entity1)));
  731. $meta_data[] = array(
  732. 'items' => array(
  733. LANGUAGE_NONE => array(
  734. array('product_id' => entity_id('commerce_product', $synonym_entity1)),
  735. array('product_id' => entity_id('commerce_product', $synonym_entity2)),
  736. ),
  737. ),
  738. 'found_synonyms' => array(
  739. entity_label('commerce_product', $synonym_entity1),
  740. entity_label('commerce_product', $synonym_entity2),
  741. ),
  742. );
  743. $condition = db_and()
  744. ->where("REPLACE(" . AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER . ", ' ', '-') = :synonym", array(
  745. ':synonym' => entity_label('commerce_product', $synonym_entity2),
  746. ));
  747. $this->assertSynonymsFind($meta_data, $condition, "on a field with 2 values, where 2nd value replaces spaces with dashes in the 1st value, searching for REPLACE(column, ' ', '-') = value2");
  748. }
  749. /**
  750. * Supportive function.
  751. *
  752. * Create an entity of necessary entity type (in our test it's commerce
  753. * product).
  754. *
  755. * @param string $label
  756. * Label to use for the entity that is about to be created
  757. * @param string $bundle
  758. * Bundle to use for the entity that is about to be created
  759. *
  760. * @return object
  761. * Fully loaded entity object of the just created entity
  762. */
  763. protected function createProduct($label = NULL, $bundle = 'product') {
  764. if (is_null($label)) {
  765. $label = $this->randomName();
  766. }
  767. $entity = commerce_product_new($bundle);
  768. $entity->title = $label;
  769. $entity->sku = drupal_html_id($label);
  770. commerce_product_save($entity);
  771. return $entity;
  772. }
  773. }
  774. /**
  775. * Test CommercePriceSynonymsBehavior class.
  776. */
  777. class CommercePriceSynonymsBehaviorWebTestCase extends AbstractSynonymsProviderFieldWebTestCase {
  778. /**
  779. * GetInfo method.
  780. */
  781. public static function getInfo() {
  782. return array(
  783. 'name' => 'CommercePriceSynonymsBehavior',
  784. 'description' => 'Ensure that the synonyms module extracts synonyms from commerce price fields correctly.',
  785. 'group' => 'Synonyms',
  786. );
  787. }
  788. /**
  789. * SetUp method.
  790. */
  791. public function setUp($modules = array()) {
  792. $modules[] = 'commerce_price';
  793. $modules[] = 'commerce_product_reference';
  794. $modules[] = 'commerce_product_ui';
  795. $modules[] = 'synonyms_commerce';
  796. $this->fields['enabled']['field'] = array(
  797. 'field_name' => 'synonyms_commerce_price',
  798. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  799. 'type' => 'commerce_price',
  800. );
  801. parent::setUp($modules);
  802. }
  803. /**
  804. * Test synonyms extraction for 'commerce_price' field type.
  805. */
  806. public function testCommercePrice() {
  807. // Testing synonymsExtract().
  808. $this->assertSynonymsExtract(array(), array(), 'on empty field.');
  809. $this->assertSynonymsExtract(array(
  810. LANGUAGE_NONE => array(
  811. 0 => array(
  812. 'amount' => 1000,
  813. 'currency_code' => 'USD',
  814. ),
  815. ),
  816. ), array(commerce_currency_format(1000, 'USD')), 'on a field that holds one value.');
  817. // Testing synonymFind() method.
  818. $this->assertSynonymsFind(array(), db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on empty field');
  819. $meta_data = array();
  820. $meta_data[] = array(
  821. 'items' => array(),
  822. 'found_synonyms' => array(),
  823. );
  824. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field without values');
  825. $meta_data = array();
  826. $meta_data[] = array(
  827. 'items' => array(
  828. LANGUAGE_NONE => array(
  829. array(
  830. 'amount' => 1000,
  831. 'currency_code' => 'USD',
  832. ),
  833. ),
  834. ),
  835. 'found_synonyms' => array(),
  836. );
  837. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field with a value but searching for another string');
  838. $meta_data = array();
  839. $meta_data[] = array(
  840. 'items' => array(
  841. LANGUAGE_NONE => array(
  842. array(
  843. 'amount' => 1000,
  844. 'currency_code' => 'USD',
  845. ),
  846. ),
  847. ),
  848. 'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
  849. );
  850. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on a field with a single value searching for that string');
  851. $meta_data = array();
  852. $meta_data[] = array(
  853. 'items' => array(
  854. LANGUAGE_NONE => array(
  855. array(
  856. 'amount' => 1000,
  857. 'currency_code' => 'USD',
  858. ),
  859. array(
  860. 'amount' => 2000,
  861. 'currency_code' => 'USD',
  862. ),
  863. ),
  864. ),
  865. 'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
  866. );
  867. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on a field with 2 values searching for one of those 2 values');
  868. $meta_data = array();
  869. $meta_data[] = array(
  870. 'items' => array(
  871. LANGUAGE_NONE => array(
  872. array(
  873. 'amount' => 1000,
  874. 'currency_code' => 'USD',
  875. ),
  876. array(
  877. 'amount' => 2000,
  878. 'currency_code' => 'USD',
  879. ),
  880. ),
  881. ),
  882. 'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
  883. );
  884. $meta_data[] = array(
  885. 'items' => array(
  886. LANGUAGE_NONE => array(
  887. array(
  888. 'amount' => 100,
  889. 'currency_code' => 'USD',
  890. ),
  891. array(
  892. 'amount' => 200,
  893. 'currency_code' => 'USD',
  894. ),
  895. ),
  896. ),
  897. 'found_synonyms' => array(),
  898. );
  899. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on 2 fields with 2 values each searching for one of those values');
  900. $meta_data = array();
  901. $meta_data[] = array(
  902. 'items' => array(
  903. LANGUAGE_NONE => array(
  904. array(
  905. 'amount' => 1000,
  906. 'currency_code' => 'USD',
  907. ),
  908. ),
  909. ),
  910. 'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
  911. );
  912. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(10) . '%', 'LIKE'), 'on a field with a value searching for a string LIKE the %value%');
  913. $meta_data = array();
  914. $meta_data[] = array(
  915. 'items' => array(
  916. LANGUAGE_NONE => array(
  917. array(
  918. 'amount' => 1000,
  919. 'currency_code' => 'USD',
  920. ),
  921. array(
  922. 'amount' => 100,
  923. 'currency_code' => 'USD',
  924. ),
  925. ),
  926. ),
  927. 'found_synonyms' => array(
  928. commerce_currency_format(1000, 'USD'),
  929. commerce_currency_format(100, 'USD'),
  930. ),
  931. );
  932. $this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, db_like(100) . '%', 'LIKE'), 'on a field with 2 similar values searching a string like %both values%');
  933. $meta_data = array();
  934. $meta_data[] = array(
  935. 'items' => array(
  936. LANGUAGE_NONE => array(
  937. array(
  938. 'amount' => 1000,
  939. 'currency_code' => 'USD',
  940. ),
  941. array(
  942. 'amount' => 2000,
  943. 'currency_code' => 'USD',
  944. ),
  945. ),
  946. ),
  947. 'found_synonyms' => array(
  948. commerce_currency_format(1000, 'USD'),
  949. commerce_currency_format(2000, 'USD'),
  950. ),
  951. );
  952. $condition = db_or()
  953. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
  954. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 2000);
  955. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 or value2');
  956. $meta_data = array();
  957. $meta_data[] = array(
  958. 'items' => array(
  959. LANGUAGE_NONE => array(
  960. array(
  961. 'amount' => 1000,
  962. 'currency_code' => 'USD',
  963. ),
  964. array(
  965. 'amount' => 2000,
  966. 'currency_code' => 'USD',
  967. ),
  968. ),
  969. ),
  970. 'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
  971. );
  972. $condition = db_and()
  973. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
  974. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(10) . '%', 'LIKE');
  975. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 and LIKE value1%');
  976. $meta_data = array();
  977. $meta_data[] = array(
  978. 'items' => array(
  979. LANGUAGE_NONE => array(
  980. array(
  981. 'amount' => 1000,
  982. 'currency_code' => 'USD',
  983. ),
  984. array(
  985. 'amount' => 2000,
  986. 'currency_code' => 'USD',
  987. ),
  988. ),
  989. ),
  990. 'found_synonyms' => array(
  991. commerce_currency_format(1000, 'USD'),
  992. commerce_currency_format(2000, 'USD'),
  993. ),
  994. );
  995. $condition = db_or()
  996. ->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
  997. ->condition(db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 2000)->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(20) . '%', 'LIKE'));
  998. $this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for (value1 or (value2 AND value2%))');
  999. }
  1000. }