13 class DataTest extends \PHPUnit\Framework\TestCase
35 protected function setUp()
37 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38 $className = \Magento\Captcha\Helper\Data::class;
42 $this->configMock = $context->getScopeConfig();
56 $this->configMock->expects(
61 'customer/captcha/type' 63 $this->returnValue(
'zend')
66 $this->factoryMock->expects(
71 $this->equalTo(
'Zend')
74 new \
Magento\Captcha\Model\DefaultModel(
75 $this->createMock(\
Magento\Framework\Session\SessionManager::class),
76 $this->createMock(\
Magento\Captcha\Helper\Data::class),
83 $this->assertInstanceOf(\
Magento\Captcha\Model\DefaultModel::class, $this->helper->getCaptcha(
'user_create'));
91 $this->configMock->expects(
96 'customer/captcha/enable',
97 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
99 $this->returnValue(
'1')
102 $this->helper->getConfig(
'enable');
107 $fontPath =
'path/to/fixture.ttf';
108 $expectedFontPath =
'lib/' . $fontPath;
110 $libDirMock = $this->createMock(\
Magento\Framework\Filesystem\Directory\Read::class);
111 $libDirMock->expects($this->once())
112 ->method(
'getAbsolutePath')
114 ->will($this->returnValue($expectedFontPath));
115 $this->_filesystem->expects($this->once())
116 ->method(
'getDirectoryRead')
118 ->will($this->returnValue($libDirMock));
120 $configData = [
'font_code' => [
'label' =>
'Label',
'path' => $fontPath]];
122 $this->configMock->expects(
133 $fonts = $this->helper->getFonts();
134 $this->assertArrayHasKey(
'font_code', $fonts);
136 $this->assertArrayHasKey(
'label', $fonts[
'font_code']);
137 $this->assertArrayHasKey(
'path', $fonts[
'font_code']);
138 $this->assertEquals(
'Label', $fonts[
'font_code'][
'label']);
139 $this->assertEquals($expectedFontPath, $fonts[
'font_code'][
'path']);
148 $dirWriteMock = $this->createPartialMock(
149 \
Magento\Framework\Filesystem\Directory\Write::class,
150 [
'changePermissions',
'create',
'getAbsolutePath']
153 $this->_filesystem->expects(
160 $this->returnValue($dirWriteMock)
163 $dirWriteMock->expects(
170 $this->returnValue(TESTS_TEMP_DIR .
'/captcha/base')
173 $this->assertFileNotExists(TESTS_TEMP_DIR .
'/captcha');
174 $result = $this->helper->getImgDir();
175 $this->assertStringStartsWith(TESTS_TEMP_DIR,
$result);
176 $this->assertStringEndsWith(
'captcha/base/',
$result);
185 $this->assertEquals($this->helper->getImgUrl(),
'http://localhost/pub/media/captcha/base/');
195 $website = $this->createPartialMock(\
Magento\Store\Model\Website::class, [
'getCode',
'__wakeup']);
197 $website->expects($this->any())->method(
'getCode')->will($this->returnValue(
'base'));
209 $store = $this->createMock(\
Magento\Store\Model\Store::class);
211 $store->expects($this->any())->method(
'getBaseUrl')->will($this->returnValue(
'http://localhost/pub/media/'));