|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\SampleData\Test\Unit\Model; |
| 8 | + |
| 9 | +use Magento\SampleData\Model\SampleData; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test Magento\Setup\Model\SampleData |
| 13 | + */ |
| 14 | +class SampleDataTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \Magento\SampleData\Model\SampleData |
| 18 | + */ |
| 19 | + protected $sampleDataInstall; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Framework\App\Filesystem\DirectoryList |
| 23 | + */ |
| 24 | + protected $directoryList; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Magento\SampleData\Helper\State|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + protected $state; |
| 30 | + |
| 31 | + protected function setUp() |
| 32 | + { |
| 33 | + $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); |
| 34 | + $this->state = $this->getMock('Magento\SampleData\Helper\State', [], [], '', false); |
| 35 | + $this->sampleDataInstall = new SampleData($this->directoryList, $this->state); |
| 36 | + } |
| 37 | + |
| 38 | + public function testIsInstalledSuccessfullyTrue() |
| 39 | + { |
| 40 | + $this->state->expects($this->once()) |
| 41 | + ->method('getState') |
| 42 | + ->willReturn(\Magento\SampleData\Helper\State::STATE_FINISHED); |
| 43 | + $this->assertTrue($this->sampleDataInstall->isInstalledSuccessfully()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testIsInstalledSuccessfullyFalse() |
| 47 | + { |
| 48 | + $this->state->expects($this->once()) |
| 49 | + ->method('getState') |
| 50 | + ->willReturn(\Magento\SampleData\Helper\State::STATE_NOT_STARTED); |
| 51 | + $this->assertFalse($this->sampleDataInstall->isInstalledSuccessfully()); |
| 52 | + } |
| 53 | + |
| 54 | + public function testIsInstallationErrorTrue() |
| 55 | + { |
| 56 | + $this->state->expects($this->once()) |
| 57 | + ->method('getState') |
| 58 | + ->willReturn(\Magento\SampleData\Helper\State::STATE_STARTED); |
| 59 | + $this->assertTrue($this->sampleDataInstall->isInstallationError()); |
| 60 | + } |
| 61 | + |
| 62 | + public function testIsInstallationErrorFalse() |
| 63 | + { |
| 64 | + $this->state->expects($this->once()) |
| 65 | + ->method('getState') |
| 66 | + ->willReturn(\Magento\SampleData\Helper\State::STATE_NOT_STARTED); |
| 67 | + $this->assertFalse($this->sampleDataInstall->isInstallationError()); |
| 68 | + } |
| 69 | + |
| 70 | + public function testInstall() |
| 71 | + { |
| 72 | + $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false); |
| 73 | + $logger = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface', [], '', false); |
| 74 | + $sampleLogger = $this->getMock('Magento\SampleData\Model\Logger', [], [], '', false); |
| 75 | + $sampleLogger->expects($this->once())->method('setSubject')->with($logger); |
| 76 | + $objectManager->expects($this->at(0))->method('get')->willReturn($sampleLogger); |
| 77 | + $state = $this->getMock('Magento\Framework\App\State', [], [], '', false); |
| 78 | + $objectManager->expects($this->at(1))->method('get')->willReturn($state); |
| 79 | + $state->expects($this->once())->method('setAreaCode')->with('adminhtml'); |
| 80 | + $configLoader = $this->getMockForAbstractClass( |
| 81 | + 'Magento\Framework\ObjectManager\ConfigLoaderInterface', |
| 82 | + [], |
| 83 | + '', |
| 84 | + false |
| 85 | + ); |
| 86 | + $objectManager->expects($this->at(2))->method('get')->willReturn($configLoader); |
| 87 | + $configLoader->expects($this->once())->method('load')->willReturn([]); |
| 88 | + $objectManager->expects($this->at(3))->method('configure')->with([]); |
| 89 | + $installer = $this->getMock('Magento\SampleData\Model\Installer', [], [], '', false); |
| 90 | + $objectManager->expects($this->at(4))->method('get')->willReturn($installer); |
| 91 | + $installer->expects($this->once())->method('run')->with('admin', []); |
| 92 | + $this->sampleDataInstall->install($objectManager, $logger, 'admin', []); |
| 93 | + } |
| 94 | +} |
0 commit comments