Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FaviconTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Theme\Model\Favicon\Favicon;
13 
17 class FaviconTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $object;
23 
27  protected $store;
28 
32  protected $scopeManager;
33 
38 
42  protected $mediaDir;
43 
47  protected function setUp()
48  {
49  $storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)->getMock();
50  $this->store = $this->getMockBuilder(
51  \Magento\Store\Model\Store::class
52  )->disableOriginalConstructor()->getMock();
53  $storeManager->expects($this->any())
54  ->method('getStore')
55  ->willReturn($this->store);
57  $this->scopeManager = $this->getMockBuilder(
58  \Magento\Framework\App\Config\ScopeConfigInterface::class
59  )->getMock();
60  $this->fileStorageDatabase = $this->getMockBuilder(\Magento\MediaStorage\Helper\File\Storage\Database::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63  $filesystem = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66  $this->mediaDir = $this->getMockBuilder(
67  \Magento\Framework\Filesystem\Directory\ReadInterface::class
68  )->getMock();
69  $filesystem->expects($this->once())
70  ->method('getDirectoryRead')
71  ->with(DirectoryList::MEDIA)
72  ->willReturn($this->mediaDir);
75  $this->object = new Favicon(
77  $this->scopeManager,
78  $this->fileStorageDatabase,
80  );
81  }
82 
86  public function testGetFaviconFileNegative()
87  {
88  $this->assertFalse($this->object->getFaviconFile());
89  }
90 
94  public function testGetFaviconFile()
95  {
96  $scopeConfigValue = 'path';
97  $urlToMediaDir = 'http://magento.url/pub/media/';
98  $expectedFile = ImageFavicon::UPLOAD_DIR . '/' . $scopeConfigValue;
99  $expectedUrl = $urlToMediaDir . $expectedFile;
100 
101  $this->scopeManager->expects($this->once())
102  ->method('getValue')
103  ->with('design/head/shortcut_icon', ScopeInterface::SCOPE_STORE)
104  ->willReturn($scopeConfigValue);
105  $this->store->expects($this->once())
106  ->method('getBaseUrl')
108  ->willReturn($urlToMediaDir);
109  $this->fileStorageDatabase->expects($this->once())
110  ->method('checkDbUsage')
111  ->willReturn(true);
112  $this->fileStorageDatabase->expects($this->once())
113  ->method('saveFileToFilesystem')
114  ->willReturn(true);
115  $this->mediaDir->expects($this->at(0))
116  ->method('isFile')
117  ->with($expectedFile)
118  ->willReturn(false);
119  $this->mediaDir->expects($this->at(1))
120  ->method('isFile')
121  ->with($expectedFile)
122  ->willReturn(true);
123 
124  $results = $this->object->getFaviconFile();
125  $this->assertEquals(
126  $expectedUrl,
127  $results
128  );
129  $this->assertNotFalse($results);
130  }
131 
135  public function testGetDefaultFavicon()
136  {
137  $this->assertEquals('Magento_Theme::favicon.ico', $this->object->getDefaultFavicon());
138  }
139 }
$results
Definition: popup.phtml:13
$storeManager
$filesystem