Passed
Pull Request — master (#23)
by
unknown
03:45
created
tests/AkismetTest.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -14,133 +14,133 @@
 block discarded – undo
14 14
 
15 15
 class AkismetTest extends FunctionalTest
16 16
 {
17
-    protected static $extra_dataobjects = [AkismetTestSubmission::class];
18
-
19
-    protected $usesDatabase = true;
20
-
21
-    protected static $required_extensions = [
22
-        SiteConfig::class => [
23
-            AkismetConfig::class,
24
-        ],
25
-    ];
26
-
27
-    protected static $extra_controllers = [
28
-        AkismetTestController::class,
29
-    ];
30
-
31
-    protected function setUp()
32
-    {
33
-        parent::setUp();
34
-        Injector::inst()->unregisterObjects(AkismetService::class);
35
-
36
-        // Mock service
37
-        Config::modify()->set(Injector::class, AkismetService::class, AkismetTestService::class);
38
-        Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'dummykey');
39
-        AkismetSpamProtector::set_api_key(null);
40
-
41
-        // Reset options to reasonable default
42
-        Config::modify()->remove(AkismetSpamProtector::class, 'save_spam');
43
-        Config::modify()->remove(AkismetSpamProtector::class, 'require_confirmation');
44
-        Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members');
45
-        Config::modify()->set(AkismetSpamProtector::class, 'bypass_permission', 'ADMIN');
46
-    }
47
-
48
-    public function testSpamDetectionForm()
49
-    {
17
+	protected static $extra_dataobjects = [AkismetTestSubmission::class];
18
+
19
+	protected $usesDatabase = true;
20
+
21
+	protected static $required_extensions = [
22
+		SiteConfig::class => [
23
+			AkismetConfig::class,
24
+		],
25
+	];
26
+
27
+	protected static $extra_controllers = [
28
+		AkismetTestController::class,
29
+	];
30
+
31
+	protected function setUp()
32
+	{
33
+		parent::setUp();
34
+		Injector::inst()->unregisterObjects(AkismetService::class);
35
+
36
+		// Mock service
37
+		Config::modify()->set(Injector::class, AkismetService::class, AkismetTestService::class);
38
+		Config::modify()->set(AkismetSpamProtector::class, 'api_key', 'dummykey');
39
+		AkismetSpamProtector::set_api_key(null);
40
+
41
+		// Reset options to reasonable default
42
+		Config::modify()->remove(AkismetSpamProtector::class, 'save_spam');
43
+		Config::modify()->remove(AkismetSpamProtector::class, 'require_confirmation');
44
+		Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members');
45
+		Config::modify()->set(AkismetSpamProtector::class, 'bypass_permission', 'ADMIN');
46
+	}
47
+
48
+	public function testSpamDetectionForm()
49
+	{
50 50
         
51
-        // Test "nice" setting
52
-        $result = $this->post('AkismetTestController/Form', array(
53
-            'Name' => 'person',
54
-            'Email' => '[email protected]',
55
-            'Content' => 'what a nice comment',
56
-            'action_doSubmit' => 'Submit',
57
-        ));
58
-
59
-        $this->assertContains('Thanks for your submission, person', $result->getBody());
60
-        $saved = AkismetTestSubmission::get()->last();
61
-        $this->assertNotEmpty($saved);
62
-        $this->assertEquals('person', $saved->Name);
63
-        $this->assertEquals('[email protected]', $saved->Email);
64
-        $this->assertEquals('what a nice comment', $saved->Content);
65
-        $this->assertEquals(false, (bool)$saved->IsSpam);
66
-        $saved->delete();
67
-
68
-        // Test failed setting
69
-        $result = $this->post('AkismetTestController/Form', array(
70
-            'Name' => 'spam',
71
-            'Email' => '[email protected]',
72
-            'Content' => 'spam',
73
-            'action_doSubmit' => 'Submit',
74
-        ));
75
-
76
-        $errorMessage = _t(
77
-            'SilverStripe\\Akismet\\AkismetField.SPAM',
78
-            "Your submission has been rejected because it was treated as spam."
79
-        );
80
-        $this->assertContains($errorMessage, $result->getBody());
81
-        $saved = AkismetTestSubmission::get()->last();
82
-        $this->assertEmpty($saved);
83
-    }
84
-
85
-    public function testSaveSpam()
86
-    {
87
-        Config::modify()->set(AkismetSpamProtector::class, 'save_spam', true);
88
-
89
-        // Test "nice" setting
90
-        $result = $this->post('AkismetTestController/Form', array(
91
-            'Name' => 'person',
92
-            'Email' => '[email protected]',
93
-            'Content' => 'what a nice comment',
94
-            'action_doSubmit' => 'Submit',
95
-        ));
96
-
97
-        $this->assertContains('Thanks for your submission, person', $result->getBody());
98
-        $saved = AkismetTestSubmission::get()->last();
99
-        $this->assertNotEmpty($saved);
100
-        $this->assertEquals('person', $saved->Name);
101
-        $this->assertEquals('[email protected]', $saved->Email);
102
-        $this->assertEquals('what a nice comment', $saved->Content);
103
-        $this->assertEquals(false, (bool)$saved->IsSpam);
104
-        $saved->delete();
105
-
106
-        $this->markTestIncomplete('@todo fix form validation message in AkismetField');
107
-
108
-        // Test failed setting
109
-        $result = $this->post('AkismetTestController/Form', array(
110
-            'Name' => 'spam',
111
-            'Email' => '[email protected]',
112
-            'Content' => 'spam',
113
-            'action_doSubmit' => 'Submit',
114
-        ));
115
-
116
-        $errorMessage = _t(
117
-            'SilverStripe\\Akismet\\AkismetField.SPAM',
118
-            "Your submission has been rejected because it was treated as spam."
119
-        );
120
-        $this->assertContains($errorMessage, $result->getBody());
121
-        $saved = AkismetTestSubmission::get()->last();
122
-        $this->assertNotEmpty($saved);
123
-        $this->assertEquals('spam', $saved->Name);
124
-        $this->assertEquals('[email protected]', $saved->Email);
125
-        $this->assertEquals('spam', $saved->Content);
126
-        $this->assertEquals(true, (bool)$saved->IsSpam);
127
-    }
128
-
129
-    /**
130
-     * Test that the request processor can safely activate when able (and only then)
131
-     */
132
-    public function testProcessor()
133
-    {
134
-        $siteconfig = SiteConfig::current_site_config();
135
-        $siteconfig->write();
136
-
137
-        // Test assignment via request filter
138
-        $processor = new AkismetTestTestMiddleware();
139
-        $this->assertTrue($processor->publicIsDBReady());
140
-
141
-        // Remove AkismetKey field
142
-        DB::query('ALTER TABLE "SiteConfig" DROP COLUMN "AkismetKey"');
143
-        $this->assertFalse($processor->publicIsDBReady());
144
-    }
51
+		// Test "nice" setting
52
+		$result = $this->post('AkismetTestController/Form', array(
53
+			'Name' => 'person',
54
+			'Email' => '[email protected]',
55
+			'Content' => 'what a nice comment',
56
+			'action_doSubmit' => 'Submit',
57
+		));
58
+
59
+		$this->assertContains('Thanks for your submission, person', $result->getBody());
60
+		$saved = AkismetTestSubmission::get()->last();
61
+		$this->assertNotEmpty($saved);
62
+		$this->assertEquals('person', $saved->Name);
63
+		$this->assertEquals('[email protected]', $saved->Email);
64
+		$this->assertEquals('what a nice comment', $saved->Content);
65
+		$this->assertEquals(false, (bool)$saved->IsSpam);
66
+		$saved->delete();
67
+
68
+		// Test failed setting
69
+		$result = $this->post('AkismetTestController/Form', array(
70
+			'Name' => 'spam',
71
+			'Email' => '[email protected]',
72
+			'Content' => 'spam',
73
+			'action_doSubmit' => 'Submit',
74
+		));
75
+
76
+		$errorMessage = _t(
77
+			'SilverStripe\\Akismet\\AkismetField.SPAM',
78
+			"Your submission has been rejected because it was treated as spam."
79
+		);
80
+		$this->assertContains($errorMessage, $result->getBody());
81
+		$saved = AkismetTestSubmission::get()->last();
82
+		$this->assertEmpty($saved);
83
+	}
84
+
85
+	public function testSaveSpam()
86
+	{
87
+		Config::modify()->set(AkismetSpamProtector::class, 'save_spam', true);
88
+
89
+		// Test "nice" setting
90
+		$result = $this->post('AkismetTestController/Form', array(
91
+			'Name' => 'person',
92
+			'Email' => '[email protected]',
93
+			'Content' => 'what a nice comment',
94
+			'action_doSubmit' => 'Submit',
95
+		));
96
+
97
+		$this->assertContains('Thanks for your submission, person', $result->getBody());
98
+		$saved = AkismetTestSubmission::get()->last();
99
+		$this->assertNotEmpty($saved);
100
+		$this->assertEquals('person', $saved->Name);
101
+		$this->assertEquals('[email protected]', $saved->Email);
102
+		$this->assertEquals('what a nice comment', $saved->Content);
103
+		$this->assertEquals(false, (bool)$saved->IsSpam);
104
+		$saved->delete();
105
+
106
+		$this->markTestIncomplete('@todo fix form validation message in AkismetField');
107
+
108
+		// Test failed setting
109
+		$result = $this->post('AkismetTestController/Form', array(
110
+			'Name' => 'spam',
111
+			'Email' => '[email protected]',
112
+			'Content' => 'spam',
113
+			'action_doSubmit' => 'Submit',
114
+		));
115
+
116
+		$errorMessage = _t(
117
+			'SilverStripe\\Akismet\\AkismetField.SPAM',
118
+			"Your submission has been rejected because it was treated as spam."
119
+		);
120
+		$this->assertContains($errorMessage, $result->getBody());
121
+		$saved = AkismetTestSubmission::get()->last();
122
+		$this->assertNotEmpty($saved);
123
+		$this->assertEquals('spam', $saved->Name);
124
+		$this->assertEquals('[email protected]', $saved->Email);
125
+		$this->assertEquals('spam', $saved->Content);
126
+		$this->assertEquals(true, (bool)$saved->IsSpam);
127
+	}
128
+
129
+	/**
130
+	 * Test that the request processor can safely activate when able (and only then)
131
+	 */
132
+	public function testProcessor()
133
+	{
134
+		$siteconfig = SiteConfig::current_site_config();
135
+		$siteconfig->write();
136
+
137
+		// Test assignment via request filter
138
+		$processor = new AkismetTestTestMiddleware();
139
+		$this->assertTrue($processor->publicIsDBReady());
140
+
141
+		// Remove AkismetKey field
142
+		DB::query('ALTER TABLE "SiteConfig" DROP COLUMN "AkismetKey"');
143
+		$this->assertFalse($processor->publicIsDBReady());
144
+	}
145 145
 }
146 146
 
Please login to merge, or discard this patch.
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.
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.