Пример #1
0
 /**
  * Load variable by code
  *
  * @param \Magento\Variable\Model\Variable $object
  * @param string $code
  * @return $this
  */
 public function loadByCode(\Magento\Variable\Model\Variable $object, $code)
 {
     if ($result = $this->getVariableByCode($code, true, $object->getStoreId())) {
         $object->setData($result);
     }
     return $this;
 }
Пример #2
0
 /**
  * @dataProvider validateDataProvider
  */
 public function testValidate($variableArray, $objectId, $expectedResult)
 {
     $code = 'variable_code';
     $this->model->setCode($code)->setName('some_name');
     $this->resourceMock->expects($this->once())->method('getVariableByCode')->with($code)->willReturn($variableArray);
     $this->model->setId($objectId);
     $this->assertEquals($expectedResult, $this->model->validate($variableArray));
 }
Пример #3
0
 public function testCollection()
 {
     $collection = $this->_model->getCollection();
     $collection->setStoreId(1);
     $this->assertEquals(1, $collection->getStoreId(), 'Store id setter and getter');
     $collection->addValuesToResult();
     $this->assertContains('variable_value', (string) $collection->getSelect());
 }
Пример #4
0
 /**
  * @covers \Magento\Email\Block\Adminhtml\Template\Edit\Form::getVariables
  */
 public function testGetVariables()
 {
     $this->variablesMock->expects($this->once())->method('toOptionArray')->willReturn(['var1', 'var2', 'var3']);
     $this->variableFactoryMock->expects($this->once())->method('create')->willReturn($this->variableMock);
     $this->variableMock->expects($this->once())->method('getVariablesOptionArray')->willReturn(['custom var 1', 'custom var 2']);
     $this->registryMock->expects($this->once())->method('registry')->willReturn($this->templateMock);
     $this->templateMock->expects($this->once())->method('getId')->willReturn(1);
     $this->templateMock->expects($this->once())->method('getVariablesOptionArray')->willReturn(['template var 1', 'template var 2']);
     $this->assertEquals([['var1', 'var2', 'var3'], ['custom var 1', 'custom var 2'], ['template var 1', 'template var 2']], $this->form->getVariables());
 }
Пример #5
0
 /**
  * @param mixed $result
  * @param string[] $responseArray
  * @dataProvider executeDataProvider
  */
 public function testExecute($result, $responseArray)
 {
     $getParamMap = [['variable_id', null, null], ['store', 0, 0]];
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap($getParamMap);
     $this->requestMock->expects($this->any())->method('getPost')->with('variable')->will($this->returnValue([]));
     $this->variableMock->expects($this->any())->method('validate')->willReturn($result);
     if ($result instanceof \Magento\Framework\Phrase) {
         $this->messageManagerMock->expects($this->once())->method('addError')->with($result->getText());
         $this->layoutMock->expects($this->once())->method('initMessages');
     }
     $this->resultJsonMock->expects($this->once())->method('setData')->with($responseArray);
     $this->validateMock->execute();
 }