Skip to content

Commit 177e403

Browse files
author
Alex Bomko
committed
Merge remote-tracking branch 'origin/MAGETWO-38571' into develop
2 parents 9a007f0 + ca78dad commit 177e403

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ public function testStartAction()
6262
$this->assertTrue($variables['success']);
6363
}
6464

65-
public function testStartActionWithError()
65+
public function testStartActionException()
66+
{
67+
$this->webLogger->expects($this->once())->method('clear');
68+
$this->installer->expects($this->once())->method('install')
69+
->willThrowException($this->getMock('\Magento\Setup\SampleDataException'));
70+
$jsonModel = $this->controller->startAction();
71+
$this->assertTrue($jsonModel->getVariable('isSampleDataError'));
72+
}
73+
74+
public function testStartActionWithSampleDataError()
6675
{
6776
$this->webLogger->expects($this->once())->method('clear');
6877
$this->webLogger->expects($this->once())->method('logError');
@@ -108,6 +117,19 @@ public function testProgressActionWithError()
108117
$this->assertStringStartsWith('exception \'LogicException\' with message \'' . $e, $variables['console'][0]);
109118
}
110119

120+
public function testProgressActionWithSampleDataError()
121+
{
122+
$this->progressFactory->expects($this->once())->method('createFromLog')
123+
->willThrowException($this->getMock('\Magento\Setup\SampleDataException'));
124+
$jsonModel = $this->controller->progressAction();
125+
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
126+
$variables = $jsonModel->getVariables();
127+
$this->assertArrayHasKey('success', $variables);
128+
$this->assertArrayHasKey('console', $variables);
129+
$this->assertFalse($variables['success']);
130+
$this->assertTrue($jsonModel->getVariable('isSampleDataError'));
131+
}
132+
111133
public function testDispatch()
112134
{
113135
$request = $this->getMock('\Zend\Http\PhpEnvironment\Request', [], [], '', false);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Test\Unit\Model;
8+
9+
use Magento\Setup\Model\SampleData;
10+
/**
11+
* Test Magento\Setup\Model\SampleData
12+
*/
13+
class InstallerTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Setup\Model\SampleData
17+
*/
18+
protected $sampleDataInstall;
19+
20+
/**
21+
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $objectManagerInterface;
24+
25+
/**
26+
* @var \Magento\Framework\Setup\LoggerInterface
27+
*/
28+
protected $loggerInterface;
29+
30+
/**
31+
* @var \Magento\Framework\App\Filesystem\DirectoryList
32+
*/
33+
protected $directoryList;
34+
35+
protected function setUp()
36+
{
37+
$this->objectManagerInterface = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface');
38+
$this->loggerInterface = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface');
39+
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
40+
$this->sampleDataInstall = new SampleData($this->directoryList);
41+
}
42+
43+
public function testInstall()
44+
{
45+
$areaCode = 'adminhtml';
46+
$userName = 'admin';
47+
$modules = ['module_1', 'module_2'];
48+
$configData = ['config_data'];
49+
$sampleDataLogger = $this->getMock('Magento\SampleData\Model\Logger', ['setSubject'], [], '', false);
50+
$appState = $this->getMock('Magento\Framework\App\State', ['setAreaCode'], [], '', false);
51+
$configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', ['load'], [], '', false);
52+
$installer = $this->getMock('Magento\SampleData\Model\Installer', ['run'], [], '', false);
53+
$this->objectManagerInterface->expects($this->any())->method('get')->willReturnMap(
54+
[
55+
['Magento\SampleData\Model\Logger', $sampleDataLogger],
56+
['Magento\Framework\App\State', $appState],
57+
['Magento\Framework\App\ObjectManager\ConfigLoader', $configLoader],
58+
['Magento\SampleData\Model\Installer', $installer]
59+
]
60+
);
61+
$sampleDataLogger->expects($this->any())->method('setSubject')->with($this->loggerInterface)->willReturnSelf();
62+
$appState->expects($this->once())->method('setAreaCode')->with($areaCode)->willReturnSelf();
63+
$configLoader->expects($this->once())->method('load')->with($areaCode)->willReturn($configData);
64+
$this->objectManagerInterface->expects($this->once())->method('configure')->with($configData)
65+
->willReturnSelf();
66+
$installer->expects($this->once())->method('run')->with($userName, $modules);
67+
$this->sampleDataInstall->install($this->objectManagerInterface, $this->loggerInterface, $userName, $modules);
68+
}
69+
70+
public function testIsDeployed()
71+
{
72+
$this->directoryList->expects($this->once())->method('getPath')->with('code');
73+
$this->sampleDataInstall->isDeployed();
74+
}
75+
76+
/**
77+
* Test SampleData installation check method.
78+
* Can be tested only negative case because file_exists method used in the tested class
79+
*/
80+
public function testIsInstalledSuccessfully()
81+
{
82+
$this->assertFalse($this->sampleDataInstall->isInstalledSuccessfully());
83+
}
84+
}

0 commit comments

Comments
 (0)