Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated for CakePHP 3.6 #22

Merged
merged 8 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/crabstudio/Recaptcha.svg?branch=master)](https://travis-ci.org/crabstudio/Recaptcha) [![Latest Stable Version](https://poser.pugx.org/crabstudio/recaptcha/v/stable)](https://packagist.org/packages/crabstudio/recaptcha) [![Total Downloads](https://poser.pugx.org/crabstudio/recaptcha/downloads)](https://packagist.org/packages/crabstudio/recaptcha) [![Latest Unstable Version](https://poser.pugx.org/crabstudio/recaptcha/v/unstable)](https://packagist.org/packages/crabstudio/recaptcha) [![License](https://poser.pugx.org/crabstudio/recaptcha/license)](https://packagist.org/packages/crabstudio/recaptcha)
# Integrate Google Recaptcha v2 to your CakePHP v3.2+ project
# Integrate Google Recaptcha v2 to your CakePHP v3.6+ project

## Installation

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
},
"require": {
"php": ">=5.6",
"cakephp/cakephp": "~3.2"
"cakephp/cakephp": "~3.6"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping to 3.6 is not necessary. The updated methods exist in 3.5 too so please change this to ^3.5.

},
"require-dev": {
"phpunit/phpunit": "*",
"phpunit/phpunit": "^5.7|^6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally ^5.7.14|^6.0 is needed.

"cakephp/cakephp-codesniffer": "2.*"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update this too to ^3.0.

},
"autoload": {
Expand Down
9 changes: 4 additions & 5 deletions src/Controller/Component/RecaptchaComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
namespace Recaptcha\Controller\Component;

use Cake\Controller\Component;
use Cake\I18n\I18n;
use Cake\Network\Http\Client;
use Cake\Http\Client;

/**
* Recaptcha component
Expand Down Expand Up @@ -36,7 +35,7 @@ class RecaptchaComponent extends Component
*/
public function initialize(array $config = [])
{
$this->config($config);
$this->setConfig($config);
$this->_registry->getController()->viewBuilder()->helpers(['Recaptcha.Recaptcha' => $this->_config]);
}

Expand All @@ -51,7 +50,7 @@ public function verify()
}

$controller = $this->_registry->getController();
if (isset($controller->request->data['g-recaptcha-response'])) {
if ($controller->request->getData('g-recaptcha-response')) {
$response = json_decode($this->apiCall());

if (isset($response->success)) {
Expand All @@ -75,7 +74,7 @@ protected function apiCall()

return $client->post('https://www.google.com/recaptcha/api/siteverify', [
'secret' => $this->_config['secret'],
'response' => $controller->request->data['g-recaptcha-response'],
'response' => $controller->request->getData('g-recaptcha-response'),
'remoteip' => $controller->request->clientIp()
])->getBody();
}
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/RecaptchaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RecaptchaHelper extends Helper
*/
public function initialize(array $config = [])
{
$this->config($config);
$this->setConfig($config);
}

/**
Expand All @@ -25,7 +25,7 @@ public function initialize(array $config = [])
*/
public function display()
{
$recaptcha = $this->config();
$recaptcha = $this->getConfig();
if (!$recaptcha['enable']) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Network\Request;
use Cake\Http\ServerRequest as Request;
use Cake\TestSuite\TestCase;
use Recaptcha\Controller\Component\RecaptchaComponent;

Expand Down Expand Up @@ -37,7 +37,7 @@ public function testVerifyFalse()
{
$this->assertFalse($this->Recaptcha->verify());

$this->controller->request->data['g-recaptcha-response'] = 'foo';
$this->controller->request = $this->controller->request->withData('g-recaptcha-response', 'foo');

$this->Recaptcha->expects($this->once())
->method('apiCall')
Expand All @@ -48,15 +48,15 @@ public function testVerifyFalse()

public function testVerifyTrue()
{
$this->controller->request->data['g-recaptcha-response'] = 'foo';
$this->controller->request = $this->controller->request->withData('g-recaptcha-response', 'foo');

$this->Recaptcha->expects($this->once())
->method('apiCall')
->will($this->returnValue('{"success":true}'));

$this->assertTrue($this->Recaptcha->verify());

$this->Recaptcha->config('enable', false);
$this->Recaptcha->setConfig('enable', false);
$this->assertTrue($this->Recaptcha->verify());
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/RecaptchaHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testDisplay()
$this->assertTrue(is_string($result));
$this->assertContains('class="g-recaptcha"', $result);

$this->Recaptcha->config('enable', false);
$this->Recaptcha->setConfig('enable', false);
$this->assertEmpty($this->Recaptcha->display());
}
}