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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.5.0
* Feat: Add `More Plugins` options page.

## 1.4.3
* Tested up to WP 7.0.

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"email": "badasswpdev@gmail.com"
}
],
"require": {
"badasswp/pluginate": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"mockery/mockery": "^1.6",
Expand All @@ -40,4 +43,4 @@
"analyse": "vendor/bin/phpstan analyse --memory-limit=2048M",
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-cobertura cobertura.xml && coveralls --repo-token=lo7lxZfU7gVcSJwU7oXEx6qPZW8F9p7wt --file=cobertura.xml"
}
}
}
59 changes: 59 additions & 0 deletions inc/Services/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,27 @@
use SqlToCpt\Abstracts\Service;
use SqlToCpt\Interfaces\Kernel;

use Pluginate\Admin as Pluginate;

class Admin extends Service implements Kernel {
/**
* Pluginate instance.
*
* @since 1.5.0
*
* @var Pluginate
*/
public Pluginate $pluginate;

/**
* Admin constructor.
*
* @since 1.5.0
*/
public function __construct() {
$this->pluginate = new Pluginate( 'sql-to-cpt' );
}

/**
* Bind to WP.
*
Expand All @@ -23,6 +43,7 @@ class Admin extends Service implements Kernel {
*/
public function register(): void {
add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
add_action( 'admin_init', [ $this->pluginate, 'init' ] );
}

/**
Expand All @@ -44,6 +65,15 @@ public function register_admin_menu(): void {
'dashicons-database',
90
);

add_submenu_page(
'sql-to-cpt',
__( 'More Plugins', 'sql-to-cpt' ),
__( 'More Plugins', 'sql-to-cpt' ),
'manage_options',
sprintf( '%s-more-plugins', 'sql-to-cpt' ),
[ $this, 'register_more_plugins' ]
);
}

/**
Expand All @@ -69,4 +99,33 @@ public function register_admin_page(): void {
]
);
}

/**
* Register More Plugins.
*
* This controls the display of the
* "More Plugins" submenu page.
*
* @since 1.5.0
*
* @return void
*/
public function register_more_plugins(): void {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
vprintf(
'<section class="wrap">
<h1>%s</h1>
<p>%s</p>
%s
</section>',
array_map(
'__',
[
'More Plugins',
'Check out some other amazing plugin of ours...',
$this->pluginate->get_more_plugins(),
]
)
);
}
}
11 changes: 11 additions & 0 deletions tests/unit/php/Core/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @covers \SqlToCpt\Services\Post::__construct
* @covers \SqlToCpt\Core\Post::__construct
* @covers \SqlToCpt\Services\Routes::__construct
* @covers \SqlToCpt\Services\Admin::__construct
*/
class ContainerTest extends TestCase {
public Container $container;
Expand Down Expand Up @@ -108,6 +109,16 @@ public function test_register() {
]
);

$admin = Service::$services[ Admin::class ];

WP_Mock::expectActionAdded(
'admin_init',
[
$admin->pluginate,
'init',
]
);

WP_Mock::expectActionAdded(
'init',
[
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/php/Services/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @covers \SqlToCpt\Services\Admin::register
* @covers \SqlToCpt\Services\Admin::register_admin_menu
* @covers \SqlToCpt\Services\Admin::register_admin_page
* @covers \SqlToCpt\Services\Admin::__construct
*/
class AdminTest extends TestCase {
public Admin $admin;
Expand All @@ -26,6 +27,7 @@ public function tearDown(): void {

public function test_register() {
WP_Mock::expectActionAdded( 'admin_menu', [ $this->admin, 'register_admin_menu' ] );
WP_Mock::expectActionAdded( 'admin_init', [ $this->admin->pluginate, 'init' ] );

$this->admin->register();

Expand All @@ -52,6 +54,21 @@ function ( $arg ) {
)
->andReturn( null );

WP_Mock::userFunction( '__' )
->andReturnUsing( fn( $text, $domain ) => $text );

WP_Mock::userFunction( 'add_submenu_page' )
->once()
->with(
'sql-to-cpt',
'More Plugins',
'More Plugins',
'manage_options',
'sql-to-cpt-more-plugins',
[ $this->admin, 'register_more_plugins' ]
)
->andReturn( null );

$this->admin->register_admin_menu();

$this->assertConditionsMet();
Expand Down
Loading