diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..98b5d37df20420b4e0660d3eaff4510082ea85aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor/ +.idea +build-coverage +swagger +composer.lock \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..a23f1c1b0d8fcf0a5336528329d083a8c57e8730 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,10 @@ +variables: + DISABLE_ACCEPTANCE: 1 + DISABLE_FUNCTIONAL: 1 + DISABLE_CODECEPTION: 1 + DISABLE_INTEGRATION_TESTS: 1 + IS_LIBRARY: 1 + DISABLE_PHP_5_5: 1 + +include: 'https://gitlab.com/wpdesk/gitlab-ci/raw/master/gitlab-ci-1.2.yml' + diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..a38f6c673ebf42d1f82d4a5b412bbb70a320d8ca --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## [1.0.0] - 2021-08-05 +### Added +- Init \ No newline at end of file diff --git a/README.md b/README.md index 303cc7d8a18f19e260c4b4207116395ce6d55fe3..78be485a52e2ed8868d8fc4162d303ebc653e175 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ +[](https://gitlab.com/wpdesk/wp-wpdesk-activation-reminder/commits/master) +Integration: [](https://gitlab.com/wpdesk/wp-wpdesk-activation-reminder/commits/master) +Unit: [](https://gitlab.com/wpdesk/wp-wpdesk-activation-reminder/commits/master) + # wp-wpdesk-activation-reminder +## Usage + +```bash +composer require --dev wpdesk/wp-wpdesk-activation-reminder + +composer update +``` \ No newline at end of file diff --git a/apigen.neon b/apigen.neon new file mode 100644 index 0000000000000000000000000000000000000000..3cddd91f341529a26febc4c6fac4562edffcb9f0 --- /dev/null +++ b/apigen.neon @@ -0,0 +1,27 @@ +destination: docs +templateConfig: /app/theme-woocommerce/config.neon +extensions: [php] +source: + - classes +exclude: + - vendor + - tests + - languages + +charset: [UTF-8] +main: Wordpress plugin +title: Plugin template more info +baseUrl: "/" + +templateTheme: default +php: false +sourceCode: false +tree: true +deprecated: false +todo: false +download: false + +accessLevels: + - public + - private + - protected \ No newline at end of file diff --git a/composer.json b/composer.json index 525bddae9ad8bb081861e5c50d71e4e61e0def18..fae4ca9bda9f61a07ec39a170d7068fad93ff531 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "wpdesk/wp-wpdesk-activation-reminder", + "type": "composer-plugin", "authors": [ { "name": "Krzysiek", @@ -11,9 +12,11 @@ } ], "require": { - "php": ">=7.0" + "php": ">=7.0", + "composer-plugin-api": "^1|^2" }, "require-dev": { + "composer/composer": "^1|^2", "phpunit/phpunit": "<7", "mockery/mockery": "^1.2", "10up/wp_mock": "^0.3" @@ -26,7 +29,8 @@ "autoload-dev": { }, "extra": { - "text-domain": "wp-wpdesk-fs-table-rate", + "class": "WPDesk\\ActivationReminder\\Composer\\Plugin", + "text-domain": "wp-wpdesk-activation-reminder", "translations-folder": "lang", "po-files": { "pl_PL": "pl_PL.po" diff --git a/lang/pl_PL.po b/lang/pl_PL.po new file mode 100644 index 0000000000000000000000000000000000000000..efbe39e0806542cf82a7d02fbd7d770d082b3a54 --- /dev/null +++ b/lang/pl_PL.po @@ -0,0 +1,27 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-07-29 12:26+0200\n" +"PO-Revision-Date: 2021-07-29 12:27+0200\n" +"Last-Translator: Krzysztof Dyszczyk <krzysztof.dyszczyk@gmail.com>\n" +"Language-Team: Polish (Poland)\n" +"Language: pl_PL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10 >= 2 && n%10<=4 &&(n" +"%100<10||n%100 >= 20)? 1 : 2);\n" +"X-Loco-Source-Locale: en_PL\n" +"X-Poedit-Basepath: ..\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;" +"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" +"_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"X-Generator: Poedit 3.0\n" +"X-Loco-Parser: loco_parse_po\n" +"X-Poedit-SearchPath-0: .\n" +"X-Poedit-SearchPathExcluded-0: *.js\n" +"X-Poedit-SearchPathExcluded-1: vendor_prefixed\n" +"X-Poedit-SearchPathExcluded-2: vendor\n" + diff --git a/phpunit-integration.xml b/phpunit-integration.xml new file mode 100644 index 0000000000000000000000000000000000000000..4a342abf125d638d044bafa01cd9a75a771b4b3d --- /dev/null +++ b/phpunit-integration.xml @@ -0,0 +1,28 @@ +<phpunit bootstrap="tests/integration/bootstrap.php" + backupGlobals="false" + > + <testsuites> + <testsuite> + <directory prefix="Test" suffix=".php">./tests/integration</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory suffix=".php">src</directory> + </whitelist> + </filter> + + <logging> + <log type="junit" target="build-coverage/report.junit.xml"/> + <log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/> + <log type="coverage-text" target="build-coverage/coverage.txt"/> + <log type="coverage-clover" target="build-coverage/clover.xml"/> + </logging> + + <php> + <env name="WP_DEVELOP_DIR" value="/tmp/wordpress-develop"/> + <env name="WC_DEVELOP_DIR" value="/tmp/woocommerce"/> + </php> + +</phpunit> \ No newline at end of file diff --git a/phpunit-unit.xml b/phpunit-unit.xml new file mode 100644 index 0000000000000000000000000000000000000000..31e5c9f9c202769cac9487ac192f331e827c9489 --- /dev/null +++ b/phpunit-unit.xml @@ -0,0 +1,21 @@ +<phpunit bootstrap="tests/unit/bootstrap.php"> + <testsuites> + <testsuite> + <directory prefix="Test" suffix=".php">./tests/unit/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory suffix=".php">src</directory> + </whitelist> + </filter> + + <logging> + <log type="junit" target="build-coverage/report.junit.xml"/> + <log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/> + <log type="coverage-text" target="build-coverage/coverage.txt"/> + <log type="coverage-clover" target="build-coverage/clover.xml"/> + </logging> + +</phpunit> diff --git a/src/ActivationReminder/Composer/CommandProvider.php b/src/ActivationReminder/Composer/CommandProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..d25a1978351227a8ff72bb8e5415bc8078b55b58 --- /dev/null +++ b/src/ActivationReminder/Composer/CommandProvider.php @@ -0,0 +1,18 @@ +<?php + +namespace WPDesk\ActivationReminder\Composer; + +/** + * Links plugin commands handlers to composer + * + * @package WPDesk\ActivationReminder\Composer + */ +class CommandProvider implements \Composer\Plugin\Capability\CommandProvider +{ + public function getCommands() + { + return [ + new PrepareActivationReminderCommand(), + ]; + } +} \ No newline at end of file diff --git a/src/ActivationReminder/Composer/Plugin.php b/src/ActivationReminder/Composer/Plugin.php new file mode 100644 index 0000000000000000000000000000000000000000..60b554b275956b4f70f2cc13d76b1cf89e0d2de3 --- /dev/null +++ b/src/ActivationReminder/Composer/Plugin.php @@ -0,0 +1,88 @@ +<?php + +namespace WPDesk\ActivationReminder\Composer; + +use Composer\Composer; +use Composer\EventDispatcher\EventSubscriberInterface; +use Composer\IO\IOInterface; +use Composer\EventDispatcher\Event; +use Composer\Plugin\Capable; +use Composer\Plugin\PluginInterface; +use Composer\Script\ScriptEvents; + +/** + * Main plugin class - initializes everything. + * + * @package WPDesk\Composer\GitPlugin + */ +class Plugin implements PluginInterface, Capable, EventSubscriberInterface { + + const PRIORITY_RUN_LAST = 1; + + /** + * @var Composer + */ + private $composer; + + /** + * @var IOInterface + */ + private $io; + + /** + * @inheritDoc + */ + public static function getSubscribedEvents(): array { + return [ + ScriptEvents::POST_INSTALL_CMD => [ + [ 'generateReminder', self::PRIORITY_RUN_LAST ], + ], + ScriptEvents::POST_UPDATE_CMD => [ + [ 'generateReminder', self::PRIORITY_RUN_LAST ], + ] + ]; + } + + /** + * @inheritDoc + */ + public function activate( Composer $composer, IOInterface $io ) { + $this->composer = $composer; + $this->io = $io; + } + + /** + * @inheritDoc + */ + public function deactivate( Composer $composer, IOInterface $io ) { + $this->composer = $composer; + $this->io = $io; + } + + /** + * @inheritDoc + */ + public function uninstall(Composer $composer, IOInterface $io) + { + $this->composer = $composer; + $this->io = $io; + } + + /** + * @inheritDoc + */ + public function getCapabilities(): array + { + return [ + \Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class + ]; + } + + /** + * @param Event $event + */ + public function generateReminder(Event $event) { + passthru("composer prepare-activation-reminder"); + } + +} diff --git a/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php b/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..3a4af8c4e9d251392fc9ce0eb0209983b8e4b4b9 --- /dev/null +++ b/src/ActivationReminder/Composer/PrepareActivationReminderCommand.php @@ -0,0 +1,154 @@ +<?php + +namespace WPDesk\ActivationReminder\Composer; + +use Composer\Command\BaseCommand; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Can prepare activation reminder for plugin. + * + * @package WPDesk\Composer\GitPlugin\Command + */ +class PrepareActivationReminderCommand extends BaseCommand +{ + + protected function configure() + { + $this + ->setName('prepare-activation-reminder') + ->setDescription('Prepares activation reminder for WP Desk plugin.'); + } + + /** + * Execute command. + * + * @param InputInterface $input + * @param OutputInterface $output + * @return int|void|null + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln("Creating activation reminder."); + + $classLoader = require('vendor/autoload.php'); + + $class_map = $classLoader->getClassMap(); + + $random_class = $this->get_random_class( $class_map ); + + $random_letter = strtolower( chr( rand( 65, 90 ) ) ); + + $target_file = $class_map[ $random_class ]; + $target_file = str_replace( '.php', $random_letter . '.php', $target_file ); + $target_file = str_replace( getcwd() . '/vendor/composer/../../', '', $target_file ); + + $output->writeln("Target file name: $target_file"); + + $this->clear_vendor_prefixed(); + + passthru( 'composer generate-vendor-prefixed' ); + + copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/src/Reminder.php', $target_file ); + + $this->regenerate_autoload( $target_file ); + + $this->prepare_class( $random_class . $random_letter, $target_file ); + + $output->writeln("Activation reminder created."); + } + + /** + * @param string $class_file + */ + private function regenerate_autoload( $class_file ) { + $composer = $this->getComposer(); + $config = $composer->getConfig(); + $localRepo = $composer->getRepositoryManager()->getLocalRepository(); + $package = $composer->getPackage(); + $installationManager = $composer->getInstallationManager(); + $optimize = $config->get('optimize-autoloader'); + + $autoload = $package->getAutoload(); + $autoload['files'] = isset( $autoload['files'] ) ? $autoload['files'] : []; + $autoload['files'][] = $class_file; + $package->setAutoload( $autoload ); + + $composer->getAutoloadGenerator()->dump( $config, $localRepo, $package, $installationManager, 'composer', $optimize ); + } + + /** + * @param string $class_name + * @param string $class_file + */ + private function prepare_class( $class_name, $class_file ) { + $namespace = $this->prepare_namespace_from_class_name( $class_name ); + $short_classname = $this->prepare_short_class_name_from_class_name( $class_name ); + + $file_contents = file_get_contents( $class_file ); + $file_contents = str_replace( 'namespace ReminderNamespace;', 'namespace ' . $namespace . ';', $file_contents ); + $file_contents = str_replace( 'class Reminder', 'class ' . $short_classname, $file_contents ); + $file_contents = str_replace( 'new Reminder();', 'new ' . $short_classname . '();', $file_contents ); + file_put_contents( $class_file, $file_contents ); + } + + /** + * @param string $class_name + * + * @return string + */ + private function prepare_namespace_from_class_name( $class_name ) { + $exploded = explode( '\\', $class_name ); + unset( $exploded[ count( $exploded ) - 1 ] ); + + return implode( '\\', $exploded ); + } + + /** + * @param string $class_name + * + * @return string + */ + private function prepare_short_class_name_from_class_name( $class_name ) { + $exploded = explode( '\\', $class_name ); + + return $exploded[ count( $exploded ) - 1 ]; + } + + /** + * @param array $class_map + * + * @return string + */ + private function get_random_class( $class_map ) { + do { + $class_name = array_rand( $class_map ); + } while ( strpos( $class_map[ $class_name ], '../../vendor_prefixed/wpdesk' ) === false ); + + return $class_name; + } + + /** + * + */ + private function clear_vendor_prefixed() { + $this->delete_all( 'vendor_prefixed' ); + } + + /** + * @param string $dir + */ + private function delete_all( $dir ) { + foreach ( glob( $dir . '/*' ) as $file ) { + if ( is_dir( $file ) ) { + $this->delete_all( $file ); + } else { + unlink( $file ); + } + } + rmdir( $dir ); + } + +} diff --git a/src/Reminder.php b/src/Reminder.php new file mode 100644 index 0000000000000000000000000000000000000000..4f1c76bb84b0de63ac0bf66b933b60932d528813 --- /dev/null +++ b/src/Reminder.php @@ -0,0 +1,17 @@ +<?php + +namespace ReminderNamespace; + +class Reminder { + + public function __construct() { + add_action( 'admin_footer', array( $this, 'admin_footer' ) ); + } + + public function admin_footer() { + echo "<!-- footer reminder -->\n"; + } + +} + +new Reminder(); diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9751c73e133c5ed879aeccb7435e5065797f712c --- /dev/null +++ b/tests/docker-compose.yaml @@ -0,0 +1,172 @@ +version: '2.0' + +services: + + wordpress: + image: wpdesknet/phpunit-woocommerce:0-0 + volumes: + - .././:/opt/project + depends_on: + - mysql0 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql0 + + wordpress-0-1: + image: wpdesknet/phpunit-woocommerce:0-1 + volumes: + - .././:/opt/project + depends_on: + - mysql1 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql1 + + wordpress-0-2: + image: wpdesknet/phpunit-woocommerce:0-2 + volumes: + - .././:/opt/project + depends_on: + - mysql2 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql2 + + wordpress-0-3: + image: wpdesknet/phpunit-woocommerce:0-3 + volumes: + - .././:/opt/project + depends_on: + - mysql3 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql3 + + wordpress-0-4: + image: wpdesknet/phpunit-woocommerce:0-4 + volumes: + - .././:/opt/project + depends_on: + - mysql4 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql4 + + wordpress-0-5: + image: wpdesknet/phpunit-woocommerce:0-5 + volumes: + - .././:/opt/project + depends_on: + - mysql5 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql5 + + wordpress-1-0: + image: wpdesknet/phpunit-woocommerce:1-0 + volumes: + - .././:/opt/project + depends_on: + - mysql0 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql0 + + wordpress-2-0: + image: wpdesknet/phpunit-woocommerce:2-0 + volumes: + - .././:/opt/project + depends_on: + - mysql0 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql0 + + wordpress-3-0: + image: wpdesknet/phpunit-woocommerce:3-0 + volumes: + - .././:/opt/project + depends_on: + - mysql0 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql0 + + wordpress-4-0: + image: wpdesknet/phpunit-woocommerce:4-0 + volumes: + - .././:/opt/project + depends_on: + - mysql0 + environment: + WORDPRESS_DB_NAME: wptest + WORDPRESS_DB_USER: mysql + WORDPRESS_DB_PASSWORD: mysql + WORDPRESS_DB_HOST: mysql0 + + mysql0: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + + mysql1: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + + mysql2: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + + mysql3: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + + mysql4: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + + mysql5: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wptest + MYSQL_USER: mysql + MYSQL_PASSWORD: mysql + diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..31dc891a1cef8175feca82e47cb5962cda912c9d --- /dev/null +++ b/tests/integration/bootstrap.php @@ -0,0 +1,30 @@ +<?php + +ini_set( 'error_reporting', E_ALL ); // or error_reporting(E_ALL); +ini_set( 'display_errors', '1' ); +ini_set( 'display_startup_errors', '1' ); + +require_once __DIR__ . '/../../vendor/autoload.php'; + +// disable xdebug backtrace +if ( function_exists( 'xdebug_disable' ) ) { + xdebug_disable(); +} + +if ( getenv( 'PLUGIN_PATH' ) !== false ) { + define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) ); +} else { + define( 'PLUGIN_PATH', __DIR__ . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ); +} + +require_once( getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/functions.php' ); + +tests_add_filter( 'muplugins_loaded', + function () { + }, + 100 ); + +putenv( 'WP_TESTS_DIR=' . getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit' ); +require_once( getenv( 'WC_DEVELOP_DIR' ) . '/tests/bootstrap.php' ); + +do_action( 'plugins_loaded' ); \ No newline at end of file diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..76b8109582ae17560b77a6e0499b232e09047810 --- /dev/null +++ b/tests/unit/bootstrap.php @@ -0,0 +1,9 @@ +<?php +/** + * PHPUnit bootstrap file + */ + +require_once __DIR__ . '/../../vendor/autoload.php'; + +WP_Mock::setUsePatchwork( true ); +WP_Mock::bootstrap();