Example #1
0
 /**
  * Get options for font selection field
  *
  * @return array
  */
 public function toOptionArray()
 {
     $optionArray = array();
     foreach ($this->_captchaData->getFonts() as $fontName => $fontData) {
         $optionArray[] = array('label' => $fontData['label'], 'value' => $fontName);
     }
     return $optionArray;
 }
Example #2
0
 public function testGetFonts()
 {
     $fontPath = 'path/to/fixture.ttf';
     $expectedFontPath = 'lib/' . $fontPath;
     $libDirMock = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false);
     $libDirMock->expects($this->once())->method('getAbsolutePath')->with($fontPath)->will($this->returnValue($expectedFontPath));
     $this->_filesystem->expects($this->once())->method('getDirectoryRead')->with(DirectoryList::LIB_INTERNAL)->will($this->returnValue($libDirMock));
     $configData = ['font_code' => ['label' => 'Label', 'path' => $fontPath]];
     $this->configMock->expects($this->any())->method('getValue')->with('captcha/fonts', 'default')->will($this->returnValue($configData));
     $fonts = $this->helper->getFonts();
     $this->assertArrayHasKey('font_code', $fonts);
     // fixture
     $this->assertArrayHasKey('label', $fonts['font_code']);
     $this->assertArrayHasKey('path', $fonts['font_code']);
     $this->assertEquals('Label', $fonts['font_code']['label']);
     $this->assertEquals($expectedFontPath, $fonts['font_code']['path']);
 }
 /**
  * Get font to use when generating captcha
  *
  * @return string
  */
 public function getFont()
 {
     $font = (string) $this->_captchaData->getConfig('font');
     $fonts = $this->_captchaData->getFonts();
     if (isset($fonts[$font])) {
         $fontPath = $fonts[$font]['path'];
     } else {
         $fontData = array_shift($fonts);
         $fontPath = $fontData['path'];
     }
     return $fontPath;
 }