Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Evron committed Jul 25, 2010
7 parents 9dcf3a1 + 5d7867c + 1f8bc83 + c5ab2f3 + 7a52da4 + bb2812c + f7972b4 commit aefc063
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function generate();
* @param mixed $element
* @return string
*/
public function render(\Zend_View_Interface $view = null, $element = null);
public function render(\Zend\View\ViewEngine $view = null, $element = null);

/**
* Set captcha name
Expand Down
2 changes: 1 addition & 1 deletion src/Dumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Dumb extends Word
* @param mixed $element
* @return string
*/
public function render(\Zend_View_Interface $view = null, $element = null)
public function render(\Zend\View\ViewEngine $view = null, $element = null)
{
return 'Please type this word backwards: <b>'
. strrev($this->getWord())
Expand Down
2 changes: 1 addition & 1 deletion src/Figlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function generate()
* @param mixed $element
* @return string
*/
public function render(\Zend_View_Interface $view = null, $element = null)
public function render(\Zend\View\ViewEngine $view = null, $element = null)
{
return '<pre>'
. $this->_figlet->render($this->getWord())
Expand Down
11 changes: 8 additions & 3 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,14 @@ protected function _gc()
// safety guard
return;
}
$suffixLength = strlen($this->_suffix);
foreach (new \DirectoryIterator($imgdir) as $file) {
if (!$file->isDot() && !$file->isDir()) {
if ($file->getMTime() < $expire) {
unlink($file->getPathname());
// only deletes files ending with $this->_suffix
if (substr($file->getFilename(), -($suffixLength)) == $this->_suffix) {
unlink($file->getPathname());
}
}
}
}
Expand All @@ -592,8 +596,9 @@ protected function _gc()
* @param mixed $element
* @return string
*/
public function render(\Zend_View_Interface $view = null, $element = null)
public function render(\Zend\View\ViewEngine $view = null, $element = null)
{
return '<img width="'.$this->getWidth().'" height="'.$this->getHeight().'" alt="'.$this->getImgAlt().'" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '"/><br/>';
return '<img width="' . $this->getWidth() . '" height="' . $this->getHeight() . '" alt="' . $this->getImgAlt()
. '" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '" />';
}
}
2 changes: 1 addition & 1 deletion src/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function isValid($value, $context = null)
* @param mixed $element
* @return string
*/
public function render(\Zend_View_Interface $view = null, $element = null)
public function render(\Zend\View\ViewEngine $view = null, $element = null)
{
return $this->getService()->getHTML();
}
Expand Down
26 changes: 24 additions & 2 deletions src/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ abstract class Word extends AbstractAdapter
*
* @return string
*/
public function getSessionClass()
public function getSessionClass()
{
return $this->_sessionClass;
}
Expand Down Expand Up @@ -234,6 +234,28 @@ public function setKeepSession($keepSession)
}

/**
* Numbers should be included in the pattern?
*
* @return bool
*/
public function getUseNumbers()
{
return $this->_useNumbers;
}

/**
* Set if numbers should be included in the pattern
*
* @param $_useNumbers numbers should be included in the pattern?
* @return Zend_Captcha_Word
*/
public function setUseNumbers($_useNumbers)
{
$this->_useNumbers = $_useNumbers;
return $this;
}

/**
* Get session object
*
* @return \Zend\Session\Container
Expand Down Expand Up @@ -394,6 +416,6 @@ public function isValid($value, $context = null)
*/
public function getDecorator()
{
return "Captcha_Word";
return "Captcha\Word";
}
}
4 changes: 2 additions & 2 deletions test/DumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function setUp()
unset($this->word);
}

$this->element = new \Zend_Form_Element_Captcha(
$this->element = new \Zend\Form\Element\Captcha(
'captchaD',
array(
'captcha' => array(
Expand All @@ -63,7 +63,7 @@ public function testRendersWordInReverse()
{
$id = $this->captcha->generate('test');
$word = $this->captcha->getWord();
$html = $this->captcha->render(new \Zend_View);
$html = $this->captcha->render(new \Zend\View\View);
$this->assertContains(strrev($word), $html);
$this->assertNotContains($word, $html);
}
Expand Down
9 changes: 5 additions & 4 deletions test/FigletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @namespace
*/
namespace ZendTest\Captcha;
use Zend\View\View;

/**
* @category Zend
Expand All @@ -47,7 +48,7 @@ public function setUp()
unset($this->word);
}

$this->element = new \Zend_Form_Element_Captcha(
$this->element = new \Zend\Form\Element\Captcha(
'captchaF',
array(
'captcha' => array(
Expand All @@ -66,7 +67,7 @@ public function testCaptchaAdapterCreated()

public function getView()
{
$view = new \Zend_View();
$view = new View();
$view->addHelperPath(__DIR__ . '/../../../../library/Zend/View/Helper');
return $view;
}
Expand All @@ -92,7 +93,7 @@ public function testCaptchaHasIdAndInput()
*/
public function testLabelIdIsCorrect()
{
$form = new \Zend_Form();
$form = new \Zend\Form\Form();
$form->setElementsBelongTo('comment');
$this->element->setLabel("My Captcha");
$form->addElement($this->element);
Expand Down Expand Up @@ -208,7 +209,7 @@ public function testWrongWordNotValid()

public function testUsesWordCaptchaDecoratorByDefault()
{
$this->assertEquals('Captcha_Word', $this->element->getCaptcha()->getDecorator());
$this->assertEquals('Captcha\\Word', $this->element->getCaptcha()->getDecorator());
}

public function testCaptchaShouldBeConfigurableViaConfigObject()
Expand Down
28 changes: 25 additions & 3 deletions test/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @namespace
*/
namespace ZendTest\Captcha;
use Zend\View\View;

/**
* @category Zend
Expand Down Expand Up @@ -63,11 +64,11 @@ public function setUp()
if(!is_dir($this->testDir)) {
@mkdir($this->testDir);
}
$this->element = new \Zend_Form_Element_Captcha('captchaI',
$this->element = new \Zend\Form\Element\Captcha('captchaI',
array('captcha' => array('Image',
'sessionClass' => 'ZendTest\\Captcha\\TestAsset\\SessionContainer',
'imgDir' => $this->testDir,
'font' => __DIR__. '/../PDF/_fonts/Vera.ttf')
'font' => __DIR__. '/../Pdf/_fonts/Vera.ttf')
));
$this->captcha = $this->element->getCaptcha();
}
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function _getTmpDir()

public function getView()
{
$view = new \Zend_View();
$view = new View;
$view->addHelperPath(__DIR__ . '/../../../../library/Zend/View/Helper');
return $view;
}
Expand Down Expand Up @@ -180,6 +181,27 @@ public function testCaptchaImageCleanup()
$this->assertFalse(file_exists($filename), "File $filename was found even after GC");
}

/**
* @group ZF-10006
*/
public function testCaptchaImageCleanupOnlyCaptchaFilesIdentifiedByTheirSuffix()
{
$this->element->render($this->getView());
$filename = $this->testDir."/".$this->captcha->getId().".png";
$this->assertTrue(file_exists($filename));
//Create other cache file
$otherFile = $this->testDir . "/zf10006.cache";
file_put_contents($otherFile, '');
$this->assertTrue(file_exists($otherFile));
$this->captcha->setExpiration(1);
$this->captcha->setGcFreq(1);
sleep(2);
$this->captcha->generate();
clearstatcache();
$this->assertFalse(file_exists($filename), "File $filename was found even after GC");
$this->assertTrue(file_exists($otherFile), "File $otherFile was not found after GC");
}

public function testGenerateReturnsId()
{
$id = $this->captcha->generate();
Expand Down
2 changes: 1 addition & 1 deletion test/ReCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function setUp()
unset($this->word);
}

$this->element = new \Zend_Form_Element_Captcha(
$this->element = new \Zend\Form\Element\Captcha(
'captchaR',
array(
'captcha' => array(
Expand Down

0 comments on commit aefc063

Please sign in to comment.