|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) |
| 4 | + */ |
| 5 | + |
| 6 | +namespace Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery; |
| 7 | + |
| 8 | +use Mtf\Fixture\FixtureFactory; |
| 9 | +use Mtf\Fixture\FixtureInterface; |
| 10 | +use Mtf\Fixture\InjectableFixture; |
| 11 | + |
| 12 | +/** |
| 13 | + * Data to search for. |
| 14 | + * Possible templates: |
| 15 | + * - {value} |
| 16 | + * - {product}::{product_property_to_search} |
| 17 | + * - {product}::{product_dataSet}::{product_property_to_search} |
| 18 | + */ |
| 19 | +class QueryText implements FixtureInterface |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Entity to search. |
| 23 | + * |
| 24 | + * @var InjectableFixture |
| 25 | + */ |
| 26 | + protected $product; |
| 27 | + |
| 28 | + /** |
| 29 | + * Resource data. |
| 30 | + * |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + protected $data; |
| 34 | + |
| 35 | + /** |
| 36 | + * @constructor |
| 37 | + * @param FixtureFactory $fixtureFactory |
| 38 | + * @param array $params |
| 39 | + * @param array $data |
| 40 | + */ |
| 41 | + public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = []) |
| 42 | + { |
| 43 | + $this->params = $params; |
| 44 | + $explodeValue = explode('::', $data['value']); |
| 45 | + if (!empty($explodeValue) && count($explodeValue) > 1) { |
| 46 | + $fixtureCode = $explodeValue[0]; |
| 47 | + $dataSet = isset($explodeValue[2]) ? $explodeValue[1] : ''; |
| 48 | + $searchValue = isset($explodeValue[2]) ? $explodeValue[2] : $explodeValue[1]; |
| 49 | + $this->product = $fixtureFactory->createByCode($fixtureCode, ['dataSet' => $dataSet]); |
| 50 | + if (!$this->product->hasData('id')) { |
| 51 | + $this->product->persist(); |
| 52 | + } |
| 53 | + if ($this->product->hasData($searchValue)) { |
| 54 | + $getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue))); |
| 55 | + $this->data = $this->product->$getProperty(); |
| 56 | + } else { |
| 57 | + $this->data = $searchValue; |
| 58 | + } |
| 59 | + } else { |
| 60 | + $this->data = strval($data['value']); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Persist custom selections products. |
| 66 | + * |
| 67 | + * @return void |
| 68 | + */ |
| 69 | + public function persist() |
| 70 | + { |
| 71 | + // |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Return prepared data. |
| 76 | + * |
| 77 | + * @param string|null $key |
| 78 | + * @return string |
| 79 | + * |
| 80 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 81 | + */ |
| 82 | + public function getData($key = null) |
| 83 | + { |
| 84 | + return $this->data; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Return data set configuration settings. |
| 89 | + * |
| 90 | + * @return array |
| 91 | + */ |
| 92 | + public function getDataConfig() |
| 93 | + { |
| 94 | + return $this->params; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Get product fixture to search. |
| 99 | + * |
| 100 | + * @return InjectableFixture |
| 101 | + */ |
| 102 | + public function getProduct() |
| 103 | + { |
| 104 | + return $this->product; |
| 105 | + } |
| 106 | +} |
0 commit comments