예제 #1
0
 /**
  * @test
  * @return void
  */
 public function testLoadData()
 {
     $fileContent = 'content file';
     $media = ['preview_image' => 'preview.jpg'];
     $themeTitle = 'Theme title';
     $themeConfigFile = 'theme.xml';
     $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $parentTheme = ['parentThemeCode'];
     $parentThemePath = 'frontend/parent/theme';
     $themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false);
     $themePackage->expects($this->any())->method('getArea')->will($this->returnValue('frontend'));
     $themePackage->expects($this->any())->method('getVendor')->will($this->returnValue('theme'));
     $themePackage->expects($this->any())->method('getName')->will($this->returnValue('code'));
     $this->themePackageList->expects($this->once())->method('getThemes')->will($this->returnValue([$themePackage]));
     $this->directory->expects($this->once())->method('isExist')->with($themeConfigFile)->willReturn(true);
     $this->directory->expects($this->once())->method('readFile')->with($themeConfigFile)->willReturn($fileContent);
     $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
     $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
     $themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
     $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
     $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
     $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme/code', 'code' => 'theme/code', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => 'theme/parentThemeCode'])->willReturnSelf();
     $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
     $theme->expects($this->once())->method('getArea')->willReturn('frontend');
     $this->assertInstanceOf(get_class($this->model), $this->model->loadData());
 }
 protected function setUp()
 {
     $this->coreEntityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface', [], [], '', false);
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->coreResourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resourceHelperMock = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Helper', [], [], '', false);
     $this->validatorFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false);
     $this->entityFactoryMock = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false);
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->statementMock = $this->getMock('Magento\\Framework\\DB\\Statement\\Pdo\\Mysql', ['fetch'], [], '', false);
     /** @var $selectMock \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->coreEntityFactoryMock->expects($this->any())->method('create')->will($this->returnCallback([$this, 'getMagentoObject']));
     $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
     $connectionMock->expects($this->any())->method('query')->willReturn($this->statementMock);
     $this->coreResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $entityMock = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $entityMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $entityMock->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
     $this->validatorFactoryMock->expects($this->any())->method('create')->with('test_entity_model')->will($this->returnValue($entityMock));
     $this->model = new AbstractCollectionStub($this->coreEntityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->configMock, $this->coreResourceMock, $this->entityFactoryMock, $this->resourceHelperMock, $this->validatorFactoryMock, null);
 }
예제 #3
0
 /**
  * @test
  * @return void
  */
 public function testLoadData()
 {
     $relativeDir = 'dir';
     $fileContent = 'content file';
     $media = ['preview_image' => 'preview.jpg'];
     $themeTitle = 'Theme title';
     $themeConfigs = ['frontend/theme/code'];
     $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock();
     $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock();
     $parentTheme = ['parentThemeCode'];
     $parentThemePath = 'frontend/parent/theme';
     $this->directory->expects($this->once())->method('search')->with($relativeDir)->willReturn($themeConfigs);
     $this->directory->expects($this->any())->method('isExist')->with($themeConfigs[0])->willReturn(true);
     $this->directory->expects($this->any())->method('readFile')->with($themeConfigs[0])->willReturn($fileContent);
     $this->directory->expects($this->any())->method('getRelativePath')->with($themeConfigs[0])->willReturn($themeConfigs[0]);
     $this->directory->expects($this->any())->method('getAbsolutePath')->willReturnMap([[$themeConfigs[0], $themeConfigs[0]], [null, '']]);
     $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig);
     $this->directory->expects($this->at(1))->method('getAbsolutePath')->willReturn('');
     $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme);
     $themeConfig->expects($this->once())->method('getMedia')->willReturn($media);
     $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme);
     $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle);
     $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme', 'code' => 'theme', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => $parentTheme[0]])->willReturnSelf();
     $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath);
     $theme->expects($this->once())->method('getArea')->willReturn('frontend');
     $this->model->addTargetPattern($relativeDir);
     $this->assertInstanceOf(get_class($this->model), $this->model->loadData());
 }
 public function testLoad()
 {
     $data = [10 => 'test'];
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->with($this->selectMock, [])->will($this->returnValue([$data]));
     $objectMock = $this->getMock('Magento\\Framework\\DataObject', ['addData'], []);
     $objectMock->expects($this->once())->method('addData')->with($data);
     $this->entityFactoryMock->expects($this->once())->method('create')->with('Magento\\Review\\Model\\Review\\Summary')->will($this->returnValue($objectMock));
     $this->collection->load();
 }
예제 #5
0
 public function setUp()
 {
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->historyItemMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', ['__wakeup', 'addData'], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getReadConnection', 'getMainTable', 'getTable', '__wakeup']);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $data = [['data']];
     $this->historyItemMock->expects($this->once())->method('addData')->with($this->equalTo($data[0]))->will($this->returnValue($this->historyItemMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->entityFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->historyItemMock));
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->collection = new \Magento\Sales\Model\Resource\Order\Status\History\Collection($this->entityFactoryMock, $logger, $this->fetchStrategyMock, $this->eventManagerMock, $this->connectionMock, $this->resourceMock);
 }
예제 #6
0
파일: DbTest.php 프로젝트: opexsw/magento2
 public function testToOptionHash()
 {
     $data = [10 => 'test'];
     $adapterMock = $this->getMock('Zend_Db_Adapter_Pdo_Mysql', ['select', 'query'], [], '', false);
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], ['adapter' => $adapterMock]);
     $adapterMock->expects($this->once())->method('select')->will($this->returnValue($selectMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->with($selectMock, [])->will($this->returnValue([$data]));
     $objectMock = $this->getMock('Magento\\Framework\\Object', ['addData', 'setIdFieldName', 'getData'], []);
     $objectMock->expects($this->once())->method('addData')->with($data);
     $objectMock->expects($this->any())->method('getData')->will($this->returnValueMap([[null, null, 10], ['name', null, 'test']]));
     $this->entityFactoryMock->expects($this->once())->method('create')->with('Magento\\Framework\\Object')->will($this->returnValue($objectMock));
     $this->collection->setConnection($adapterMock);
     $this->collection->loadData(false, false);
     $this->collection->loadData(false, false);
     $this->assertEquals($data, $this->collection->toOptionHash());
 }