Skip to content

Commit 4faa20a

Browse files
MAGETWO-31369: [South] Unit and Integration tests coverage
1 parent d69b608 commit 4faa20a

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Model\Favicon;
7+
8+
use Magento\Backend\Model\Config\Backend\Image\Favicon as ImageFavicon;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\UrlInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
class FaviconTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var Favicon
17+
*/
18+
protected $object;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
22+
*/
23+
protected $store;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
27+
*/
28+
protected $scopeManager;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Core\Helper\File\Storage\Database
32+
*/
33+
protected $fileStorageDatabase;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\ReadInterface
37+
*/
38+
protected $mediaDir;
39+
40+
/**
41+
* Initialize testable object
42+
*/
43+
public function setUp()
44+
{
45+
$storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')->getMock();
46+
$this->store = $this->getMockBuilder('Magento\Store\Model\Store')->disableOriginalConstructor()->getMock();
47+
$storeManager->expects($this->any())
48+
->method('getStore')
49+
->willReturn($this->store);
50+
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
51+
$this->scopeManager = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')->getMock();
52+
$this->fileStorageDatabase = $this->getMockBuilder('Magento\Core\Helper\File\Storage\Database')
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
56+
->disableOriginalConstructor()
57+
->getMock();
58+
$this->mediaDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface')->getMock();
59+
$filesystem->expects($this->once())
60+
->method('getDirectoryRead')
61+
->with(DirectoryList::MEDIA)
62+
->willReturn($this->mediaDir);
63+
/** @var \Magento\Framework\Filesystem $filesystem */
64+
65+
$this->object = new Favicon(
66+
$storeManager,
67+
$this->scopeManager,
68+
$this->fileStorageDatabase,
69+
$filesystem
70+
);
71+
}
72+
73+
/**
74+
* cover negative case for getFaviconFile
75+
*/
76+
public function testGetFaviconFileNegative()
77+
{
78+
$this->assertFalse($this->object->getFaviconFile());
79+
}
80+
81+
/**
82+
* cover positive case for getFaviconFile and checkIsFile
83+
*/
84+
public function testGetFaviconFile()
85+
{
86+
$scopeConfigValue = 'path';
87+
$urlToMediaDir = 'http://magneto.url/pub/media/';
88+
$expectedFile = ImageFavicon::UPLOAD_DIR . '/' . $scopeConfigValue;
89+
$expectedUrl = $urlToMediaDir . $expectedFile;
90+
91+
$this->scopeManager->expects($this->once())
92+
->method('getValue')
93+
->with('design/head/shortcut_icon', ScopeInterface::SCOPE_STORE)
94+
->willReturn($scopeConfigValue);
95+
$this->store->expects($this->once())
96+
->method('getBaseUrl')
97+
->with(UrlInterface::URL_TYPE_MEDIA)
98+
->willReturn($urlToMediaDir);
99+
$this->fileStorageDatabase->expects($this->once())
100+
->method('checkDbUsage')
101+
->willReturn(true);
102+
$this->fileStorageDatabase->expects($this->once())
103+
->method('saveFileToFilesystem')
104+
->willReturn(true);
105+
$this->mediaDir->expects($this->at(0))
106+
->method('isFile')
107+
->with($expectedFile)
108+
->willReturn(false);
109+
$this->mediaDir->expects($this->at(1))
110+
->method('isFile')
111+
->with($expectedFile)
112+
->willReturn(true);
113+
114+
$results = $this->object->getFaviconFile();
115+
$this->assertEquals(
116+
$expectedUrl,
117+
$results
118+
);
119+
$this->assertNotFalse($results);
120+
}
121+
122+
/**
123+
* cover getDefaultFavicon
124+
*/
125+
public function testGetDefaultFavicon()
126+
{
127+
$this->assertEquals('Magento_Theme::favicon.ico', $this->object->getDefaultFavicon());
128+
}
129+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Model\Theme\Customization\File;
7+
8+
class CustomCssTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Design\Theme\Customization\Path
12+
*/
13+
protected $customizationPath;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Design\Theme\FileFactory
17+
*/
18+
protected $fileFactory;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem
22+
*/
23+
protected $filesystem;
24+
25+
/**
26+
* @var CustomCss
27+
*/
28+
protected $object;
29+
30+
/**
31+
* Initialize testable object
32+
*/
33+
public function setUp()
34+
{
35+
$this->customizationPath = $this->getMockBuilder('Magento\Framework\View\Design\Theme\Customization\Path')
36+
->disableOriginalConstructor()
37+
->getMock();
38+
$this->fileFactory = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FileFactory')
39+
->setMethods(['create'])
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
46+
$this->object = new CustomCss(
47+
$this->customizationPath,
48+
$this->fileFactory,
49+
$this->filesystem
50+
);
51+
}
52+
53+
/**
54+
* cover _prepareSortOrder
55+
* cover _prepareFileName
56+
*/
57+
public function testPrepareFile()
58+
{
59+
$file = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FileInterface')
60+
->setMethods(
61+
[
62+
'delete',
63+
'save',
64+
'getContent',
65+
'getFileInfo',
66+
'getFullPath',
67+
'getFileName',
68+
'setFileName',
69+
'getTheme',
70+
'setTheme',
71+
'getCustomizationService',
72+
'setCustomizationService',
73+
'getId',
74+
'setData',
75+
]
76+
)
77+
->getMock();
78+
$file->expects($this->any())
79+
->method('setData')
80+
->willReturnMap(
81+
[
82+
['file_type', CustomCss::TYPE, $this->returnSelf()],
83+
['file_path', CustomCss::TYPE . '/' . CustomCss::FILE_NAME, $this->returnSelf()],
84+
['sort_order', CustomCss::SORT_ORDER, $this->returnSelf()],
85+
]
86+
);
87+
$file->expects($this->once())
88+
->method('getId')
89+
->willReturn(null);
90+
$file->expects($this->at(0))
91+
->method('getFileName')
92+
->willReturn(null);
93+
$file->expects($this->at(1))
94+
->method('getFileName')
95+
->willReturn(CustomCss::FILE_NAME);
96+
$file->expects($this->once())
97+
->method('setFileName')
98+
->with(CustomCss::FILE_NAME);
99+
100+
/** @var $file \Magento\Framework\View\Design\Theme\FileInterface */
101+
$this->assertInstanceOf(
102+
'Magento\Theme\Model\Theme\Customization\File\CustomCss',
103+
$this->object->prepareFile($file)
104+
);
105+
}
106+
}

0 commit comments

Comments
 (0)