Completed
Push — master ( 049972...6be9b1 )
by
unknown
13s
created
tests/AkismetTest.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $this->assertEquals('person', $saved->Name);
63 63
         $this->assertEquals('[email protected]', $saved->Email);
64 64
         $this->assertEquals('what a nice comment', $saved->Content);
65
-        $this->assertEquals(false, (bool)$saved->IsSpam);
65
+        $this->assertEquals(false, (bool) $saved->IsSpam);
66 66
         $saved->delete();
67 67
 
68 68
         // Test failed setting
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $this->assertEquals('person', $saved->Name);
101 101
         $this->assertEquals('[email protected]', $saved->Email);
102 102
         $this->assertEquals('what a nice comment', $saved->Content);
103
-        $this->assertEquals(false, (bool)$saved->IsSpam);
103
+        $this->assertEquals(false, (bool) $saved->IsSpam);
104 104
         $saved->delete();
105 105
 
106 106
         $this->markTestIncomplete('@todo fix form validation message in AkismetField');
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         $this->assertEquals('spam', $saved->Name);
124 124
         $this->assertEquals('[email protected]', $saved->Email);
125 125
         $this->assertEquals('spam', $saved->Content);
126
-        $this->assertEquals(true, (bool)$saved->IsSpam);
126
+        $this->assertEquals(true, (bool) $saved->IsSpam);
127 127
     }
128 128
 
129 129
     /**
Please login to merge, or discard this patch.
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -13,131 +13,131 @@
 block discarded – undo
13 13
 
14 14
 class AkismetTest extends FunctionalTest
15 15
 {
16
-    protected static $extra_dataobjects = [AkismetTestSubmission::class];
17
-
18
-    protected $usesDatabase = true;
19
-
20
-    protected static $required_extensions = [
21
-        SiteConfig::class => [
22
-            AkismetConfig::class,
23
-        ],
24
-    ];
25
-
26
-    protected static $extra_controllers = [
27
-        AkismetTestController::class,
28
-    ];
29
-
30
-    protected function setUp()
31
-    {
32
-        parent::setUp();
33
-        Injector::inst()->unregisterObjects(AkismetService::class);
34
-
35
-        // Mock service
36
-        Config::modify()->set(Injector::class, AkismetService::class, AkismetTestService::class);
37
-        Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'dummykey');
38
-
39
-        // Reset options to reasonable default
40
-        Config::modify()->remove(AkismetSpamProtector::class, 'save_spam');
41
-        Config::modify()->remove(AkismetSpamProtector::class, 'require_confirmation');
42
-        Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members');
43
-        Config::modify()->set(AkismetSpamProtector::class, 'bypass_permission', 'ADMIN');
44
-    }
45
-
46
-    public function testSpamDetectionForm()
47
-    {
16
+	protected static $extra_dataobjects = [AkismetTestSubmission::class];
17
+
18
+	protected $usesDatabase = true;
19
+
20
+	protected static $required_extensions = [
21
+		SiteConfig::class => [
22
+			AkismetConfig::class,
23
+		],
24
+	];
25
+
26
+	protected static $extra_controllers = [
27
+		AkismetTestController::class,
28
+	];
29
+
30
+	protected function setUp()
31
+	{
32
+		parent::setUp();
33
+		Injector::inst()->unregisterObjects(AkismetService::class);
34
+
35
+		// Mock service
36
+		Config::modify()->set(Injector::class, AkismetService::class, AkismetTestService::class);
37
+		Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'dummykey');
38
+
39
+		// Reset options to reasonable default
40
+		Config::modify()->remove(AkismetSpamProtector::class, 'save_spam');
41
+		Config::modify()->remove(AkismetSpamProtector::class, 'require_confirmation');
42
+		Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members');
43
+		Config::modify()->set(AkismetSpamProtector::class, 'bypass_permission', 'ADMIN');
44
+	}
45
+
46
+	public function testSpamDetectionForm()
47
+	{
48 48
         
49
-        // Test "nice" setting
50
-        $result = $this->post('AkismetTestController/Form', array(
51
-            'Name' => 'person',
52
-            'Email' => '[email protected]',
53
-            'Content' => 'what a nice comment',
54
-            'action_doSubmit' => 'Submit',
55
-        ));
56
-
57
-        $this->assertContains('Thanks for your submission, person', $result->getBody());
58
-        $saved = AkismetTestSubmission::get()->last();
59
-        $this->assertNotEmpty($saved);
60
-        $this->assertEquals('person', $saved->Name);
61
-        $this->assertEquals('[email protected]', $saved->Email);
62
-        $this->assertEquals('what a nice comment', $saved->Content);
63
-        $this->assertEquals(false, (bool)$saved->IsSpam);
64
-        $saved->delete();
65
-
66
-        // Test failed setting
67
-        $result = $this->post('AkismetTestController/Form', array(
68
-            'Name' => 'spam',
69
-            'Email' => '[email protected]',
70
-            'Content' => 'spam',
71
-            'action_doSubmit' => 'Submit',
72
-        ));
73
-
74
-        $errorMessage = _t(
75
-            'SilverStripe\\Akismet\\AkismetField.SPAM',
76
-            "Your submission has been rejected because it was treated as spam."
77
-        );
78
-        $this->assertContains($errorMessage, $result->getBody());
79
-        $saved = AkismetTestSubmission::get()->last();
80
-        $this->assertEmpty($saved);
81
-    }
82
-
83
-    public function testSaveSpam()
84
-    {
85
-        Config::modify()->set(AkismetSpamProtector::class, 'save_spam', true);
86
-
87
-        // Test "nice" setting
88
-        $result = $this->post('AkismetTestController/Form', array(
89
-            'Name' => 'person',
90
-            'Email' => '[email protected]',
91
-            'Content' => 'what a nice comment',
92
-            'action_doSubmit' => 'Submit',
93
-        ));
94
-
95
-        $this->assertContains('Thanks for your submission, person', $result->getBody());
96
-        $saved = AkismetTestSubmission::get()->last();
97
-        $this->assertNotEmpty($saved);
98
-        $this->assertEquals('person', $saved->Name);
99
-        $this->assertEquals('[email protected]', $saved->Email);
100
-        $this->assertEquals('what a nice comment', $saved->Content);
101
-        $this->assertEquals(false, (bool)$saved->IsSpam);
102
-        $saved->delete();
103
-
104
-        $this->markTestIncomplete('@todo fix form validation message in AkismetField');
105
-
106
-        // Test failed setting
107
-        $result = $this->post('AkismetTestController/Form', array(
108
-            'Name' => 'spam',
109
-            'Email' => '[email protected]',
110
-            'Content' => 'spam',
111
-            'action_doSubmit' => 'Submit',
112
-        ));
113
-
114
-        $errorMessage = _t(
115
-            'SilverStripe\\Akismet\\AkismetField.SPAM',
116
-            "Your submission has been rejected because it was treated as spam."
117
-        );
118
-        $this->assertContains($errorMessage, $result->getBody());
119
-        $saved = AkismetTestSubmission::get()->last();
120
-        $this->assertNotEmpty($saved);
121
-        $this->assertEquals('spam', $saved->Name);
122
-        $this->assertEquals('[email protected]', $saved->Email);
123
-        $this->assertEquals('spam', $saved->Content);
124
-        $this->assertEquals(true, (bool)$saved->IsSpam);
125
-    }
126
-
127
-    /**
128
-     * Test that the request processor can safely activate when able (and only then)
129
-     */
130
-    public function testProcessor()
131
-    {
132
-        $siteconfig = SiteConfig::current_site_config();
133
-        $siteconfig->write();
134
-
135
-        // Test assignment via request filter
136
-        $processor = new AkismetTestTestMiddleware();
137
-        $this->assertTrue($processor->publicIsDBReady());
138
-
139
-        // Remove AkismetKey field
140
-        DB::query('ALTER TABLE "SiteConfig" DROP COLUMN "AkismetKey"');
141
-        $this->assertFalse($processor->publicIsDBReady());
142
-    }
49
+		// Test "nice" setting
50
+		$result = $this->post('AkismetTestController/Form', array(
51
+			'Name' => 'person',
52
+			'Email' => '[email protected]',
53
+			'Content' => 'what a nice comment',
54
+			'action_doSubmit' => 'Submit',
55
+		));
56
+
57
+		$this->assertContains('Thanks for your submission, person', $result->getBody());
58
+		$saved = AkismetTestSubmission::get()->last();
59
+		$this->assertNotEmpty($saved);
60
+		$this->assertEquals('person', $saved->Name);
61
+		$this->assertEquals('[email protected]', $saved->Email);
62
+		$this->assertEquals('what a nice comment', $saved->Content);
63
+		$this->assertEquals(false, (bool)$saved->IsSpam);
64
+		$saved->delete();
65
+
66
+		// Test failed setting
67
+		$result = $this->post('AkismetTestController/Form', array(
68
+			'Name' => 'spam',
69
+			'Email' => '[email protected]',
70
+			'Content' => 'spam',
71
+			'action_doSubmit' => 'Submit',
72
+		));
73
+
74
+		$errorMessage = _t(
75
+			'SilverStripe\\Akismet\\AkismetField.SPAM',
76
+			"Your submission has been rejected because it was treated as spam."
77
+		);
78
+		$this->assertContains($errorMessage, $result->getBody());
79
+		$saved = AkismetTestSubmission::get()->last();
80
+		$this->assertEmpty($saved);
81
+	}
82
+
83
+	public function testSaveSpam()
84
+	{
85
+		Config::modify()->set(AkismetSpamProtector::class, 'save_spam', true);
86
+
87
+		// Test "nice" setting
88
+		$result = $this->post('AkismetTestController/Form', array(
89
+			'Name' => 'person',
90
+			'Email' => '[email protected]',
91
+			'Content' => 'what a nice comment',
92
+			'action_doSubmit' => 'Submit',
93
+		));
94
+
95
+		$this->assertContains('Thanks for your submission, person', $result->getBody());
96
+		$saved = AkismetTestSubmission::get()->last();
97
+		$this->assertNotEmpty($saved);
98
+		$this->assertEquals('person', $saved->Name);
99
+		$this->assertEquals('[email protected]', $saved->Email);
100
+		$this->assertEquals('what a nice comment', $saved->Content);
101
+		$this->assertEquals(false, (bool)$saved->IsSpam);
102
+		$saved->delete();
103
+
104
+		$this->markTestIncomplete('@todo fix form validation message in AkismetField');
105
+
106
+		// Test failed setting
107
+		$result = $this->post('AkismetTestController/Form', array(
108
+			'Name' => 'spam',
109
+			'Email' => '[email protected]',
110
+			'Content' => 'spam',
111
+			'action_doSubmit' => 'Submit',
112
+		));
113
+
114
+		$errorMessage = _t(
115
+			'SilverStripe\\Akismet\\AkismetField.SPAM',
116
+			"Your submission has been rejected because it was treated as spam."
117
+		);
118
+		$this->assertContains($errorMessage, $result->getBody());
119
+		$saved = AkismetTestSubmission::get()->last();
120
+		$this->assertNotEmpty($saved);
121
+		$this->assertEquals('spam', $saved->Name);
122
+		$this->assertEquals('[email protected]', $saved->Email);
123
+		$this->assertEquals('spam', $saved->Content);
124
+		$this->assertEquals(true, (bool)$saved->IsSpam);
125
+	}
126
+
127
+	/**
128
+	 * Test that the request processor can safely activate when able (and only then)
129
+	 */
130
+	public function testProcessor()
131
+	{
132
+		$siteconfig = SiteConfig::current_site_config();
133
+		$siteconfig->write();
134
+
135
+		// Test assignment via request filter
136
+		$processor = new AkismetTestTestMiddleware();
137
+		$this->assertTrue($processor->publicIsDBReady());
138
+
139
+		// Remove AkismetKey field
140
+		DB::query('ALTER TABLE "SiteConfig" DROP COLUMN "AkismetKey"');
141
+		$this->assertFalse($processor->publicIsDBReady());
142
+	}
143 143
 }
Please login to merge, or discard this patch.
tests/AkismetTestSubmission.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@
 block discarded – undo
7 7
 
8 8
 class AkismetTestSubmission extends DataObject implements TestOnly
9 9
 {
10
-    private static $db = array(
11
-        'Name' => 'Varchar',
12
-        'Email' => 'Varchar',
13
-        'Content' => 'Text',
14
-        'IsSpam' => 'Boolean',
15
-    );
10
+	private static $db = array(
11
+		'Name' => 'Varchar',
12
+		'Email' => 'Varchar',
13
+		'Content' => 'Text',
14
+		'IsSpam' => 'Boolean',
15
+	);
16 16
 
17
-    private static $default_sort = 'ID';
17
+	private static $default_sort = 'ID';
18 18
 }
Please login to merge, or discard this patch.
tests/AkismetTestTestMiddleware.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
 
8 8
 class AkismetTestTestMiddleware extends AkismetMiddleware implements TestOnly
9 9
 {
10
-    public function publicIsDBReady()
11
-    {
12
-        return $this->isDBReady();
13
-    }
10
+	public function publicIsDBReady()
11
+	{
12
+		return $this->isDBReady();
13
+	}
14 14
 }
Please login to merge, or discard this patch.
tests/AkismetTestController.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@
 block discarded – undo
19 19
  */
20 20
 class AkismetTestController extends Controller implements TestOnly
21 21
 {
22
-    private static $allowed_actions = array(
23
-        'Form'
24
-    );
22
+	private static $allowed_actions = array(
23
+		'Form'
24
+	);
25 25
 
26
-    public function Form()
27
-    {
28
-        $fields = new FieldList(
29
-            new TextField('Name'),
30
-            new EmailField('Email'),
31
-            new TextareaField('Content')
32
-        );
33
-        $actions = new FieldList(new FormAction('doSubmit', 'Submit'));
34
-        $validator = new RequiredFields('Name', 'Content');
35
-        $form = new Form($this, 'Form', $fields, $actions, $validator);
26
+	public function Form()
27
+	{
28
+		$fields = new FieldList(
29
+			new TextField('Name'),
30
+			new EmailField('Email'),
31
+			new TextareaField('Content')
32
+		);
33
+		$actions = new FieldList(new FormAction('doSubmit', 'Submit'));
34
+		$validator = new RequiredFields('Name', 'Content');
35
+		$form = new Form($this, 'Form', $fields, $actions, $validator);
36 36
 
37
-        $form->enableSpamProtection(array(
38
-            'protector' => AkismetSpamProtector::class,
39
-            'name' => 'IsSpam',
40
-            'mapping' => array(
41
-                'Content' => 'body',
42
-                'Name' => 'authorName',
43
-                'Email' => 'authorMail',
44
-            )
45
-        ));
37
+		$form->enableSpamProtection(array(
38
+			'protector' => AkismetSpamProtector::class,
39
+			'name' => 'IsSpam',
40
+			'mapping' => array(
41
+				'Content' => 'body',
42
+				'Name' => 'authorName',
43
+				'Email' => 'authorMail',
44
+			)
45
+		));
46 46
 
47
-        // Because we don't want to be testing this
48
-        $form->disableSecurityToken();
49
-        return $form;
50
-    }
47
+		// Because we don't want to be testing this
48
+		$form->disableSecurityToken();
49
+		return $form;
50
+	}
51 51
 
52
-    public function doSubmit($data, Form $form)
53
-    {
54
-        $item = new AkismetTestSubmission();
55
-        $form->saveInto($item);
56
-        $item->write();
57
-        $form->sessionMessage('Thanks for your submission, ' . $data['Name'], 'good');
58
-        return $this->redirect($this->Link());
59
-    }
52
+	public function doSubmit($data, Form $form)
53
+	{
54
+		$item = new AkismetTestSubmission();
55
+		$form->saveInto($item);
56
+		$item->write();
57
+		$form->sessionMessage('Thanks for your submission, ' . $data['Name'], 'good');
58
+		return $this->redirect($this->Link());
59
+	}
60 60
 
61
-    public function Link($action = null)
62
-    {
63
-        return 'AkismetTestController';
64
-    }
61
+	public function Link($action = null)
62
+	{
63
+		return 'AkismetTestController';
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
         $item = new AkismetTestSubmission();
55 55
         $form->saveInto($item);
56 56
         $item->write();
57
-        $form->sessionMessage('Thanks for your submission, ' . $data['Name'], 'good');
57
+        $form->sessionMessage('Thanks for your submission, '.$data['Name'], 'good');
58 58
         return $this->redirect($this->Link());
59 59
     }
60 60
 
Please login to merge, or discard this patch.
tests/AkismetTestService.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
 
9 9
 class AkismetTestService implements TestOnly, AkismetService
10 10
 {
11
-    public function __construct($apiKey, $url)
12
-    {
13
-        if ($apiKey !== 'dummykey') {
14
-            throw new Exception("Invalid key");
15
-        }
16
-    }
11
+	public function __construct($apiKey, $url)
12
+	{
13
+		if ($apiKey !== 'dummykey') {
14
+			throw new Exception("Invalid key");
15
+		}
16
+	}
17 17
     
18
-    public function isSpam($content, $author = null, $email = null, $url = null, $permalink = null, $type = null)
19
-    {
20
-        // This dummy service only checks the content
21
-        return $content === 'spam';
22
-    }
18
+	public function isSpam($content, $author = null, $email = null, $url = null, $permalink = null, $type = null)
19
+	{
20
+		// This dummy service only checks the content
21
+		return $content === 'spam';
22
+	}
23 23
 }
Please login to merge, or discard this patch.
tests/AkismetSpamProtectorTest.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@
 block discarded – undo
9 9
 
10 10
 class AkismetSpamProtectorTest extends SapphireTest
11 11
 {
12
-    public function testGetApiKeyPriority()
13
-    {
14
-        $spamProtector = AkismetSpamProtector::singleton();
12
+	public function testGetApiKeyPriority()
13
+	{
14
+		$spamProtector = AkismetSpamProtector::singleton();
15 15
 
16
-        // Clear all possible values from the environment
17
-        Config::modify()->set(AkismetSpamProtector::class, 'api_key', '');
18
-        Environment::setEnv('SS_AKISMET_API_KEY', '');
19
-        $this->assertSame('', $spamProtector->getApiKey(), 'Blank string returned by default');
16
+		// Clear all possible values from the environment
17
+		Config::modify()->set(AkismetSpamProtector::class, 'api_key', '');
18
+		Environment::setEnv('SS_AKISMET_API_KEY', '');
19
+		$this->assertSame('', $spamProtector->getApiKey(), 'Blank string returned by default');
20 20
 
21
-        // Set some values in all possible places
22
-        $spamProtector->setApiKey('instance_api_key');
23
-        Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'config_api_key');
24
-        Environment::setEnv('SS_AKISMET_API_KEY', 'env_api_key');
21
+		// Set some values in all possible places
22
+		$spamProtector->setApiKey('instance_api_key');
23
+		Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'config_api_key');
24
+		Environment::setEnv('SS_AKISMET_API_KEY', 'env_api_key');
25 25
 
26
-        $this->assertSame('instance_api_key', $spamProtector->getApiKey(), 'Instance value is given priority');
26
+		$this->assertSame('instance_api_key', $spamProtector->getApiKey(), 'Instance value is given priority');
27 27
 
28
-        $spamProtector->setApiKey('');
29
-        $this->assertSame('config_api_key', $spamProtector->getApiKey(), 'Config value is second priority');
28
+		$spamProtector->setApiKey('');
29
+		$this->assertSame('config_api_key', $spamProtector->getApiKey(), 'Config value is second priority');
30 30
 
31
-        Config::modify()->set(AkismetSpamProtector::class, 'api_key', '');
32
-        $this->assertSame('env_api_key', $spamProtector->getApiKey(), 'Environment value is last priority');
33
-    }
31
+		Config::modify()->set(AkismetSpamProtector::class, 'api_key', '');
32
+		$this->assertSame('env_api_key', $spamProtector->getApiKey(), 'Environment value is last priority');
33
+	}
34 34
 }
Please login to merge, or discard this patch.