Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion templates/apbct_settings__footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function apbct_settings__footer()
)],
];
$block2_links = [
['text' => 'Security plugin by CleanTalk', 'url' => admin_url('plugin-install.php') . '?s=spbct&tab=search&type=term']
['text' => 'Security plugin by CleanTalk', 'url' => admin_url('plugin-install.php') . '?s=spbct&tab=search&type=term'],
['text' => esc_html__('Forms to CRM / Gravity Add-On'), 'url' => admin_url('plugin-install.php') . '?s=cleantalk-doboard-add-on-for-gravity-forms&tab=search&type=term'],
];

?>
Expand Down
39 changes: 39 additions & 0 deletions tests/StandaloneFunctions/TestSettingsFooterLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

require_once dirname(__DIR__, 2) . '/templates/apbct_settings__footer.php';

use PHPUnit\Framework\TestCase;

class TestSettingsFooterLinks extends TestCase
{
/**
* JSON structure for $block2_links
*/
public function testBlock2LinksJsonStructureIsValid(): void
{
$function = new ReflectionFunction('apbct_settings__footer');

ob_start();
$function->invoke();
$output = ob_get_clean();

preg_match('/blockName:\s*["\']Recommended plugins["\'][\s\S]*?links:\s*(\[[\s\S]*?\])\s*,?\s*}/s', $output, $matches);

if (isset($matches[1])) {
$json = $matches[1];

$decoded = json_decode($json, true);
$this->assertIsArray($decoded, 'Must be a valid JSON');

$this->assertArrayHasKey('text', $decoded[0]);
$this->assertArrayHasKey('url', $decoded[0]);
$this->assertEquals('Security plugin by CleanTalk', $decoded[0]['text']);

$this->assertArrayHasKey('text', $decoded[1]);
$this->assertArrayHasKey('url', $decoded[1]);
$this->assertStringContainsString('Gravity Add-On', $decoded[1]['text']);
} else {
$this->fail('JSON for Recommended plugins not found');
}
}
}