Source of file HoneypotFieldTest.php
Size: 1,997 Bytes - Last Modified: 2017-05-11T07:25:30+00:00
/var/www/docs.ssmods.com/process/src/tests/HoneypotFieldTest.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 | <?php namespace StudioBonito\SilverStripe\SpamProtection\Honeypot\Tests; use Mockery as m; use StudioBonito\SilverStripe\SpamProtection\Honeypot\FormField\HoneypotField; class HoneypotFieldTest extends \PHPUnit_Framework_TestCase { public function tearDown() { m::close(); } /** * @covers StudioBonito\SilverStripe\SpamProtection\Honeypot\FormField\HoneypotField::validate */ public function testInvalidWithCaptcha() { $form = $this->getForm(); $validator = $this->getValidator(); $honeypotField = new HoneypotField('Captcha'); $honeypotField->setForm($form); $honeypotField->setValue('foobar'); $valid = $honeypotField->validate($validator); $this->assertFalse($valid); } /** * @covers StudioBonito\SilverStripe\SpamProtection\Honeypot\FormField\HoneypotField::validate */ public function testValidWithEmptyCaptcha() { $form = $this->getForm(); $validator = $this->getValidator(); $honeypotField = new HoneypotField('Captcha'); $honeypotField->setForm($form); $honeypotField->setValue(null); $valid = $honeypotField->validate($validator); $this->assertTrue($valid); } /** * @return m\MockInterface */ protected function getForm() { $request = m::mock('Request'); $request->shouldReceive('postVar') ->andReturn(time() + 10); $controller = m::mock('Controller'); $controller->shouldReceive('getRequest') ->andReturn($request); $form = m::mock('Form'); $form->shouldReceive('getController') ->andReturn($controller); return $form; } /** * @return m\MockInterface */ protected function getValidator() { $validator = m::mock('RequiredFields') ->shouldReceive('validationError') ->getMock(); return $validator; } } |