示例#1
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Specification must implement SpecificationInterface
  */
 public function testWrongTypeException()
 {
     $className = 'WrongClass';
     $methodMock = $this->getMock($className);
     $this->objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($methodMock));
     $this->factory->create($className);
 }
示例#2
0
 /**
  * @param mixed $class
  * @param array $arguments
  * @param string $expectedClassName
  * @dataProvider createDataProvider
  */
 public function testCreate($class, $arguments, $expectedClassName)
 {
     $createdModel = $this->getMock('Magento\\Sales\\Model\\Order\\Pdf\\Total\\DefaultTotal', array(), array(), (string) $class, false);
     $this->_objectManager->expects($this->once())->method('create')->with($expectedClassName, $arguments)->will($this->returnValue($createdModel));
     $actual = $this->_factory->create($class, $arguments);
     $this->assertSame($createdModel, $actual);
 }
示例#3
0
 public function testCreateCheckout()
 {
     $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods([])->getMock();
     $instance = $this->getMockBuilder('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface')->getMock();
     $this->objectManagerMock->expects($this->once())->method('create')->with(Factory::CHECKOUT_VALIDATOR)->will($this->returnValue($instance));
     $this->assertInstanceOf('Magento\\Paypal\\Helper\\Shortcut\\ValidatorInterface', $this->factory->create($checkoutMock));
 }
 public function testCreate()
 {
     $type = '1';
     $data = ['data2', 'data3'];
     $this->objectManagerMock->expects($this->once())->method('create')->with($type, $data);
     $this->conditionFactory->create($type, $data);
 }
示例#5
0
 protected function setUp()
 {
     $this->_session = $this->getMock('Magento\\Customer\\Model\\Session', array(), array(), '', false);
     $this->_agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', array('load', 'getId', 'getCustomerId', 'getReferenceId', 'canCancel', 'cancel', '__wakeup'), array(), '', false);
     $this->_agreement->expects($this->once())->method('load')->with(15)->will($this->returnSelf());
     $this->_agreement->expects($this->once())->method('getId')->will($this->returnValue(15));
     $this->_agreement->expects($this->once())->method('getCustomerId')->will($this->returnValue(871));
     $this->_objectManager = $this->getMock('Magento\\Framework\\ObjectManager');
     $this->_objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap(array(array('Magento\\Customer\\Model\\Session', $this->_session))));
     $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Paypal\\Model\\Billing\\Agreement')->will($this->returnValue($this->_agreement));
     $this->_request = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->_request->expects($this->once())->method('getParam')->with('agreement')->will($this->returnValue(15));
     $response = $this->getMock('Magento\\Framework\\App\\ResponseInterface');
     $redirect = $this->getMock('Magento\\Framework\\App\\Response\\RedirectInterface');
     $this->_messageManager = $this->getMock('Magento\\Framework\\Message\\ManagerInterface');
     $context = $this->getMock('Magento\\Framework\\App\\Action\\Context', array(), array(), '', false);
     $context->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager));
     $context->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request));
     $context->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $context->expects($this->any())->method('getRedirect')->will($this->returnValue($redirect));
     $context->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->_messageManager));
     $this->_registry = $this->getMock('Magento\\Framework\\Registry', array(), array(), '', false);
     $title = $this->getMock('Magento\\Framework\\App\\Action\\Title', array(), array(), '', false);
     $this->_controller = new Cancel($context, $this->_registry, $title);
 }
示例#6
0
 /**
  * @covers \Magento\Framework\App\RequestFactory::__construct
  * @covers \Magento\Framework\App\RequestFactory::create
  */
 public function testCreate()
 {
     $arguments = ['some_key' => 'same_value'];
     $appRequest = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\RequestInterface', $arguments)->will($this->returnValue($appRequest));
     $this->assertEquals($appRequest, $this->model->create($arguments));
 }
示例#7
0
 public function testGet()
 {
     $actionInterfaceMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ActionInterface', array(), '', false);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Mview\\ActionInterface')->will($this->returnValue($actionInterfaceMock));
     $this->model->get('Magento\\Framework\\Mview\\ActionInterface');
     $this->assertInstanceOf('Magento\\Framework\\Mview\\ActionInterface', $actionInterfaceMock);
 }
示例#8
0
 public function testGetNonShared()
 {
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Mview\\Config\\Data')->will($this->returnValue($this->dataMock));
     $this->dataMock->expects($this->once())->method('get')->with('some_path', 'default')->will($this->returnValue('some_value'));
     $this->model = new Proxy($this->objectManagerMock, 'Magento\\Framework\\Mview\\Config\\Data', false);
     $this->assertEquals('some_value', $this->model->get('some_path', 'default'));
 }
示例#9
0
 /**
  * @expectedException \Magento\Framework\Model\Exception
  * @expectedExceptionMessage WrongClass doesn't extends \Magento\Framework\Filter\Template
  */
 public function testWrongTypeException()
 {
     $className = 'WrongClass';
     $filterMock = $this->getMock($className, array(), array(), '', false);
     $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($filterMock));
     $this->_factory->create($className);
 }
示例#10
0
 public function testCreateBlock()
 {
     $className = 'Magento\\Framework\\View\\Element\\Template';
     $argumentsResult = ['arg1', 'arg2'];
     $templateMock = $this->getMockBuilder('Magento\\Framework\\View\\Element\\Template')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock->expects($this->once())->method('create')->with($className, $argumentsResult)->will($this->returnValue($templateMock));
     $this->assertInstanceOf('Magento\\Framework\\View\\Element\\BlockInterface', $this->blockFactory->createBlock($className, $argumentsResult));
 }
示例#11
0
 public function testCreateWithArguments()
 {
     $className = 'SomeModel';
     $data = array('param1', 'param2');
     $classMock = $this->getMock('SomeModel');
     $this->_objectManagerMock->expects($this->once())->method('create')->with($className, $data)->will($this->returnValue($classMock));
     $this->assertEquals($classMock, $this->_factory->create($className, $data));
 }
示例#12
0
 public function testGetHandlers()
 {
     $backendHandlerMock = $this->getMock('Magento\\Backend\\App\\Router\\NoRouteHandler', array(), array(), '', false);
     $defaultHandlerMock = $this->getMock('Magento\\Core\\App\\Router\\NoRouteHandler', array(), array(), '', false);
     $this->_objectManagerMock->expects($this->at(0))->method('create')->with('Magento\\Backend\\App\\Router\\NoRouteHandler')->will($this->returnValue($backendHandlerMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with('Magento\\Core\\App\\Router\\NoRouteHandler')->will($this->returnValue($defaultHandlerMock));
     $expectedResult = array('0' => $backendHandlerMock, '1' => $defaultHandlerMock);
     $this->assertEquals($expectedResult, $this->_model->getHandlers());
 }
示例#13
0
 public function testCreate()
 {
     $className = 'Magento\\Class';
     $observerMock = $this->getMock('Magento\\Observer', [], [], '', false, false);
     $arguments = ['arg1', 'arg2'];
     $this->objectManagerMock->expects($this->once())->method('create')->with($className, $this->equalTo($arguments))->will($this->returnValue($observerMock));
     $result = $this->observerFactory->create($className, $arguments);
     $this->assertEquals($observerMock, $result);
 }
示例#14
0
 /**
  * @dataProvider evaluateWrongClassDataProvider
  */
 public function testEvaluateWrongClass($input, $expectedException, $expectedExceptionMessage)
 {
     $this->setExpectedException($expectedException, $expectedExceptionMessage);
     $self = $this;
     $this->_objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) use($self) {
         return $self->getMock($className);
     }));
     $this->_model->evaluate($input);
 }
示例#15
0
 public function testGetAdditionalHtmlAttribute()
 {
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\Translate\\Inline')->will($this->returnValue($this->translateMock));
     $this->objectManagerMock->expects($this->never())->method('get');
     $this->translateMock->expects($this->exactly(2))->method('getAdditionalHtmlAttribute')->with($this->logicalOr('some_value', null))->will($this->returnArgument(0));
     $model = new Proxy($this->objectManagerMock, 'Magento\\Framework\\Translate\\Inline', false);
     $this->assertEquals('some_value', $model->getAdditionalHtmlAttribute('some_value'));
     $this->assertNull($model->getAdditionalHtmlAttribute());
 }
示例#16
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage Instance of layout argument updater is expected
  */
 public function testEvaluateWrongUpdaterClass()
 {
     $input = array('value' => 'some text', 'updater' => array('Magento\\Framework\\View\\Layout\\Argument\\UpdaterInterface', 'Magento\\Framework\\ObjectManager'));
     $self = $this;
     $this->_objectManager->expects($this->exactly(2))->method('get')->will($this->returnCallback(function ($className) use($self) {
         return $self->getMockForAbstractClass($className);
     }));
     $this->_model->evaluate($input);
 }
示例#17
0
 public function testEvaluate()
 {
     $input = array('value' => 'some text', 'helper' => __CLASS__ . '::help');
     $evaluatedValue = array('value' => 'some text (evaluated)');
     $this->_interpreter->expects($this->once())->method('evaluate')->with($input)->will($this->returnValue($evaluatedValue));
     $this->_objectManager->expects($this->once())->method('get')->with(__CLASS__)->will($this->returnValue($this));
     $expected = 'some text (evaluated) (updated)';
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
 public function testCreate()
 {
     $rawResponse = ['documents' => [['title' => 'oneTitle', 'description' => 'oneDescription'], ['title' => 'twoTitle', 'description' => 'twoDescription']], 'aggregations' => []];
     $exceptedResponse = ['documents' => [[['name' => 'title', 'value' => 'oneTitle'], ['name' => 'description', 'value' => 'oneDescription']], [['name' => 'title', 'value' => 'twoTitle'], ['name' => 'description', 'value' => 'twoDescription']]], 'aggregations' => []];
     $this->documentFactory->expects($this->at(0))->method('create')->with($this->equalTo($exceptedResponse['documents'][0]))->will($this->returnValue('document1'));
     $this->documentFactory->expects($this->at(1))->method('create')->with($exceptedResponse['documents'][1])->will($this->returnValue('document2'));
     $this->objectManager->expects($this->once())->method('create')->with($this->equalTo('\\Magento\\Framework\\Search\\QueryResponse'), $this->equalTo(['documents' => ['document1', 'document2'], 'aggregations' => null]))->will($this->returnValue('QueryResponseObject'));
     $result = $this->factory->create($rawResponse);
     $this->assertEquals('QueryResponseObject', $result);
 }
示例#19
0
 public function testGetAdditionalElementTypes()
 {
     $method = self::getMethod('_getAdditionalElementTypes');
     /** @var $configModel \Magento\Framework\App\Config\ScopeConfigInterface */
     $configModel = $this->getMock('Magento\\Framework\\App\\Config\\ScopeConfigInterface');
     $this->_objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\App\\Config\\ScopeConfigInterface')->will($this->returnValue($configModel));
     $result = $method->invokeArgs($this->_model, array());
     $expectedResult = array('links' => 'Magento\\Theme\\Block\\Adminhtml\\System\\Design\\Theme\\Edit\\Form\\Element\\Links', 'css_file' => 'Magento\\Theme\\Block\\Adminhtml\\System\\Design\\Theme\\Edit\\Form\\Element\\File');
     $this->assertEquals($expectedResult, $result);
 }
示例#20
0
 /**
  * @param string|null $fixtureFrontendId
  * @param string $inputCacheType
  * @param string $expectedFrontendId
  *
  * @dataProvider getDataProvider
  */
 public function testGet($fixtureFrontendId, $inputCacheType, $expectedFrontendId)
 {
     $this->_arguments->expects($this->once())->method('getCacheTypeFrontendId')->with($inputCacheType)->will($this->returnValue($fixtureFrontendId));
     $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface');
     $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend));
     $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', array(), array(), '', false);
     $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(array('frontend' => $cacheFrontend, 'identifier' => $inputCacheType)))->will($this->returnValue($accessProxy));
     $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
     // Result has to be cached in memory
     $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
 }
示例#21
0
 protected function setUp()
 {
     $this->_data = array('id' => '1385661590_snapshot', 'time' => 1385661590, 'path' => 'C:\\test\\test\\var\\backups', 'name' => '', 'type' => 'snapshot');
     $this->_fsCollection = $this->getMock('Magento\\Backup\\Model\\Fs\\Collection', array(), array(), '', false);
     $this->_fsCollection->expects($this->at(0))->method('getIterator')->will($this->returnValue(new \ArrayIterator(array(new \Magento\Framework\Object($this->_data)))));
     $this->_backupModel = $this->getMock('Magento\\Backup\\Model\\Backup', array(), array(), '', false);
     $this->_objectManager = $this->getMock('Magento\\Framework\\ObjectManager');
     $this->_objectManager->expects($this->at(0))->method('get')->with('Magento\\Backup\\Model\\Fs\\Collection')->will($this->returnValue($this->_fsCollection));
     $this->_objectManager->expects($this->at(1))->method('get')->with('Magento\\Backup\\Model\\Backup')->will($this->returnValue($this->_backupModel));
     $this->_instance = new \Magento\Backup\Model\BackupFactory($this->_objectManager);
 }
示例#22
0
 protected function setObjectManager()
 {
     $this->objectManager = $this->getMock('\\Magento\\Framework\\ObjectManager', [], [], '', false);
     $this->objectManager->expects($this->any())->method('create')->with($this->logicalOr($this->equalTo('model'), $this->equalTo('null')), $this->equalTo([]))->will($this->returnCallback(function ($className) {
         $returnValue = null;
         if ($className == 'model') {
             $returnValue = $this->model;
         }
         return $returnValue;
     }));
 }
示例#23
0
 /**
  * @codingStandardsIgnoreStart
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Magento\Framework\Pricing\PriceInfo\Base doesn't implement \Magento\Framework\Pricing\Price\PriceInterface
  * @codingStandardsIgnoreEnd
  */
 public function testCreateWithException()
 {
     $quantity = 2.2;
     $className = 'Magento\\Framework\\Pricing\\PriceInfo\\Base';
     $priceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
     $saleableItem = $this->getMock('Magento\\Framework\\Pricing\\Object\\SaleableInterface');
     $arguments = [];
     $argumentsResult = array_merge($arguments, ['saleableItem' => $saleableItem, 'quantity' => $quantity]);
     $this->objectManagerMock->expects($this->once())->method('create')->with($className, $argumentsResult)->will($this->returnValue($priceMock));
     $this->model->create($saleableItem, $className, $quantity, $arguments);
 }
示例#24
0
 public function testEvaluate()
 {
     $modelClass = 'Magento\\Framework\\Data\\OptionSourceInterface';
     $model = $this->getMockForAbstractClass($modelClass);
     $model->expects($this->once())->method('toOptionArray')->will($this->returnValue(array('value1' => 'label 1', 'value2' => 'label 2', array('value' => 'value3', 'label' => 'label 3'))));
     $this->_objectManager->expects($this->once())->method('get')->with($modelClass)->will($this->returnValue($model));
     $input = array('model' => $modelClass);
     $expected = array(array('value' => 'value1', 'label' => 'label 1'), array('value' => 'value2', 'label' => 'label 2'), array('value' => 'value3', 'label' => 'label 3'));
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
示例#25
0
 public function testRewind()
 {
     $frontClass = new FrontClass();
     $defaultClass = new DefaultClass();
     $this->objectManagerMock->expects($this->at(0))->method('create')->with('DefaultClass')->will($this->returnValue($defaultClass));
     $this->objectManagerMock->expects($this->at(1))->method('create')->with('FrontClass')->will($this->returnValue($frontClass));
     $this->assertEquals($defaultClass, $this->model->current());
     $this->model->next();
     $this->assertEquals($frontClass, $this->model->current());
     $this->model->rewind();
     $this->assertEquals($defaultClass, $this->model->current());
 }
示例#26
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage Filter factory must implement FilterFactoryInterface interface, stdClass was given.
  */
 public function testGetFilterFactoriesWrongInstance()
 {
     $factoryName = 'Magento\\Framework\\Filter\\Factory';
     $this->_factoryMock = new \stdClass();
     $this->_objectManager = $this->getMockForAbstractClass('\\Magento\\Framework\\ObjectManager', array(), '', true, true, true, array('create'));
     $this->_objectManager->expects($this->atLeastOnce())->method('create')->with($this->equalTo($factoryName))->will($this->returnValue($this->_factoryMock));
     $this->_config = $this->getMock('\\Magento\\Framework\\Filter\\FilterManager\\Config', array('getFactories'), array(), '', false);
     $this->_config->expects($this->atLeastOnce())->method('getFactories')->will($this->returnValue(array($factoryName)));
     $this->_filterManager = new \Magento\Framework\Filter\FilterManager($this->_objectManager, $this->_config);
     $method = new \ReflectionMethod('Magento\\Framework\\Filter\\FilterManager', 'getFilterFactories');
     $method->setAccessible(true);
     $method->invoke($this->_filterManager);
 }
示例#27
0
 /**
  * Save default translator
  */
 protected function setUp()
 {
     $this->_defaultTranslator = \Magento\Framework\Validator\AbstractValidator::getDefaultTranslator();
     $this->_objectManager = $this->getMock('Magento\\Framework\\ObjectManager');
     $this->_validatorConfig = $this->getMockBuilder('Magento\\Framework\\Validator\\Config')->setMethods(array('createValidatorBuilder', 'createValidator'))->disableOriginalConstructor()->getMock();
     $this->_objectManager->expects($this->at(0))->method('create')->with('Magento\\Framework\\Translate\\Adapter')->will($this->returnValue(new \Magento\Framework\Translate\Adapter()));
     $this->_objectManager->expects($this->at(1))->method('create')->with('Magento\\Framework\\Validator\\Config', array('configFiles' => array('/tmp/moduleOne/etc/validation.xml')))->will($this->returnValue($this->_validatorConfig));
     // Config mock
     $this->_config = $this->getMockBuilder('Magento\\Framework\\Module\\Dir\\Reader')->setMethods(array('getConfigurationFiles'))->disableOriginalConstructor()->getMock();
     $this->_config->expects($this->once())->method('getConfigurationFiles')->with('validation.xml')->will($this->returnValue(array('/tmp/moduleOne/etc/validation.xml')));
     // Translate adapter mock
     $this->_translateAdapter = $this->getMockBuilder('Magento\\Framework\\TranslateInterface')->disableOriginalConstructor()->getMock();
 }
示例#28
0
 /**
  * Processing section runtime errors
  *
  * @return void
  */
 protected function exceptionResponse()
 {
     $dataMock = $this->getMock('Magento\\Core\\Helper\\Data', ['jsonEncode'], [], '', false);
     $this->objectManagerMock->expects($this->once())->method('get')->will($this->returnValue($dataMock));
     $dataMock->expects($this->once())->method('jsonEncode')->will($this->returnValue('{json-data}'));
     $this->responseMock->expects($this->once())->method('representJson')->with('{json-data}');
 }
示例#29
0
 /**
  * Represent json json section
  *
  * @param array $errors
  * @return void
  */
 protected function representJson(array $errors)
 {
     $dataHelper = $this->getMock('Magento\\Core\\Helper\\Data', ['jsonEncode'], [], '', false);
     $dataHelper->expects($this->once())->method('jsonEncode')->with($errors)->will($this->returnValue('{json}'));
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Core\\Helper\\Data')->will($this->returnValue($dataHelper));
     $this->responseMock->expects($this->once())->method('representJson')->with('{json}');
 }
示例#30
0
 public function testExecute()
 {
     $type = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|attribute_set_id';
     $this->request->expects($this->at(0))->method('getParam')->with('id')->will($this->returnValue('1--1'));
     $this->request->expects($this->at(1))->method('getParam')->with('type')->will($this->returnValue($type));
     $this->request->expects($this->at(2))->method('getParam')->with('form')->will($this->returnValue('request_form_param_value'));
     $condition = $this->getMockBuilder('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->setMethods(['setId', 'setType', 'setRule', 'setPrefix', 'setAttribute', 'asHtmlRecursive', 'setJsFormObject'])->disableOriginalConstructor()->getMock();
     $condition->expects($this->once())->method('setId')->with('1--1')->will($this->returnSelf());
     $condition->expects($this->once())->method('setType')->with('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->will($this->returnSelf());
     $condition->expects($this->once())->method('setRule')->with($this->rule)->will($this->returnSelf());
     $condition->expects($this->once())->method('setPrefix')->with('conditions')->will($this->returnSelf());
     $condition->expects($this->once())->method('setJsFormObject')->with('request_form_param_value')->will($this->returnSelf());
     $condition->expects($this->once())->method('setAttribute')->with('attribute_set_id')->will($this->returnSelf());
     $condition->expects($this->once())->method('asHtmlRecursive')->will($this->returnValue('<some_html>'));
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($condition));
     $this->response->expects($this->once())->method('setBody')->with('<some_html>')->will($this->returnSelf());
     $this->controller->execute();
 }