Skip to content
Snippets Groups Projects
Commit 1502ed63 authored by Sebastian Pisula's avatar Sebastian Pisula
Browse files

feature(core): plugin template changes

parent 17550d61
No related branches found
No related tags found
1 merge request!40feature(core): plugin template changes
<?php <?php
/** /**
* Plugin main class. * Plugin main class.
*
* @package WPDesk\PluginTemplate
*/ */
namespace WPDesk\PluginTemplate; namespace WPDesk\PluginTemplate;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use PluginTemplateVendor\WPDesk_Plugin_Info;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin; use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableCollection; use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableParent; use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
/** /**
* Main plugin class. The most important flow decisions are made here. * Main plugin class. The most important flow decisions are made here.
* *
* @package WPDesk\PluginTemplate * @codeCoverageIgnore
*/ */
class Plugin extends AbstractPlugin implements LoggerAwareInterface, HookableCollection { class Plugin extends AbstractPlugin implements LoggerAwareInterface, HookableCollection {
use LoggerAwareTrait; use LoggerAwareTrait;
use HookableParent; use HookableParent;
/** /**
* Plugin constructor. * Init hooks.
*
* @param WPDesk_Plugin_Info $plugin_info Plugin info.
*/
public function __construct( WPDesk_Plugin_Info $plugin_info ) {
parent::__construct( $plugin_info );
$this->setLogger( new NullLogger() );
$this->plugin_url = $this->plugin_info->get_plugin_url();
$this->plugin_namespace = $this->plugin_info->get_text_domain();
}
/**
* Initializes plugin external state.
*
* The plugin internal state is initialized in the constructor and the plugin should be internally consistent after creation.
* The external state includes hooks execution, communication with other plugins, integration with WC etc.
*
* @return void
*/
public function init() {
parent::init();
}
/**
* Integrate with WordPress and with other plugins using action/filter system.
* *
* @return void * @return void
* @codeCoverageIgnore
*/ */
public function hooks() { public function hooks(): void {
parent::hooks(); parent::hooks();
$this->hooks_on_hookable_objects();
} }
} }
#!/bin/bash
export WPDESK_PLUGIN_SLUG=wp-desk-plugin-template
export WPDESK_PLUGIN_TITLE="WP Desk Plugin Template"
export WOOTESTS_IP=${WOOTESTS_IP:wootests}
sh ./vendor/wpdesk/wp-codeception/scripts/common_bootstrap.sh
...@@ -9,23 +9,25 @@ actor: AcceptanceTester ...@@ -9,23 +9,25 @@ actor: AcceptanceTester
modules: modules:
enabled: enabled:
- Cli - Cli
- WPCLI
- REST
- WPDb - WPDb
- WPWebDriver - WPWebDriver
- WPFilesystem - WPFilesystem
- WPCLI
- \Helper\Acceptance - \Helper\Acceptance
config: config:
WPDb: WPDb:
dsn: 'mysql:host=%TEST_SITE_DB_HOST%;dbname=%TEST_SITE_DB_NAME%' dsn: 'mysql:host=%TEST_SITE_DB_HOST%;dbname=%TEST_SITE_DB_NAME%'
user: '%TEST_SITE_DB_USER%' user: '%TEST_SITE_DB_USER%'
password: '%TEST_SITE_DB_PASSWORD%' password: '%TEST_SITE_DB_PASSWORD%'
#dump: 'tests/_data/dump.sql' dump: 'tests/codeception/tests/_data/db.sql'
#import the dump before the tests; this means the test site database will be repopulated before the tests. #import the dump before the tests; this means the test site database will be repopulated before the tests.
populate: false populate: true
# re-import the dump between tests; this means the test site database will be repopulated between the tests. # re-import the dump between tests; this means the test site database will be repopulated between the tests.
cleanup: true cleanup: true
waitlock: 10 waitlock: 10
url: '%TEST_SITE_WP_URL%' url: '%TEST_SITE_WP_URL%'
originalUrl: '%TEST_SITE_WP_URL%'
urlReplacement: true #replace the hardcoded dump URL with the one above urlReplacement: true #replace the hardcoded dump URL with the one above
tablePrefix: '%TEST_SITE_TABLE_PREFIX%' tablePrefix: '%TEST_SITE_TABLE_PREFIX%'
WPBrowser: WPBrowser:
...@@ -33,17 +35,28 @@ modules: ...@@ -33,17 +35,28 @@ modules:
adminUsername: '%TEST_SITE_ADMIN_USERNAME%' adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
adminPassword: '%TEST_SITE_ADMIN_PASSWORD%' adminPassword: '%TEST_SITE_ADMIN_PASSWORD%'
adminPath: '%TEST_SITE_WP_ADMIN_PATH%' adminPath: '%TEST_SITE_WP_ADMIN_PATH%'
log_js_errors: true
WPWebDriver: WPWebDriver:
browser: chrome # 'chrome' or 'firefox' browser: chrome # 'chrome' or 'firefox'
url: '%TEST_SITE_WP_URL%' url: '%TEST_SITE_WP_URL%'
host: chrome host: '%SELENIUM_HOST%'
port: '%SELENIUM_PORT%'
adminUsername: '%TEST_SITE_ADMIN_USERNAME%' adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
adminPassword: '%TEST_SITE_ADMIN_PASSWORD%' adminPassword: '%TEST_SITE_ADMIN_PASSWORD%'
adminPath: '%TEST_SITE_WP_ADMIN_PATH%' adminPath: '%TEST_SITE_WP_ADMIN_PATH%'
wait: 10
restart: false
clear_cookies: true
log_js_errors: true log_js_errors: true
capabilities:
unexpectedAlertBehaviour: "accept"
chromeOptions:
args: [ "unexpectedAlertBehaviour: 'accept'" ]
WPCLI: WPCLI:
path: '%WP_ROOT_FOLDER%' path: '%WP_ROOT_FOLDER%'
allow-root: true
throw: true throw: true
WPFilesystem: WPFilesystem:
wpRootFolder: '%WP_ROOT_FOLDER%' wpRootFolder: '%WP_ROOT_FOLDER%'
REST:
depends: WPBrowser
url: '%TEST_SITE_WP_URL%'
<?php <?php
use WPDesk\Codeception\Tests\Acceptance\Cest; use WPDesk\Codeception\Tests\Acceptance\Cest\AbstractCestForPluginActivation;
class ActivationCest extends Cest { class ActivationCest extends AbstractCestForPluginActivation {
/** /**
* Deactivate plugins before tests. * Deactivate plugins before tests.
* *
* @param AcceptanceTester $i . * @param AcceptanceTester $i .
* *
* @throws \Codeception\Exception\ModuleException .
*/ */
public function _before( AcceptanceTester $i ) { public function _before( AcceptanceTester $i ) {
$i->loginAsAdmin(); $i->loginAsAdministrator();
$i->amOnPluginsPage(); $i->amOnPluginsPage();
$i->deactivatePlugin( $this->getPluginSlug() ); $i->deactivatePlugin( $this->getPluginSlug() );
$i->amOnPluginsPage(); $i->amOnPluginsPage();
...@@ -24,11 +23,10 @@ class ActivationCest extends Cest { ...@@ -24,11 +23,10 @@ class ActivationCest extends Cest {
* *
* @param AcceptanceTester $i . * @param AcceptanceTester $i .
* *
* @throws \Codeception\Exception\ModuleException .
*/ */
public function pluginActivation( AcceptanceTester $i ) { public function pluginActivation( AcceptanceTester $i ) {
$i->loginAsAdmin(); $i->loginAsAdministrator();
$i->amOnPluginsPage(); $i->amOnPluginsPage();
$i->seePluginDeactivated( $this->getPluginSlug() ); $i->seePluginDeactivated( $this->getPluginSlug() );
...@@ -36,7 +34,7 @@ class ActivationCest extends Cest { ...@@ -36,7 +34,7 @@ class ActivationCest extends Cest {
$i->activateWPDeskPlugin( $i->activateWPDeskPlugin(
$this->getPluginSlug(), $this->getPluginSlug(),
array( 'woocommerce' ), array( 'woocommerce' ),
array( 'The “WP Desk Plugin Template” plugin cannot run without WooCommerce active. Please install and activate WooCommerce plugin.' ) array( 'The “' . $this->getPluginProductId() . '” plugin requires activating WooCommerce plugin. Activate WooCommerce ' )
); );
} }
......
<?php
use WPDesk\Codeception\Tests\Acceptance\Cest\AbstractCestForWooCommerce;
/**
* Common WooCommerce tests.
*/
class WooCommerceCest extends AbstractCestForWooCommerce {
}
plugin-slug: plugin-template
plugin-file: plugin-template/plugin-template.php
plugin-title: WP Desk Plugin Template
plugin-product-id: WP Desk Plugin Template
plugins:
repository:
- woocommerce
activate:
- woocommerce
prepare-database:
- option set woocommerce_show_marketplace_suggestions "no"
...@@ -31,6 +31,8 @@ if (!is_array($plugins_to_active)) { ...@@ -31,6 +31,8 @@ if (!is_array($plugins_to_active)) {
$plugins_to_active[] = 'woocommerce/woocommerce.php'; $plugins_to_active[] = 'woocommerce/woocommerce.php';
update_option( 'active_plugins', $plugins_to_active ); update_option( 'active_plugins', $plugins_to_active );
do_action('plugins_loaded');
echo "\n\n"; echo "\n\n";
echo 'WC_VERSION=' . WC_VERSION . "\n"; echo 'WC_VERSION=' . WC_VERSION . "\n";
echo 'PHP_VERSION=' . phpversion() . "\n"; echo 'PHP_VERSION=' . phpversion() . "\n";
......
<?php
namespace unit;
use Mockery;
use WP_Mock;
use WP_Mock\Tools\TestCase;
class ExampleTest extends TestCase {
// private $test_class_under_tests;
public function setUp() {
WP_Mock::setUp();
// $example = Mockery::mock( class );
// $this->test_class_under_tests =
}
public function tearDown() {
WP_Mock::tearDown();
}
//
// public function testShouldImplementsHookable() {
// // Then
// $this->assertInstanceOf( Hookable::class, $this->test_class_under_tests );
// }
//
// public function testShouldAddHooks() {
// // Expects
// WP_Mock::expectFilterAdded( 'woocommerce_get_sections_shipping', [ $this->test_class_under_tests, 'add_section_to_array' ] );
// WP_Mock::expectFilterAdded( 'woocommerce_get_settings_shipping', [ $this->test_class_under_tests, 'get_section_settings_fields' ], 10, 2 );
//
// // When
// $this->test_class_under_tests->hooks();
//
// // Then
// $this->assertTrue( true );
// }
public function testShouldReturnTrueAlways() {
// Expects.
// Given.
// When.
// Then.
$this->assertTrue( true );
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
require_once __DIR__ . '/../../vendor/autoload.php'; require_once __DIR__ . '/../../vendor/autoload.php';
error_reporting( E_ALL ); error_reporting( E_ALL & ~E_DEPRECATED );
if ( getenv( 'PLUGIN_PATH' ) !== false ) { if ( getenv( 'PLUGIN_PATH' ) !== false ) {
define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) ); define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) );
......
/* ---
Docs: https://www.npmjs.com/package/mati-mix/
--- */
const mix = require( 'mati-mix' );
// Settings
mix.js( 'assets-src/js/app.js', 'assets/dist/app.js' );
mix.sass( 'assets-src/scss/app.scss', 'assets/dist/app.css' );
mix.mix.webpackConfig(
{
externals: {
"@wordpress/i18n": [ "wp", "i18n" ]
}
}
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment