Move stub classes to their own files, run PSR-2 linter

This commit is contained in:
Robbie Averill 2017-07-07 14:23:01 +12:00
parent 3d771d8179
commit 5cc9312a8d
11 changed files with 99 additions and 98 deletions

View File

@ -12,7 +12,8 @@ class SpamProtectorManager
public static function set_spam_protector($protector) public static function set_spam_protector($protector)
{ {
Deprecation::notice('1.1', Deprecation::notice(
'1.1',
'SpamProtectorManager::set_spam_protector() is deprecated. '. 'SpamProtectorManager::set_spam_protector() is deprecated. '.
'Use the new config system. FormSpamProtectorExtension.default_spam_protector' 'Use the new config system. FormSpamProtectorExtension.default_spam_protector'
); );
@ -22,16 +23,19 @@ class SpamProtectorManager
public static function get_spam_protector() public static function get_spam_protector()
{ {
Deprecation::notice('1.1', Deprecation::notice(
'1.1',
'SpamProtectorManager::get_spam_protector() is deprecated'. 'SpamProtectorManager::get_spam_protector() is deprecated'.
'Use the new config system. FormSpamProtectorExtension.default_spam_protector'); 'Use the new config system. FormSpamProtectorExtension.default_spam_protector'
);
return self::$spam_protector; return self::$spam_protector;
} }
public static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null) public static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null)
{ {
Deprecation::notice('1.1', Deprecation::notice(
'1.1',
'SpamProtectorManager::update_form is deprecated'. 'SpamProtectorManager::update_form is deprecated'.
'Please use $form->enableSpamProtection() for adding spamprotection' 'Please use $form->enableSpamProtection() for adding spamprotection'
); );

View File

@ -9,18 +9,19 @@ class EditableSpamProtectionFieldTest extends SapphireTest
{ {
parent::setUp(); parent::setUp();
if (!class_exists('EditableSpamProtectionField')) {
$this->markTestSkipped('"userforms" module not installed');
}
Config::inst()->update( Config::inst()->update(
'FormSpamProtectionExtension', 'default_spam_protector', 'FormSpamProtectionExtension',
'default_spam_protector',
'EditableSpamProtectionFieldTest_Protector' 'EditableSpamProtectionFieldTest_Protector'
); );
} }
public function testValidateFieldDoesntAddErrorOnSuccess() public function testValidateFieldDoesntAddErrorOnSuccess()
{ {
if (!class_exists('EditableSpamProtectionField')) {
$this->markTestSkipped('"userforms" module not installed');
}
$formMock = $this->getFormMock(); $formMock = $this->getFormMock();
$formFieldMock = $this->getEditableFormFieldMock(); $formFieldMock = $this->getEditableFormFieldMock();
@ -39,10 +40,6 @@ class EditableSpamProtectionFieldTest extends SapphireTest
public function testValidateFieldAddsErrorFromField() public function testValidateFieldAddsErrorFromField()
{ {
if (!class_exists('EditableSpamProtectionField')) {
$this->markTestSkipped('"userforms" module not installed');
}
$formMock = $this->getFormMock(); $formMock = $this->getFormMock();
$formFieldMock = $this->getEditableFormFieldMock(); $formFieldMock = $this->getEditableFormFieldMock();
@ -57,17 +54,14 @@ class EditableSpamProtectionFieldTest extends SapphireTest
$formMock $formMock
->expects($this->once()) ->expects($this->once())
->method('addErrorMessage') ->method('addErrorMessage')
->with($this->anything(), $this->stringContains('some field message'), $this->anything(), $this->anything());; ->with($this->anything(), $this->stringContains('some field message'), $this->anything(), $this->anything());
;
$formFieldMock->validateField(array('MyField' => null), $formMock); $formFieldMock->validateField(array('MyField' => null), $formMock);
} }
public function testValidateFieldAddsDefaultError() public function testValidateFieldAddsDefaultError()
{ {
if (!class_exists('EditableSpamProtectionField')) {
$this->markTestSkipped('"userforms" module not installed');
}
$formMock = $this->getFormMock(); $formMock = $this->getFormMock();
$formFieldMock = $this->getEditableFormFieldMock(); $formFieldMock = $this->getEditableFormFieldMock();
@ -119,17 +113,4 @@ class EditableSpamProtectionFieldTest extends SapphireTest
return $editableFormFieldMock; return $editableFormFieldMock;
} }
}
class EditableSpamProtectionFieldTest_Protector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, 'Foo', $value);
}
public function setFieldMapping($fieldMapping)
{
}
} }

View File

@ -20,15 +20,15 @@ class FormSpamProtectionExtensionTest extends SapphireTest
new TextField('Title'), new TextField('Title'),
new TextField('Comment'), new TextField('Comment'),
new TextField('URL') new TextField('URL')
), new FieldList() ), new FieldList());
);
$this->form->disableSecurityToken(); $this->form->disableSecurityToken();
} }
public function testEnableSpamProtection() public function testEnableSpamProtection()
{ {
Config::inst()->update( Config::inst()->update(
'FormSpamProtectionExtension', 'default_spam_protector', 'FormSpamProtectionExtension',
'default_spam_protector',
'FormSpamProtectionExtensionTest_FooProtector' 'FormSpamProtectionExtensionTest_FooProtector'
); );
@ -96,49 +96,3 @@ class FormSpamProtectionExtensionTest extends SapphireTest
$this->assertEquals('Foo', $fields[3]->Title()); $this->assertEquals('Foo', $fields[3]->Title());
} }
} }
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_BazProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, $title, $value);
}
public function setFieldMapping($fieldMapping)
{
}
}
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_BarProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
$title = $title ?: 'Bar';
return new TextField($name, $title, $value);
}
public function setFieldMapping($fieldMapping)
{
}
}
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_FooProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, 'Foo', $value);
}
public function setFieldMapping($fieldMapping)
{
}
}

View File

@ -0,0 +1,13 @@
<?php
class EditableSpamProtectionFieldTest_Protector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, 'Foo', $value);
}
public function setFieldMapping($fieldMapping)
{
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_BarProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
$title = $title ?: 'Bar';
return new TextField($name, $title, $value);
}
public function setFieldMapping($fieldMapping)
{
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_BazProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, $title, $value);
}
public function setFieldMapping($fieldMapping)
{
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* @package spamprotection
*/
class FormSpamProtectionExtensionTest_FooProtector implements SpamProtector, TestOnly
{
public function getFormField($name = null, $title = null, $value = null)
{
return new TextField($name, 'Foo', $value);
}
public function setFieldMapping($fieldMapping)
{
}
}