Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c2351b938 | |||
| 5cd5a74d28 |
+1
-15
@@ -15,23 +15,9 @@
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.5",
|
||||
"squizlabs/php_codesniffer": "^3.7",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"joomla/coding-standards": "dev-3.x-dev"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Joomla\\Component\\MokoSuiteCross\\Administrator\\": "source/packages/com_mokosuitecross/src/",
|
||||
"Joomla\\Component\\MokoSuiteCross\\Site\\": "source/packages/com_mokosuitecross/site/src/",
|
||||
"Joomla\\Plugin\\Content\\MokoSuiteCross\\": "source/packages/plg_content_mokosuitecross/src/",
|
||||
"Joomla\\Plugin\\System\\MokoSuiteCross\\": "source/packages/plg_system_mokosuitecross/src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"MokoSuiteCross\\Tests\\": "tests/"
|
||||
}
|
||||
"joomla/coding-standards": "^4.0"
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
colors="true"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
executionOrder="depends,defects"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory>tests/Unit</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<source>
|
||||
<include>
|
||||
<directory>source/packages/com_mokosuitecross/src</directory>
|
||||
<directory>source/packages/plg_content_mokosuitecross/src</directory>
|
||||
<directory>source/packages/plg_system_mokosuitecross/src</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
@@ -1,5 +1,14 @@
|
||||
; MokoSuiteCross — Site Frontend Language File
|
||||
; MokoSuiteCross -- Site Frontend Language File
|
||||
; Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
; License: GPL-3.0-or-later
|
||||
|
||||
COM_MOKOSUITECROSS="MokoSuiteCross"
|
||||
COM_MOKOSUITECROSS_POSTS_LIST_TITLE="Cross-Posted Content"
|
||||
COM_MOKOSUITECROSS_POST_DETAIL_TITLE="Cross-Post History"
|
||||
COM_MOKOSUITECROSS_COLUMN_ARTICLE="Article"
|
||||
COM_MOKOSUITECROSS_COLUMN_PLATFORMS="Platforms"
|
||||
COM_MOKOSUITECROSS_COLUMN_LAST_POSTED="Last Posted"
|
||||
COM_MOKOSUITECROSS_COLUMN_STATUS="Status"
|
||||
COM_MOKOSUITECROSS_COLUMN_POSTED_DATE="Posted Date"
|
||||
COM_MOKOSUITECROSS_COLUMN_LINK="Platform Link"
|
||||
COM_MOKOSUITECROSS_NO_POSTS="No cross-posted content found."
|
||||
|
||||
@@ -17,5 +17,5 @@ use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
protected $default_view = 'post';
|
||||
protected $default_view = 'posts';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\MokoSuiteCross\Site\Model;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
||||
class PostModel extends BaseDatabaseModel
|
||||
{
|
||||
public function getArticle(int $articleId): ?object
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('a.id, a.title, a.alias, a.catid, a.access')
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->where('a.id = ' . (int) $articleId)
|
||||
->where('a.state = 1');
|
||||
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
$query->where('a.access IN (' . implode(',', array_map('intval', $groups)) . ')');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadObject() ?: null;
|
||||
}
|
||||
|
||||
public function getPosts(int $articleId): array
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select([
|
||||
'p.id',
|
||||
'p.status',
|
||||
'p.platform_post_id',
|
||||
'p.posted_at',
|
||||
'p.error_message',
|
||||
'p.created',
|
||||
's.title AS service_title',
|
||||
's.service_type',
|
||||
])
|
||||
->from($db->quoteName('#__mokosuitecross_posts', 'p'))
|
||||
->join('INNER', $db->quoteName('#__mokosuitecross_services', 's') . ' ON s.id = p.service_id')
|
||||
->where('p.article_id = ' . (int) $articleId)
|
||||
->order('p.created DESC');
|
||||
|
||||
$db->setQuery($query, 0, 50);
|
||||
|
||||
return $db->loadObjectList() ?: [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\MokoSuiteCross\Site\Model;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
|
||||
class PostsModel extends ListModel
|
||||
{
|
||||
protected function getListQuery()
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select([
|
||||
'a.id AS article_id',
|
||||
'a.title AS article_title',
|
||||
'a.alias AS article_alias',
|
||||
'a.catid',
|
||||
'MAX(p.posted_at) AS last_posted',
|
||||
'COUNT(p.id) AS post_count',
|
||||
'GROUP_CONCAT(DISTINCT s.service_type ORDER BY s.service_type SEPARATOR \',\') AS service_types',
|
||||
])
|
||||
->from($db->quoteName('#__mokosuitecross_posts', 'p'))
|
||||
->join('INNER', $db->quoteName('#__content', 'a') . ' ON a.id = p.article_id')
|
||||
->join('INNER', $db->quoteName('#__mokosuitecross_services', 's') . ' ON s.id = p.service_id')
|
||||
->where('p.status = ' . $db->quote('posted'))
|
||||
->where('a.state = 1');
|
||||
|
||||
// Access filtering
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
$query->where('a.access IN (' . implode(',', array_map('intval', $groups)) . ')');
|
||||
|
||||
$query->group('a.id, a.title, a.alias, a.catid')
|
||||
->order('last_posted DESC');
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\MokoSuiteCross\Site\View\Post;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $article;
|
||||
protected $posts;
|
||||
|
||||
public function display($tpl = null): void
|
||||
{
|
||||
$articleId = Factory::getApplication()->getInput()->getInt('id', 0);
|
||||
$model = $this->getModel();
|
||||
$this->article = $model->getArticle($articleId);
|
||||
$this->posts = $model->getPosts($articleId);
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\MokoSuiteCross\Site\View\Posts;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $items;
|
||||
protected $pagination;
|
||||
|
||||
public function display($tpl = null): void
|
||||
{
|
||||
$this->items = $this->get('Items');
|
||||
$this->pagination = $this->get('Pagination');
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
$statusClasses = [
|
||||
'posted' => 'bg-success',
|
||||
'failed' => 'bg-danger',
|
||||
'permanently_failed' => 'bg-danger',
|
||||
'queued' => 'bg-warning text-dark',
|
||||
'posting' => 'bg-info',
|
||||
'scheduled' => 'bg-primary',
|
||||
'deleted' => 'bg-secondary',
|
||||
'cancelled' => 'bg-secondary',
|
||||
];
|
||||
|
||||
?>
|
||||
<div class="com-mokosuitecross-post">
|
||||
<?php if (!$this->article) : ?>
|
||||
<div class="alert alert-warning">
|
||||
<?php echo Text::_('COM_MOKOSUITECROSS_NO_POSTS'); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<h2><?php echo Text::_('COM_MOKOSUITECROSS_POST_DETAIL_TITLE'); ?></h2>
|
||||
<p>
|
||||
<strong><?php echo $this->escape($this->article->title); ?></strong>
|
||||
</p>
|
||||
|
||||
<?php if (empty($this->posts)) : ?>
|
||||
<div class="alert alert-info">
|
||||
<?php echo Text::_('COM_MOKOSUITECROSS_NO_POSTS'); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_HEADING_SERVICE'); ?></th>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_STATUS'); ?></th>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_POSTED_DATE'); ?></th>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_LINK'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($this->posts as $post) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="badge bg-secondary"><?php echo $this->escape($post->service_type); ?></span>
|
||||
<?php echo $this->escape($post->service_title); ?>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge <?php echo $statusClasses[$post->status] ?? 'bg-secondary'; ?>">
|
||||
<?php echo $this->escape(ucfirst($post->status)); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td><?php echo $post->posted_at ? $this->escape($post->posted_at) : $this->escape($post->created); ?></td>
|
||||
<td>
|
||||
<?php if (!empty($post->platform_post_id)) : ?>
|
||||
<span class="text-muted small"><?php echo $this->escape($post->platform_post_id); ?></span>
|
||||
<?php else : ?>
|
||||
—
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<a href="<?php echo Route::_('index.php?option=com_mokosuitecross&view=posts'); ?>" class="btn btn-secondary">
|
||||
← <?php echo Text::_('COM_MOKOSUITECROSS_POSTS_LIST_TITLE'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage com_mokosuitecross
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
?>
|
||||
<div class="com-mokosuitecross-posts">
|
||||
<h2><?php echo Text::_('COM_MOKOSUITECROSS_POSTS_LIST_TITLE'); ?></h2>
|
||||
|
||||
<?php if (empty($this->items)) : ?>
|
||||
<div class="alert alert-info">
|
||||
<?php echo Text::_('COM_MOKOSUITECROSS_NO_POSTS'); ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_ARTICLE'); ?></th>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_PLATFORMS'); ?></th>
|
||||
<th><?php echo Text::_('COM_MOKOSUITECROSS_COLUMN_LAST_POSTED'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($this->items as $item) : ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?php echo Route::_('index.php?option=com_mokosuitecross&view=post&id=' . (int) $item->article_id); ?>">
|
||||
<?php echo $this->escape($item->article_title); ?>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$types = explode(',', $item->service_types ?? '');
|
||||
foreach ($types as $type) :
|
||||
$type = trim($type);
|
||||
if (empty($type)) continue;
|
||||
?>
|
||||
<span class="badge bg-secondary"><?php echo $this->escape($type); ?></span>
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo $item->last_posted ? $this->escape($item->last_posted) : '—'; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if ($this->pagination->pagesTotal > 1) : ?>
|
||||
<div class="com-mokosuitecross-posts__pagination">
|
||||
<?php echo $this->pagination->getListFooter(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage Tests
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace MokoSuiteCross\Tests\Unit\Helper;
|
||||
|
||||
use Joomla\Component\MokoSuiteCross\Administrator\Helper\PreviewHelper;
|
||||
use PHPUnit\Framework\Attributes\RequiresMethod;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[RequiresMethod(PreviewHelper::class, 'render')]
|
||||
class PreviewHelperTest extends TestCase
|
||||
{
|
||||
public function testRenderTwitterContainsCharCount(): void
|
||||
{
|
||||
$html = PreviewHelper::render('twitter', 'Test Title', 'Hello world', 'https://example.com', '', 'Author');
|
||||
|
||||
$this->assertStringContainsString('11/280', $html);
|
||||
}
|
||||
|
||||
public function testRenderTwitterEscapesHtml(): void
|
||||
{
|
||||
$html = PreviewHelper::render('twitter', '<script>alert(1)</script>', 'text', 'https://example.com');
|
||||
|
||||
$this->assertStringNotContainsString('<script>', $html);
|
||||
$this->assertStringContainsString('<script>', $html);
|
||||
}
|
||||
|
||||
public function testRenderFacebookContainsAuthor(): void
|
||||
{
|
||||
$html = PreviewHelper::render('facebook', 'My Article', 'Intro text here', 'https://example.com', '', 'John Doe');
|
||||
|
||||
$this->assertStringContainsString('John Doe', $html);
|
||||
$this->assertStringContainsString('My Article', $html);
|
||||
}
|
||||
|
||||
public function testRenderMastodonContainsCharCount(): void
|
||||
{
|
||||
$html = PreviewHelper::render('mastodon', 'Title', 'Post text', 'https://example.com', '', 'Author');
|
||||
|
||||
$this->assertStringContainsString('9/500', $html);
|
||||
}
|
||||
|
||||
public function testRenderBlueskyContainsCharCount(): void
|
||||
{
|
||||
$html = PreviewHelper::render('bluesky', 'Title', 'A bluesky post', 'https://example.com', '', 'Author');
|
||||
|
||||
$this->assertStringContainsString('14/300', $html);
|
||||
}
|
||||
|
||||
public function testRenderLinkedInContainsAuthor(): void
|
||||
{
|
||||
$html = PreviewHelper::render('linkedin', 'Article', 'Text', 'https://example.com', '', 'Jane Smith');
|
||||
|
||||
$this->assertStringContainsString('Jane Smith', $html);
|
||||
}
|
||||
|
||||
public function testRenderTelegramDoesNotShowAuthor(): void
|
||||
{
|
||||
$html = PreviewHelper::render('telegram', 'Article', 'Message text', 'https://example.com');
|
||||
|
||||
$this->assertStringContainsString('Message text', $html);
|
||||
$this->assertStringContainsString('Article', $html);
|
||||
}
|
||||
|
||||
public function testRenderWithImageIncludesImgTag(): void
|
||||
{
|
||||
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', 'https://example.com/image.jpg', 'Author');
|
||||
|
||||
$this->assertStringContainsString('<img src="https://example.com/image.jpg"', $html);
|
||||
}
|
||||
|
||||
public function testRenderWithoutImageOmitsImgTag(): void
|
||||
{
|
||||
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', '', 'Author');
|
||||
|
||||
$this->assertStringNotContainsString('<img', $html);
|
||||
}
|
||||
|
||||
public function testRenderGenericPlatform(): void
|
||||
{
|
||||
$html = PreviewHelper::render('pinterest', 'Title', 'Text', 'https://example.com');
|
||||
|
||||
$this->assertStringContainsString('PINTEREST', $html);
|
||||
$this->assertStringContainsString('Title', $html);
|
||||
}
|
||||
|
||||
public function testGetSupportedPlatformsReturnsSix(): void
|
||||
{
|
||||
$platforms = PreviewHelper::getSupportedPlatforms();
|
||||
|
||||
$this->assertCount(6, $platforms);
|
||||
$this->assertContains('twitter', $platforms);
|
||||
$this->assertContains('facebook', $platforms);
|
||||
$this->assertContains('mastodon', $platforms);
|
||||
$this->assertContains('linkedin', $platforms);
|
||||
$this->assertContains('bluesky', $platforms);
|
||||
$this->assertContains('telegram', $platforms);
|
||||
}
|
||||
|
||||
public function testRenderUsesTextWhenProvided(): void
|
||||
{
|
||||
$html = PreviewHelper::render('facebook', 'My Title', 'Custom intro text', 'https://example.com');
|
||||
|
||||
$this->assertStringContainsString('Custom intro text', $html);
|
||||
}
|
||||
|
||||
public function testRenderFallsBackToTitleWhenTextEmpty(): void
|
||||
{
|
||||
$html = PreviewHelper::render('facebook', 'Fallback Title', '', 'https://example.com');
|
||||
|
||||
$this->assertMatchesRegularExpression('/Fallback Title.*Fallback Title/s', $html);
|
||||
}
|
||||
|
||||
public function testImageUrlIsEscaped(): void
|
||||
{
|
||||
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', 'https://example.com/img?a=1&b=2', 'Author');
|
||||
|
||||
$this->assertStringContainsString('https://example.com/img?a=1&b=2', $html);
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage Tests
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace MokoSuiteCross\Tests\Unit\Helper;
|
||||
|
||||
use Joomla\Component\MokoSuiteCross\Administrator\Helper\ServiceIconHelper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ServiceIconHelperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider knownServiceTypesProvider
|
||||
*/
|
||||
public function testGetIconReturnsKnownIcon(string $serviceType, string $expectedIcon): void
|
||||
{
|
||||
$this->assertSame($expectedIcon, ServiceIconHelper::getIcon($serviceType));
|
||||
}
|
||||
|
||||
public static function knownServiceTypesProvider(): array
|
||||
{
|
||||
return [
|
||||
'facebook' => ['facebook', 'icon-facebook'],
|
||||
'twitter' => ['twitter', 'icon-twitter'],
|
||||
'linkedin' => ['linkedin', 'icon-linkedin'],
|
||||
'mastodon' => ['mastodon', 'icon-globe'],
|
||||
'bluesky' => ['bluesky', 'icon-cloud'],
|
||||
'telegram' => ['telegram', 'icon-paper-plane'],
|
||||
'discord' => ['discord', 'icon-headset'],
|
||||
'slack' => ['slack', 'icon-hashtag'],
|
||||
'mailchimp' => ['mailchimp', 'icon-envelope'],
|
||||
'medium' => ['medium', 'icon-book'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGetIconReturnsFallbackForUnknownType(): void
|
||||
{
|
||||
$this->assertSame('icon-share-alt', ServiceIconHelper::getIcon('unknown_platform'));
|
||||
}
|
||||
|
||||
public function testRenderIconOutputsSpanElement(): void
|
||||
{
|
||||
$html = ServiceIconHelper::renderIcon('facebook');
|
||||
|
||||
$this->assertSame('<span class="icon-facebook" aria-hidden="true"></span>', $html);
|
||||
}
|
||||
|
||||
public function testRenderIconWithExtraClass(): void
|
||||
{
|
||||
$html = ServiceIconHelper::renderIcon('twitter', 'me-1 text-info');
|
||||
|
||||
$this->assertSame('<span class="icon-twitter me-1 text-info" aria-hidden="true"></span>', $html);
|
||||
}
|
||||
|
||||
public function testRenderIconEscapesExtraClass(): void
|
||||
{
|
||||
$html = ServiceIconHelper::renderIcon('facebook', '"><script>');
|
||||
|
||||
$this->assertStringNotContainsString('<script>', $html);
|
||||
$this->assertStringContainsString('"><script>', $html);
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage Tests
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace MokoSuiteCross\Tests\Unit\Service;
|
||||
|
||||
use Joomla\Component\MokoSuiteCross\Administrator\Service\MokoSuiteCrossServiceInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ServiceInterfaceContractTest extends TestCase
|
||||
{
|
||||
public function testInterfaceExists(): void
|
||||
{
|
||||
$this->assertTrue(interface_exists(MokoSuiteCrossServiceInterface::class));
|
||||
}
|
||||
|
||||
public function testInterfaceDefinesRequiredMethods(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(MokoSuiteCrossServiceInterface::class);
|
||||
|
||||
$expectedMethods = [
|
||||
'getServiceType',
|
||||
'getServiceName',
|
||||
'publish',
|
||||
'validateCredentials',
|
||||
'getMaxLength',
|
||||
'supportsMedia',
|
||||
'getSupportedMediaTypes',
|
||||
];
|
||||
|
||||
foreach ($expectedMethods as $method) {
|
||||
$this->assertTrue(
|
||||
$reflection->hasMethod($method),
|
||||
"Interface missing method: {$method}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetServiceTypeReturnsString(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'getServiceType');
|
||||
$returnType = $method->getReturnType();
|
||||
|
||||
$this->assertNotNull($returnType);
|
||||
$this->assertSame('string', $returnType->getName());
|
||||
}
|
||||
|
||||
public function testPublishAcceptsCorrectParameters(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'publish');
|
||||
$params = $method->getParameters();
|
||||
|
||||
$this->assertCount(4, $params);
|
||||
$this->assertSame('message', $params[0]->getName());
|
||||
$this->assertSame('media', $params[1]->getName());
|
||||
$this->assertSame('credentials', $params[2]->getName());
|
||||
$this->assertSame('params', $params[3]->getName());
|
||||
}
|
||||
|
||||
public function testPublishReturnsArray(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'publish');
|
||||
$returnType = $method->getReturnType();
|
||||
|
||||
$this->assertNotNull($returnType);
|
||||
$this->assertSame('array', $returnType->getName());
|
||||
}
|
||||
|
||||
public function testGetMaxLengthReturnsInt(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'getMaxLength');
|
||||
$returnType = $method->getReturnType();
|
||||
|
||||
$this->assertNotNull($returnType);
|
||||
$this->assertSame('int', $returnType->getName());
|
||||
}
|
||||
|
||||
public function testSupportsMediaReturnsBool(): void
|
||||
{
|
||||
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'supportsMedia');
|
||||
$returnType = $method->getReturnType();
|
||||
|
||||
$this->assertNotNull($returnType);
|
||||
$this->assertSame('bool', $returnType->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider servicePluginClassProvider
|
||||
*/
|
||||
public function testServicePluginImplementsInterface(string $className): void
|
||||
{
|
||||
if (!class_exists($className)) {
|
||||
$this->markTestSkipped("Class {$className} not autoloadable (needs Joomla runtime)");
|
||||
}
|
||||
|
||||
$this->assertTrue(
|
||||
is_subclass_of($className, MokoSuiteCrossServiceInterface::class),
|
||||
"{$className} does not implement MokoSuiteCrossServiceInterface"
|
||||
);
|
||||
}
|
||||
|
||||
public static function servicePluginClassProvider(): array
|
||||
{
|
||||
$plugins = [
|
||||
'facebook', 'twitter', 'linkedin', 'mastodon', 'bluesky',
|
||||
'telegram', 'discord', 'slack', 'mailchimp', 'medium',
|
||||
'instagram', 'youtube', 'threads', 'pinterest', 'reddit',
|
||||
];
|
||||
|
||||
$cases = [];
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
$class = ucfirst($plugin);
|
||||
$cases[$plugin] = [
|
||||
"Joomla\\Plugin\\MokoSuiteCross\\{$class}\\Extension\\{$class}Service",
|
||||
];
|
||||
}
|
||||
|
||||
return $cases;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package MokoSuiteCross
|
||||
* @subpackage Tests
|
||||
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||||
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see LICENSE
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (!defined('_JEXEC')) {
|
||||
define('_JEXEC', 1);
|
||||
}
|
||||
Reference in New Issue
Block a user