|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Downloadable\Test\Unit\Helper; |
| 10 | + |
| 11 | +use Magento\Downloadable\Model\Link; |
| 12 | +use Magento\Store\Model\ScopeInterface; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | +use Magento\Downloadable\Helper\Data; |
| 15 | +use Magento\Framework\App\Helper\Context; |
| 16 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 17 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 18 | + |
| 19 | +class DataTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var Data |
| 23 | + */ |
| 24 | + private $helper; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $scopeConfigMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var Context|\PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + private $contextMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * Setup environment for test |
| 38 | + */ |
| 39 | + protected function setUp() |
| 40 | + { |
| 41 | + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); |
| 42 | + $this->contextMock = $this->createMock(Context::class); |
| 43 | + $this->contextMock->method('getScopeConfig')->willReturn($this->scopeConfigMock); |
| 44 | + |
| 45 | + $objectManager = new ObjectManagerHelper($this); |
| 46 | + $this->helper = $objectManager->getObject( |
| 47 | + Data::class, |
| 48 | + ['context' => $this->contextMock] |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Test getIsShareable() with data provider |
| 54 | + * |
| 55 | + * @param int $linkShareable |
| 56 | + * @param bool $config |
| 57 | + * @param bool $expectedResult |
| 58 | + * @dataProvider getIsShareableDataProvider |
| 59 | + */ |
| 60 | + public function testGetIsShareable($linkShareable, $config, $expectedResult) |
| 61 | + { |
| 62 | + $this->scopeConfigMock->method('isSetFlag') |
| 63 | + ->with(Link::XML_PATH_CONFIG_IS_SHAREABLE, ScopeInterface::SCOPE_STORE) |
| 64 | + ->willReturn($config); |
| 65 | + |
| 66 | + $linkMock = $this->createMock(Link::class); |
| 67 | + $linkMock->method('getIsShareable')->willReturn($linkShareable); |
| 68 | + |
| 69 | + $this->assertEquals($expectedResult, $this->helper->getIsShareable($linkMock)); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Data provider for getIsShareable() |
| 74 | + * |
| 75 | + * @return array |
| 76 | + */ |
| 77 | + public function getIsShareableDataProvider() |
| 78 | + { |
| 79 | + return [ |
| 80 | + 'link shareable yes' => [Link::LINK_SHAREABLE_YES, true, true], |
| 81 | + 'link shareable no' => [Link::LINK_SHAREABLE_NO, true, false], |
| 82 | + 'link shareable config true' => [Link::LINK_SHAREABLE_CONFIG, true, true], |
| 83 | + 'link shareable config false' => [Link::LINK_SHAREABLE_CONFIG, false, false], |
| 84 | + ]; |
| 85 | + } |
| 86 | +} |
0 commit comments