Skip to content

Commit e7963fa

Browse files
authored
Fix. Integration. EDD integration fixed. (#770)
* Fix. Integration. EDD integration fixed. * Upd. Code. Unit-test for an integration added: `TestEasyDigitalDownloads`.
1 parent 15e239c commit e7963fa

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

inc/cleantalk-integrations-by-hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
'ajax' => false
136136
),
137137
'EasyDigitalDownloads' => array(
138-
'hook' => array('edd_pre_process_register_form', 'edd_insert_user_args'),
138+
'hook' => array('edd_pre_process_register_form', 'edd_insert_user_args', 'edd_customer_pre_create'),
139139
'setting' => 'forms__registrations_test',
140140
'ajax' => false
141141
),

lib/Cleantalk/Antispam/Integrations/EasyDigitalDownloads.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public function getDataForChecking($argument)
1313
$this->user_data = $argument;
1414

1515
if (
16-
Post::get('edd_action') === "user_register" ||
17-
!empty($argument['user_email'])
16+
Post::getString('edd_action') === "user_register" ||
17+
!empty($argument['user_email']) ||
18+
Post::getString('edd-process-checkout-nonce')
1819
) {
1920
/**
2021
* Filter for POST
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Cleantalk\Antispam\Integrations;
4+
5+
use Cleantalk\ApbctWP\Variables\Get;
6+
use Cleantalk\ApbctWP\Variables\Post;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class TestEasyDigitalDownloads extends TestCase
10+
{
11+
private $integration;
12+
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
$this->integration = new EasyDigitalDownloads();
17+
}
18+
19+
protected function tearDown(): void
20+
{
21+
// Clean up global state
22+
$_POST = [];
23+
$_GET = [];
24+
Post::getInstance()->variables = [];
25+
Get::getInstance()->variables = [];
26+
parent::tearDown();
27+
}
28+
29+
public function testGetDataForCheckingRegisterPage()
30+
{
31+
$_POST['edd_action'] = 'user_register';
32+
$_POST['edd_user_login'] = 'John';
33+
$_POST['edd_user_email'] = 'john.doe@example.com';
34+
35+
$result = $this->integration->getDataForChecking(null);
36+
37+
$this->assertIsArray($result);
38+
$this->assertEquals('john.doe@example.com', $result['email']);
39+
$this->assertEquals('', $result['nickname']); // NickName not detected at that integration
40+
$this->assertTrue($result['register']);
41+
}
42+
43+
public function testGetDataForCheckingRegisterDuringCheckout()
44+
{
45+
$_POST['edd-process-checkout-nonce'] = 'user_register';
46+
$_POST['edd_first'] = 'John';
47+
$_POST['edd_last'] = 'Doe';
48+
$_POST['edd_email'] = 'john.doe@example.com';
49+
50+
$result = $this->integration->getDataForChecking(null);
51+
52+
$this->assertIsArray($result);
53+
$this->assertEquals('john.doe@example.com', $result['email']);
54+
$this->assertEquals('', $result['nickname']); // NickName not detected at that integration
55+
$this->assertTrue($result['register']);
56+
}
57+
58+
public function testGetDataForCheckingRegisterCommon()
59+
{
60+
$_POST['edd_user_login'] = 'John';
61+
$_POST['edd_user_email'] = 'john.doe@example.com';
62+
63+
$result = $this->integration->getDataForChecking(['user_email' => 'any_email_no_sense']);
64+
65+
$this->assertIsArray($result);
66+
$this->assertEquals('john.doe@example.com', $result['email']);
67+
$this->assertEquals('', $result['nickname']); // NickName not detected at that integration
68+
$this->assertTrue($result['register']);
69+
}
70+
}

0 commit comments

Comments
 (0)