Skip to content

Commit 59ae0bc

Browse files
committed
Upd. Phones encoding. Test coverage improved.
1 parent cdba240 commit 59ae0bc

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/Cleantalk/ApbctWP/ContactsEncoder/ContactsEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static function getPhonesEncodingLongDescription()
327327
<p>%s</p>
328328
';
329329
$tmp = sprintf(
330-
$tmp,
330+
trim($tmp),
331331
__('Enable this option to encode contact phone numbers', 'cleantalk-spam-protect'),
332332
__('There are a few requirements to the number format:', 'cleantalk-spam-protect'),
333333
__('Should starting with "+" symbol or opening brace', 'cleantalk-spam-protect'),

lib/Cleantalk/Common/ContactsEncoder/ContactsEncoder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public function runEncoding($content = '')
166166
*
167167
* @return string JSON like {success: bool, data: [compiled response data]}
168168
* @psalm-suppress PossiblyUnusedMethod
169+
* @codeCoverageIgnore
169170
*/
170171
public function runDecoding($encoded_contacts_data)
171172
{

tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ public function testPlainTextEncodeDecodeSSL()
3737
$this->assertEquals($decoded_entity, $this->plain_text);
3838
}
3939

40+
public function testPlainTextDecodeError()
41+
{
42+
$decoded_entity = $this->contacts_encoder->encoder->decodeString('asdas121312');
43+
$this->assertEmpty($decoded_entity);
44+
$this->assertIsString($decoded_entity);
45+
/**
46+
* @var State $apbct
47+
*/
48+
global $apbct;
49+
$this->assertTrue($apbct->isHaveErrors());
50+
$this->assertTrue($apbct->errorExists('email_encoder'), $this->plain_text);
51+
$this->assertStringContainsString( 'decrypt attempts failed', $apbct->errors['email_encoder'][0]['error']);
52+
$apbct->errorDeleteAll();
53+
}
54+
4055
public function testEncodeErrors()
4156
{
4257
/**
@@ -228,4 +243,12 @@ public function testPhoneEncodingSetting()
228243
$this->assertEquals($test_tel_origin, $result);
229244
}
230245

246+
public function testGetPhonesEncodingLongDescription()
247+
{
248+
$description = ContactsEncoder::getPhonesEncodingLongDescription();
249+
$this->assertIsString($description);
250+
$this->assertStringStartsWith('<', $description);
251+
$this->assertStringEndsWith('>', $description);
252+
}
253+
231254
}

0 commit comments

Comments
 (0)