/**
  * @param array $data
  * @param array $expected
  * @dataProvider buildDataProvider
  */
 public function testBuild($attributeInputType, $validateRules, $data, $expected)
 {
     $this->attributeMock->expects($this->once())->method('getFrontendInput')->willReturn($attributeInputType);
     $this->attributeMock->expects($this->any())->method('getValidateRules')->willReturn($validateRules);
     $validationRules = $this->subject->build($this->attributeMock, $data);
     $this->assertEquals($expected, $validationRules);
 }
Пример #2
0
 public function testBeforeSave()
 {
     $this->attributeMock->expects($this->any())->method('getName')->willReturn('attribute_name');
     $object = new DataObject(['use_config_attribute_name' => true]);
     $this->model->beforeSave($object);
     $this->assertEquals(BooleanSource::VALUE_USE_CONFIG, $object->getData('attribute_name'));
 }
Пример #3
0
 public function testAddValueSortToCollectionNotGlobal()
 {
     $this->attributeModel->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false));
     $this->collection->expects($this->once())->method('order')->with('check_sql asc')->will($this->returnSelf());
     $this->collection->expects($this->once())->method('getStoreId')->will($this->returnValue(1));
     $this->collection->expects($this->any())->method('getConnection')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('getCheckSql')->will($this->returnValue('check_sql'));
     $this->status->setAttribute($this->attributeModel);
     $this->status->addValueSortToCollection($this->collection);
 }
 /**
  * @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
  */
 public function testLock()
 {
     $lockedFields = ['is_searchable' => 'is_searchable', 'is_filterable' => 'is_filterable'];
     $this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
     $this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
     $elementMock = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->setMethods(['setDisabled', 'setReadonly'])->disableOriginalConstructor()->getMockForAbstractClass();
     $elementMock->expects($this->exactly(2))->method('setDisabled');
     $elementMock->expects($this->exactly(2))->method('setReadonly');
     $this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
     $this->object->lock($this->formMock);
 }
Пример #5
0
 /**
  * @param string $value to assign to boolean
  * @param bool $expected text output
  * @param string $countryId
  * @param bool $isOptional
  *
  * @dataProvider validateValueDataProvider
  */
 public function testValidateValue($value, $expected, $countryId, $isOptional)
 {
     $storeLabel = 'Zip/Postal Code';
     $this->attributeMock->expects($this->once())->method('getStoreLabel')->willReturn($storeLabel);
     $this->directoryHelperMock->expects($this->once())->method('isZipCodeOptional')->willReturnMap([[$countryId, $isOptional]]);
     $object = new \Magento\Customer\Model\Attribute\Data\Postcode($this->localeMock, $this->loggerMock, $this->localeResolverMock, $this->directoryHelperMock);
     $object->setAttribute($this->attributeMock);
     $object->setExtractedData(['country_id' => $countryId]);
     $actual = $object->validateValue($value);
     $this->assertEquals($expected, $actual);
 }
Пример #6
0
 /**
  * @param bool|string $objData
  * @dataProvider beforeSaveProvider
  */
 public function testBeforeSave($objData)
 {
     $attributeName = 'attr';
     $this->attribute->expects($this->once())->method('getName')->will($this->returnValue($attributeName));
     /** @var \Magento\Catalog\Model\Product\Url|\PHPUnit_Framework_MockObject_MockObject $object */
     $object = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Url')->setMethods(['getName', 'getData', 'setData', 'formatUrlKey'])->disableOriginalConstructor()->getMock();
     $object->expects($this->once())->method('getData')->with($this->equalTo($attributeName))->will($this->returnValue($objData));
     $object->expects($this->any())->method('getName')->will($this->returnValue('testData'));
     $object->expects($this->any())->method('setData')->with($this->equalTo($attributeName), $this->logicalOr($this->equalTo('testData'), $this->equalTo('someData')));
     $object->expects($this->any())->method('formatUrlKey')->with($this->logicalOr($this->equalTo('testData'), $this->equalTo('someData')))->will($this->returnCallback(function ($data) {
         return $data;
     }));
     $this->model->beforeSave($object);
 }
Пример #7
0
 public function testGetFlatColumns()
 {
     $code = 'attribute-code';
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($code));
     $columns = $this->model->getFlatColumns();
     $this->assertInternalType('array', $columns);
     $this->assertArrayHasKey($code, $columns);
     foreach ($columns as $column) {
         $this->assertArrayHasKey('unsigned', $column);
         $this->assertArrayHasKey('default', $column);
         $this->assertArrayHasKey('extra', $column);
         $this->assertArrayHasKey('type', $column);
         $this->assertArrayHasKey('nullable', $column);
         $this->assertArrayHasKey('comment', $column);
     }
 }
Пример #8
0
 /**
  * @param $attributeCode
  * @param $data
  * @dataProvider validateDefaultSortException
  * @expectedException \Magento\Framework\Exception\LocalizedException
  */
 public function testValidateDefaultSortException($attributeCode, $data)
 {
     $this->_attribute->expects($this->any())->method('getName')->will($this->returnValue($attributeCode));
     $this->_scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('another value'));
     $object = new \Magento\Framework\DataObject($data);
     $this->_model->validate($object);
 }
Пример #9
0
 /**
  * Set up test
  *
  * @return void
  */
 protected function setUp()
 {
     $this->resource = $this->getMock('Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
     $this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\Resource\\Rule\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
     $this->backend = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->db = $this->getMock('Zend_Db_Statement_Interface', [], [], '', false);
     $this->website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', [], [], '', false);
     $this->rules = $this->getMock('Magento\\CatalogRule\\Model\\Rule', [], [], '', false);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false);
     $this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->dateFormat = $this->getMock('Magento\\Framework\\Stdlib\\DateTime', [], [], '', false);
     $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTime', [], [], '', false);
     $this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connection->expects($this->any())->method('query')->will($this->returnValue($this->db));
     $this->select->expects($this->any())->method('distinct')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('order')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$this->website]));
     $this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->rules->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->rules->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('getConditions')->will($this->returnValue($this->combine));
     $this->rules->expects($this->any())->method('getCustomerGroupIds')->will($this->returnValue([1]));
     $this->ruleCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
     $this->ruleCollectionFactory->expects($this->any())->method('addFieldToFilter')->will($this->returnValue([$this->rules]));
     $this->product->expects($this->any())->method('load')->will($this->returnSelf());
     $this->product->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->product->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->combine->expects($this->any())->method('validate')->will($this->returnValue(true));
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->attribute));
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder($this->ruleCollectionFactory, $this->priceCurrency, $this->resource, $this->storeManager, $this->logger, $this->eavConfig, $this->dateFormat, $this->dateTime, $this->productFactory);
 }
Пример #10
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @return void
  */
 protected function setUp()
 {
     $this->zendDbMock = $this->getMockBuilder('Zend_Db_Statement_Interface')->getMock();
     $this->zendDbMock->expects($this->any())->method('fetchColumn')->willReturn([]);
     $this->selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->setMethods(['from', 'where', 'joinInner', 'joinLeft', 'having', 'useStraightJoin', 'insertFromSelect', '__toString'])->getMock();
     $this->selectMock->expects($this->any())->method('from')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('where')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('joinInner')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('joinLeft')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('having')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('useStraightJoin')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('insertFromSelect')->willReturnSelf();
     $this->selectMock->expects($this->any())->method('__toString')->willReturn('string');
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
     $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
     $this->connectionMock->expects($this->any())->method('query')->willReturn($this->zendDbMock);
     $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource')->disableOriginalConstructor()->getMock();
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->resourceMock->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($arg) {
         return $arg;
     }));
     $this->contextMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Context')->disableOriginalConstructor()->getMock();
     $this->contextMock->expects($this->any())->method('getResources')->willReturn($this->resourceMock);
     $this->loggerMock = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->getMock();
     $dateTime = $this->getMockBuilder('DateTime')->getMock();
     $this->timezoneMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock();
     $this->timezoneMock->expects($this->any())->method('scopeDate')->willReturn($dateTime);
     $this->dateTimeMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->getMock();
     $this->flagMock = $this->getMockBuilder('Magento\\Reports\\Model\\Flag')->disableOriginalConstructor()->setMethods(['setReportFlagCode', 'unsetData', 'loadSelf', 'setFlagData', 'setLastUpdate', 'save'])->getMock();
     $this->flagFactoryMock = $this->getMockBuilder('Magento\\Reports\\Model\\FlagFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->flagFactoryMock->expects($this->any())->method('create')->willReturn($this->flagMock);
     $this->validatorMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\Timezone\\Validator')->disableOriginalConstructor()->getMock();
     $this->backendMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->disableOriginalConstructor()->getMock();
     $this->attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->getMock();
     $this->attributeMock->expects($this->any())->method('getBackend')->willReturn($this->backendMock);
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product')->disableOriginalConstructor()->getMock();
     $this->productMock->expects($this->any())->method('getAttribute')->willReturn($this->attributeMock);
     $this->helperMock = $this->getMockBuilder('Magento\\Reports\\Model\\Resource\\Helper')->disableOriginalConstructor()->getMock();
     $this->viewed = new Viewed($this->contextMock, $this->loggerMock, $this->timezoneMock, $this->flagFactoryMock, $this->dateTimeMock, $this->validatorMock, $this->productMock, $this->helperMock);
 }
Пример #11
0
 public function testProcessNotStaticAttribute()
 {
     $expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)';
     $scopeId = 0;
     $isNegation = false;
     $query = 'SELECT field FROM table';
     $attributeId = 1234567;
     $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
     $this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute'));
     $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute));
     $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false));
     $this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table'));
     $this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId));
     $this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL'));
     $this->select->expects($this->once())->method('from')->with(['main_table' => 'backend_table'], 'entity_id')->will($this->returnSelf());
     $this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf());
     $this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf());
     $this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf());
     $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART'));
     $actualResult = $this->target->process($this->filter, $isNegation, $query);
     $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
 }