@sabbir1991/wpscaffold 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +326 -0
- package/bin/index.js +19 -0
- package/lib/generator.js +435 -0
- package/package.json +30 -0
- package/template/_editorconfig +19 -0
- package/template/_github/ISSUE_TEMPLATE/bug_report.yml +29 -0
- package/template/_github/ISSUE_TEMPLATE/config.yml +1 -0
- package/template/_github/ISSUE_TEMPLATE/feature_request.yml +18 -0
- package/template/_github/PULL_REQUEST_TEMPLATE.md +16 -0
- package/template/_github/workflows/lint.yml +31 -0
- package/template/_github/workflows/phpcs.yml +29 -0
- package/template/_github/workflows/phpunit.yml +34 -0
- package/template/_gitignore +34 -0
- package/template/_nvmrc +1 -0
- package/template/_stylelintignore +11 -0
- package/template/composer.json +35 -0
- package/template/eslint.config.js +8 -0
- package/template/includes/Admin/Menu.php +67 -0
- package/template/includes/Assets.php +140 -0
- package/template/includes/Blocks.php +53 -0
- package/template/includes/Plugin.php +59 -0
- package/template/includes/Traits/Singleton.php +46 -0
- package/template/languages/.gitkeep +0 -0
- package/template/lefthook.yml +13 -0
- package/template/phpcs.xml.dist +42 -0
- package/template/phpunit.xml.dist +19 -0
- package/template/plugin-skeleton.php +64 -0
- package/template/readme.txt +25 -0
- package/template/src/block/block.json +17 -0
- package/template/src/block/edit.js +17 -0
- package/template/src/block/index.js +13 -0
- package/template/src/block/render.php +13 -0
- package/template/src/block/style.scss +8 -0
- package/template/src/block/view.js +5 -0
- package/template/src/global/css/admin.scss +8 -0
- package/template/src/global/js/admin.js +5 -0
- package/template/tests/Unit/AbstractTestCase.php +25 -0
- package/template/tests/Unit/AssetsTest.php +58 -0
- package/template/tests/Unit/MenuTest.php +38 -0
- package/template/tests/bootstrap.php +56 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Base test case for all unit tests.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton\Tests\Unit
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
namespace PluginVendor\PluginSkeleton\Tests\Unit;
|
|
9
|
+
|
|
10
|
+
use Brain\Monkey;
|
|
11
|
+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
|
|
12
|
+
|
|
13
|
+
abstract class AbstractTestCase extends TestCase {
|
|
14
|
+
|
|
15
|
+
protected function setUp(): void {
|
|
16
|
+
parent::setUp();
|
|
17
|
+
Monkey\setUp();
|
|
18
|
+
Monkey\Functions\stubTranslationFunctions();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected function tearDown(): void {
|
|
22
|
+
Monkey\tearDown();
|
|
23
|
+
parent::tearDown();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests for the Assets class.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton\Tests\Unit
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
namespace PluginVendor\PluginSkeleton\Tests\Unit;
|
|
9
|
+
|
|
10
|
+
use Brain\Monkey\Functions;
|
|
11
|
+
use PluginVendor\PluginSkeleton\Assets;
|
|
12
|
+
|
|
13
|
+
class AssetsTest extends AbstractTestCase {
|
|
14
|
+
|
|
15
|
+
private function make_assets(): Assets {
|
|
16
|
+
return new class extends Assets {
|
|
17
|
+
public function __construct() {
|
|
18
|
+
parent::__construct();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public function test_assets_can_be_instantiated(): void {
|
|
24
|
+
Functions\stubs( [ 'add_action' ] );
|
|
25
|
+
|
|
26
|
+
$assets = $this->make_assets();
|
|
27
|
+
$this->assertInstanceOf( Assets::class, $assets );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* @skeleton-admin */
|
|
31
|
+
public function test_setup_hooks_registers_admin_enqueue_scripts(): void {
|
|
32
|
+
Functions\expect( 'add_action' )
|
|
33
|
+
->once()
|
|
34
|
+
->with( 'admin_enqueue_scripts', \Mockery::type( 'array' ) );
|
|
35
|
+
|
|
36
|
+
$assets = $this->make_assets();
|
|
37
|
+
$this->assertInstanceOf( Assets::class, $assets );
|
|
38
|
+
}
|
|
39
|
+
/* @skeleton-admin-end */
|
|
40
|
+
|
|
41
|
+
public function test_get_file_version_returns_false_for_missing_file(): void {
|
|
42
|
+
Functions\stubs( [ 'add_action' ] );
|
|
43
|
+
|
|
44
|
+
$assets = $this->make_assets();
|
|
45
|
+
$result = $assets->get_file_version( 'nonexistent.js' );
|
|
46
|
+
|
|
47
|
+
$this->assertFalse( $result );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public function test_get_file_version_returns_provided_version(): void {
|
|
51
|
+
Functions\stubs( [ 'add_action' ] );
|
|
52
|
+
|
|
53
|
+
$assets = $this->make_assets();
|
|
54
|
+
$result = $assets->get_file_version( 'nonexistent.js', '2.0.0' );
|
|
55
|
+
|
|
56
|
+
$this->assertSame( '2.0.0', $result );
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Tests for the Admin\Menu class.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton\Tests\Unit
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
namespace PluginVendor\PluginSkeleton\Tests\Unit;
|
|
9
|
+
|
|
10
|
+
use Brain\Monkey\Functions;
|
|
11
|
+
use PluginVendor\PluginSkeleton\Admin\Menu;
|
|
12
|
+
|
|
13
|
+
class MenuTest extends AbstractTestCase {
|
|
14
|
+
|
|
15
|
+
private function make_menu(): Menu {
|
|
16
|
+
return new class extends Menu {
|
|
17
|
+
public function __construct() {
|
|
18
|
+
parent::__construct();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public function test_menu_can_be_instantiated(): void {
|
|
24
|
+
Functions\stubs( [ 'add_action' ] );
|
|
25
|
+
|
|
26
|
+
$menu = $this->make_menu();
|
|
27
|
+
$this->assertInstanceOf( Menu::class, $menu );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public function test_setup_hooks_registers_admin_menu_action(): void {
|
|
31
|
+
Functions\expect( 'add_action' )
|
|
32
|
+
->once()
|
|
33
|
+
->with( 'admin_menu', \Mockery::type( 'array' ) );
|
|
34
|
+
|
|
35
|
+
$menu = $this->make_menu();
|
|
36
|
+
$this->assertInstanceOf( Menu::class, $menu );
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* PHPUnit bootstrap for unit tests.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton\Tests
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
require dirname( __DIR__ ) . '/vendor/autoload.php';
|
|
9
|
+
|
|
10
|
+
// Minimal WP environment for unit tests.
|
|
11
|
+
defined( 'ABSPATH' ) || define( 'ABSPATH', '/tmp/' );
|
|
12
|
+
defined( 'WPINC' ) || define( 'WPINC', 'wp-includes' );
|
|
13
|
+
|
|
14
|
+
// Plugin constants used by classes under test.
|
|
15
|
+
define( 'PLUGIN_SKELETON_VERSION', '1.0.0' );
|
|
16
|
+
define( 'PLUGIN_SKELETON_PATH', dirname( __DIR__ ) );
|
|
17
|
+
define( 'PLUGIN_SKELETON_URL', 'http://example.com/wp-content/plugins/plugin-skeleton' );
|
|
18
|
+
define( 'PLUGIN_SKELETON_ASSET_PATH', PLUGIN_SKELETON_PATH . '/assets' );
|
|
19
|
+
define( 'PLUGIN_SKELETON_ASSET_URL', PLUGIN_SKELETON_URL . '/assets' );
|
|
20
|
+
|
|
21
|
+
// WP_Error stub — avoids requiring a full WP bootstrap.
|
|
22
|
+
if ( ! class_exists( 'WP_Error' ) ) {
|
|
23
|
+
class WP_Error { // phpcs:ignore
|
|
24
|
+
public string $code;
|
|
25
|
+
public string $message;
|
|
26
|
+
public mixed $data;
|
|
27
|
+
|
|
28
|
+
public function __construct( string $code = '', string $message = '', mixed $data = '' ) {
|
|
29
|
+
$this->code = $code;
|
|
30
|
+
$this->message = $message;
|
|
31
|
+
$this->data = $data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public function get_error_code(): string { return $this->code; }
|
|
35
|
+
public function get_error_message(): string { return $this->message; }
|
|
36
|
+
public function get_error_data(): mixed { return $this->data; }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ( ! function_exists( 'is_wp_error' ) ) {
|
|
41
|
+
function is_wp_error( $thing ): bool {
|
|
42
|
+
return $thing instanceof WP_Error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if ( ! function_exists( 'wp_unslash' ) ) {
|
|
47
|
+
function wp_unslash( $value ) {
|
|
48
|
+
return is_array( $value ) ? array_map( 'wp_unslash', $value ) : stripslashes( (string) $value );
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ( ! function_exists( 'wp_json_encode' ) ) {
|
|
53
|
+
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
|
|
54
|
+
return json_encode( $data, $options, $depth );
|
|
55
|
+
}
|
|
56
|
+
}
|