Skip to content
Snippets Groups Projects
Commit dd30ea8d authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Feature/wpdesk notices action

parent 437e2cbd
No related branches found
No related tags found
No related merge requests found
Showing
with 607 additions and 359 deletions
test export-ignore .git/ export-ignore
vendor export-ignore tests/ export-ignore
vendor/ export-ignore
.editorconfig export-ignore .editorconfig export-ignore
.gitattributes export-ignore .gitattributes export-ignore
.gitignore export-ignore .gitignore export-ignore
.git export-ignore
.gitlab-ci.yml export-ignore .gitlab-ci.yml export-ignore
.idea export-ignore .idea export-ignore
apigen.neon export-ignore apigen.neon export-ignore
build-coverage export-ignore
docs export-ignore
LICENSE.md export-ignore
phpcs.xml.dist export-ignore phpcs.xml.dist export-ignore
phpunit-integration.xml export-ignore phpunit-integration.xml export-ignore
phpunit-unit.xml export-ignore phpunit-unit.xml export-ignore
variables: variables:
WPDESK_CI_VERSION: 1.10.19 DISABLE_FUNCTIONAL: 1
MYSQL_ROOT_PASSWORD: mysql DISABLE_ACCEPTANCE: 1
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_INNODB_LOG_BUFFER_SIZE: 32M
PHP_ERROR_REPORTING: E_ALL
COMPOSER_ALLOW_SUPERUSER: 1
GIT_STRATEGY: fetch
ACCEPTANCE_ERROR_PATH: ${CI_PROJECT_DIR}/acceptance
stages: include: 'https://gitlab.com/wpdesk/gitlab-ci/raw/master/gitlab-ci-1.2.yml'
- tools
- tests
- pre-deploy
- deploy
.template: &job-test-template
stage: tests
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
.template: &job-test-integration-template
<<: *job-test-template
services:
- mysql:5.6
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- if [[ -f tests/integration/prepare.sh ]]; then sh tests/integration/prepare.sh; fi
- vendor/bin/phpunit --configuration phpunit-integration.xml --coverage-text --colors=never
only:
- tags
- master
.template: &job-test-integration-template-fast
<<: *job-test-integration-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- if [[ -f tests/integration/prepare.sh ]]; then sh tests/integration/prepare.sh; fi
- vendor/bin/phpunit --configuration phpunit-integration.xml --no-coverage
except:
- tags
only:
.template: &job-test-unit-template
<<: *job-test-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- vendor/bin/phpunit --configuration phpunit-unit.xml --coverage-text --colors=never
only:
- tags
.template: &job-test-unit-template-fast
<<: *job-test-unit-template
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- php --version
- cat /tmp/wordpress-develop/src/wp-includes/version.php
- cat /tmp/woocommerce/woocommerce.php
- composer update --no-progress
- vendor/bin/phpunit --configuration phpunit-unit.xml --no-coverage
except:
- tags
only:
.template: &job-deploy-template
image: wpdesknet/amazon-svn-deploy
stage: deploy
dependencies:
- build to deploy
- unit test lastest coverage
- integration test lastest coverage
retry: 2
when: manual
only:
- tags
before_script:
- cd ${CI_PROJECT_DIR}
phpmetric metrics:
stage: tools
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
when: manual
artifacts:
when: always
expire_in: 1 month
name: "metrics"
paths:
- ${CI_PROJECT_DIR}/phpmetric
script:
- echo ${WPDESK_CI_VERSION}
- composer require phpmetrics/phpmetrics
- composer update --no-progress
- php ./vendor/bin/phpmetrics --report-html=phpmetric .
churn metrics:
stage: tools
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
when: manual
script:
- echo ${WPDESK_CI_VERSION}
- composer require bmitch/churn-php
- composer update --no-progress
- vendor/bin/churn run classes inc
#code style test:
# stage: tests
# image: wpdesknet/phpunit-woocommerce:0-0
# allow_failure: true
# script:
# - echo ${WPDESK_CI_VERSION}
# - composer update --no-progress
# - vendor/bin/phpcs
unit test lastest:
<<: *job-test-unit-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
integration test lastest:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
unit test lastest coverage:
<<: *job-test-unit-template
image: wpdesknet/phpunit-woocommerce:0-0
integration test lastest coverage:
<<: *job-test-integration-template
image: wpdesknet/phpunit-woocommerce:0-0
integration test php7-1 wc-1:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:1-1
integration test php7 wc-2:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:2-2
integration test php-7 wc-3:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:2-3
integration test php5-6:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:3-0
integration test php5-5:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:4-0
integration test current woocommerce:
<<: *job-test-integration-template-fast
image: wpdesknet/phpunit-woocommerce:0-0
allow_failure: true
before_script:
- cd /tmp
- rm -rf woocommerce
- git clone https://github.com/woocommerce/woocommerce.git
- cd ${CI_PROJECT_DIR}
apigen docs:
image:
name: wpdesknet/apigen
stage: pre-deploy
artifacts:
expire_in: 1 day
name: "docs"
paths:
- docs/
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- /app/vendor/bin/apigen generate
- php /app/hooks-docs.php ${CI_PROJECT_DIR}
only:
- tags
pages:
stage: deploy
dependencies:
- apigen docs
script:
- rm -rf public
- mv docs/ public/
- 'curl -X POST --data-urlencode "payload={\"text\": \"Dokumentacja projektu ${CI_PROJECT_NAME} w wersji ${CI_COMMIT_REF_NAME} umieszczona w <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}/pages|pages> \", }" https://hooks.slack.com/services/${SLACK_AUTH}'
artifacts:
expire_in: 1 day
paths:
- public
only:
- tags
build to deploy:
image: wpdesknet/phpunit-woocommerce:4-0
stage: pre-deploy
artifacts:
expire_in: 1 month
name: "production release"
paths:
- release
- release.zip
script:
- echo ${WPDESK_CI_VERSION}
- php --version
- ls -l
- /tmp/set_version.sh ${CI_COMMIT_REF_NAME}
- rm -rf ${CI_PROJECT_DIR}/release ${CI_PROJECT_DIR}/release.zip /tmp/release
- mkdir /tmp/release
- mkdir -p ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- cp -rf ${CI_PROJECT_DIR}/* /tmp/release
- cp -rf /tmp/release/* ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- cd ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- composer install --no-dev --no-progress --optimize-autoloader
- rm -rf build-coverage release tests docs .git .editorconfig .gitignore .gitlab-ci.yml apigen.neon phpunit.xml acceptance test_soap.php .gitlab
- rm -rf composer.json composer.lock phpcs.xml.dist phpunit-integration.xml phpunit-unit.xml composer.phar wp-cli.phar
- cd ../
- zip -r -q ../release.zip ./
only:
- tags
deploy to shop:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- /tmp/deploy_shop.sh ${CI_PROJECT_NAME} release.zip ${CI_PROJECT_NAME}.zip
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do sklepu w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wpdesk shop
url: https://wpdeskplugin.s3.amazonaws.com/${CI_PROJECT_NAME}.zip
deploy to demo:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- /tmp/deploy_demo.sh release/${CI_PROJECT_NAME} ${CI_PROJECT_NAME}
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do demo w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wpdesk demo
url: https://demo.wpdesk.org
deploy to repository:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- rm -rf /tmp/svn-repository
- mkdir /tmp/svn-repository
- /tmp/deploy_repository.sh ${CI_PROJECT_NAME} ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME} /tmp/svn-repository
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do repozytorium WP w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wordpress repository
url: https://downloads.wordpress.org/plugin/${CI_PROJECT_NAME}.${CI_COMMIT_REF_NAME}.zip
...@@ -37,7 +37,7 @@ require_once 'vendor/autoload.php'; ...@@ -37,7 +37,7 @@ require_once 'vendor/autoload.php';
If you do not wish to use Composer, you can download the latest release. Then, to use the Notices, include the init.php file. If you do not wish to use Composer, you can download the latest release. Then, to use the Notices, include the init.php file.
```php ```php
require_once('/path/to/notice/src/init.php'); require_once('/path/to/notice/src/notice-init.php');
``` ```
## Getting Started ## Getting Started
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
], ],
"require": { "require": {
"php": ">=5.5", "php": ">=5.5",
"wpdesk/wp-basic-requirements": "^2.0",
"wpdesk/wp-builder": "^1.0" "wpdesk/wp-builder": "^1.0"
}, },
"require-dev": { "require-dev": {
...@@ -26,7 +25,7 @@ ...@@ -26,7 +25,7 @@
}, },
"autoload": { "autoload": {
"psr-4": {"WPDesk\\Notice\\": "src/WPDesk/Notice/"}, "psr-4": {"WPDesk\\Notice\\": "src/WPDesk/Notice/"},
"files": ["src/WPDesk/functions.php"] "files": ["src/WPDesk/notice-functions.php"]
}, },
"autoload-dev": { "autoload-dev": {
}, },
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<directory suffix=".php">src</directory> <directory suffix=".php">src</directory>
<exclude> <exclude>
<file>src/init.php</file> <file>src/init.php</file>
<directory>src/assets</directory>
<directory suffix=".php">tests</directory> <directory suffix=".php">tests</directory>
<directory suffix=".php">vendor</directory> <directory suffix=".php">vendor</directory>
</exclude> </exclude>
......
...@@ -23,7 +23,7 @@ class Factory ...@@ -23,7 +23,7 @@ class Factory
*/ */
public static function notice($noticeContent = '', $noticeType = 'info', $isDismissible = false, $priority = 10) public static function notice($noticeContent = '', $noticeType = 'info', $isDismissible = false, $priority = 10)
{ {
return new Notice($noticeType, $noticeContent, $isDismissible, $priority); return new Notice($noticeContent, $noticeType, $isDismissible, $priority);
} }
/** /**
...@@ -38,11 +38,11 @@ class Factory ...@@ -38,11 +38,11 @@ class Factory
*/ */
public static function permanentDismissibleNotice( public static function permanentDismissibleNotice(
$noticeContent = '', $noticeContent = '',
$noticeType = '',
$noticeName = '', $noticeName = '',
$noticeType = '',
$priority = 10 $priority = 10
) { ) {
return new PermanentDismissibleNotice($noticeType, $noticeContent, $noticeName, $priority); return new PermanentDismissibleNotice($noticeContent, $noticeName, $noticeType, $priority);
} }
} }
...@@ -16,6 +16,8 @@ class Notice ...@@ -16,6 +16,8 @@ class Notice
const NOTICE_TYPE_SUCCESS = 'success'; const NOTICE_TYPE_SUCCESS = 'success';
const NOTICE_TYPE_INFO = 'info'; const NOTICE_TYPE_INFO = 'info';
const ADMIN_FOOTER_BASE_PRIORITY = 9999999;
/** /**
* Notice type. * Notice type.
* *
...@@ -156,18 +158,42 @@ class Notice ...@@ -156,18 +158,42 @@ class Notice
{ {
if (!$this->actionAdded) { if (!$this->actionAdded) {
add_action('admin_notices', [$this, 'showNotice'], $this->priority); add_action('admin_notices', [$this, 'showNotice'], $this->priority);
add_action(
'admin_footer',
[$this, 'showNotice'],
self::ADMIN_FOOTER_BASE_PRIORITY + intval($this->priority)
);
$this->actionAdded = true; $this->actionAdded = true;
} }
} }
/**
* Remove action.
*/
protected function removeAction() protected function removeAction()
{ {
if ($this->actionAdded) { if ($this->actionAdded) {
remove_action('admin_notices', [$this, 'showNotice'], $this->priority); remove_action('admin_notices', [$this, 'showNotice'], $this->priority);
remove_action(
'admin_footer',
[$this, 'showNotice'],
self::ADMIN_FOOTER_BASE_PRIORITY + intval($this->priority)
);
$this->actionAdded = false; $this->actionAdded = false;
} }
} }
/**
* Add attribute.
*
* @param string $name Name
* @param string $value Value.
*/
public function addAttribute($name, $value)
{
$this->attributes[ $name ] = $value;
}
/** /**
* Get notice class. * Get notice class.
* *
...@@ -221,6 +247,7 @@ class Notice ...@@ -221,6 +247,7 @@ class Notice
*/ */
public function showNotice() public function showNotice()
{ {
$this->removeAction();
$noticeFormat = '<div %1$s>%2$s</div>'; $noticeFormat = '<div %1$s>%2$s</div>';
if ($this->addParagraphToContent()) { if ($this->addParagraphToContent()) {
$noticeFormat = '<div %1$s><p>%2$s</p></div>'; $noticeFormat = '<div %1$s><p>%2$s</p></div>';
......
...@@ -28,13 +28,18 @@ class PermanentDismissibleNotice extends Notice ...@@ -28,13 +28,18 @@ class PermanentDismissibleNotice extends Notice
* WPDesk_Flexible_Shipping_Notice constructor. * WPDesk_Flexible_Shipping_Notice constructor.
* *
* @param string $noticeContent Notice content. * @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param string $noticeName Notice dismiss option name. * @param string $noticeName Notice dismiss option name.
* @param string $noticeType Notice type.
* @param int $priority Priority * @param int $priority Priority
* @param array $attributes Attributes. * @param array $attributes Attributes.
*/ */
public function __construct($noticeContent, $noticeType, $noticeName, $priority = 10, $attributes = array()) public function __construct(
{ $noticeContent,
$noticeName,
$noticeType = 'info',
$priority = 10,
$attributes = array()
) {
parent::__construct($noticeContent, $noticeType, true, $priority, $attributes); parent::__construct($noticeContent, $noticeType, true, $priority, $attributes);
$this->noticeName = $noticeName; $this->noticeName = $noticeName;
$this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName; $this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
...@@ -61,6 +66,7 @@ class PermanentDismissibleNotice extends Notice ...@@ -61,6 +66,7 @@ class PermanentDismissibleNotice extends Notice
{ {
$attributesAsString = parent::getAttributesAsString(); $attributesAsString = parent::getAttributesAsString();
$attributesAsString .= sprintf(' data-notice-name="%1$s"', esc_attr($this->noticeName)); $attributesAsString .= sprintf(' data-notice-name="%1$s"', esc_attr($this->noticeName));
$attributesAsString .= sprintf(' id="wpdesk-notice-%1$s"', esc_attr($this->noticeName));
return $attributesAsString; return $attributesAsString;
} }
......
<?php
/**
* Creates Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNotice($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice($noticeContent, $noticeType, $dismissible, $priority);
}
/**
* Creates Notice.
*
* Alias for {@see WPDeskNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
{
return WPDeskNotice($noticeContent, $noticeType, $dismissible, $priority);
}
/**
* Creates Permanent Dismissible Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskPermanentDismissibleNotice($noticeContent, $noticeType = 'info', $priority = 10)
{
return \WPDesk\Notice\Factory::permanentDismissibleNotice($noticeContent, $noticeType, $priority);
}
/**
* Creates Permanent Dismissible Notice.
*
* Alias for {@see WPDeskPermanentDismissibleNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_permanent_dismissible_notice($noticeContent, $noticeType = 'info', $priority = 10)
{
return WPDeskPermanentDismissibleNotice($noticeContent, $noticeType, $priority);
}
<?php
if (!function_exists('WPDeskNotice')) {
/**
* Creates Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNotice($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice($noticeContent, $noticeType, $dismissible, $priority);
}
}
if (!function_exists('wpdesk_notice')) {
/**
* Creates Notice.
*
* Alias for {@see WPDeskNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
{
return WPDeskNotice($noticeContent, $noticeType, $dismissible, $priority);
}
}
if (!function_exists('WPDeskNoticeInfo')) {
/**
* Creates Notice Info.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNoticeInfo($noticeContent, $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice(
$noticeContent,
\WPDesk\Notice\Notice::NOTICE_TYPE_INFO,
$dismissible,
$priority
);
}
}
if (!function_exists('wpdesk_notice_info')) {
/**
* Creates Notice Info.
*
* Alias for {@see WPDeskNoticeInfo()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice_info($noticeContent, $dismissible = false, $priority = 10)
{
return WPDeskNoticeInfo($noticeContent, $dismissible, $priority);
}
}
if (!function_exists('WPDeskNoticeError')) {
/**
* Creates Notice Error.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNoticeError($noticeContent, $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice(
$noticeContent,
\WPDesk\Notice\Notice::NOTICE_TYPE_ERROR,
$dismissible,
$priority
);
}
}
if (!function_exists('wpdesk_notice_error')) {
/**
* Creates Notice Error.
*
* Alias for {@see WPDeskNoticeError()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice_error($noticeContent, $dismissible = false, $priority = 10)
{
return WPDeskNoticeError($noticeContent, $dismissible, $priority);
}
}
if (!function_exists('WPDeskNoticeWarning')) {
/**
* Creates Notice Warning.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNoticeWarning($noticeContent, $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice(
$noticeContent,
\WPDesk\Notice\Notice::NOTICE_TYPE_WARNING,
$dismissible,
$priority
);
}
}
if (!function_exists('wpdesk_notice_warning')) {
/**
* Creates Notice Warning.
*
* Alias for {@see WPDeskNoticeWarning()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice_warning($noticeContent, $dismissible = false, $priority = 10)
{
return WPDeskNoticeWarning($noticeContent, $dismissible, $priority);
}
}
if (!function_exists('WPDeskNoticeSuccess')) {
/**
* Creates Notice Success.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskNoticeSuccess($noticeContent, $dismissible = false, $priority = 10)
{
return \WPDesk\Notice\Factory::notice(
$noticeContent,
\WPDesk\Notice\Notice::NOTICE_TYPE_SUCCESS,
$dismissible,
$priority
);
}
}
if (!function_exists('wpdesk_notice_success')) {
/**
* Creates Notice Success.
*
* Alias for {@see WPDeskNoticeSuccess()} function.
*
* @param string $noticeContent Notice content.
* @param bool $dismissible Dismissible notice.
* @param int $priority Notice priority,
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_notice_success($noticeContent, $dismissible = false, $priority = 10)
{
return WPDeskNoticeSuccess($noticeContent, $dismissible, $priority);
}
}
if (!function_exists('WPDeskPermanentDismissibleNotice')) {
/**
* Creates Permanent Dismissible Notice.
*
* @param string $noticeContent Notice content.
* @param string $noticeType Notice type.
* @param string $noticeName Notice name.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function WPDeskPermanentDismissibleNotice($noticeContent, $noticeName, $noticeType = 'info', $priority = 10)
{
return \WPDesk\Notice\Factory::permanentDismissibleNotice(
$noticeContent,
$noticeName,
$noticeType,
$priority
);
}
}
if (!function_exists('wpdesk_permanent_dismissible_notice')) {
/**
* Creates Permanent Dismissible Notice.
*
* Alias for {@see WPDeskPermanentDismissibleNotice()} function.
*
* @param string $noticeContent Notice content.
* @param string $noticeName Notice name.
* @param string $noticeType Notice type.
* @param int $priority Notice priority.
*
* @return \WPDesk\Notice\Notice
*/
function wpdesk_permanent_dismissible_notice($noticeContent, $noticeName, $noticeType = 'info', $priority = 10)
{
return WPDeskPermanentDismissibleNotice($noticeContent, $noticeName, $noticeType, $priority);
}
}
jQuery( document ).on( 'click', '.notice-dismiss', function() {
var notice_name = jQuery(this).closest('div.notice').data('notice-name');
console.log(notice_name);
if ('' !== notice_name) {
jQuery.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'wpdesk_notice_dismiss',
notice_name: notice_name
},
success: function (response) {
}
});
}
});
jQuery(document).on("click",".notice-dismiss",function(){var a=jQuery(this).closest("div.notice").data("notice-name");console.log(a);if(""!==a){jQuery.ajax({url:ajaxurl,type:"post",data:{action:"wpdesk_notice_dismiss",notice_name:a},success:function(b){}})}});
\ No newline at end of file
<?php
include './WPDesk/Notice/AjaxHandler.php';
include './WPDesk/Notice/Notice.php';
include './WPDesk/Notice/PermanentDismissibleNotice.php';
<?php
require_once './WPDesk/Notice/AjaxHandler.php';
require_once './WPDesk/Notice/Notice.php';
require_once './WPDesk/Notice/PermanentDismissibleNotice.php';
require_once './WPDesk/Notice/Factory.php';
require_once './WPDesk/Notice/functions.php';
version: '2.0'
services:
wordpress:
image: wpdesknet/phpunit-woocommerce:0-0
volumes:
- .././:/opt/project
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
- ../.././:/tmp/plugins
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
...@@ -14,9 +14,69 @@ class TestFunctions extends WP_UnitTestCase ...@@ -14,9 +14,69 @@ class TestFunctions extends WP_UnitTestCase
*/ */
public function testWPDeskNotice() public function testWPDeskNotice()
{ {
$notice = wpdesk_notice('test'); $notice = wpdesk_notice('test function');
$this->assertInstanceOf(Notice::class, $notice); $this->assertInstanceOf(Notice::class, $notice);
$this->expectOutputString('<div class="notice notice-info"><p>test function</p></div>');
$notice->showNotice();
}
/**
* Test WPDeskNoticeInfo function.
*/
public function testWPDeskNoticeInfo()
{
$notice = wpdesk_notice_info('test function');
$this->assertInstanceOf(Notice::class, $notice);
$this->expectOutputString('<div class="notice notice-info"><p>test function</p></div>');
$notice->showNotice();
}
/**
* Test WPDeskNoticeError function.
*/
public function testWPDeskNoticeError()
{
$notice = wpdesk_notice_error('test function');
$this->assertInstanceOf(Notice::class, $notice);
$this->expectOutputString('<div class="notice notice-error"><p>test function</p></div>');
$notice->showNotice();
}
/**
* Test WPDeskNoticeWarning function.
*/
public function testWPDeskNoticeWarning()
{
$notice = wpdesk_notice_warning('test function');
$this->assertInstanceOf(Notice::class, $notice);
$this->expectOutputString('<div class="notice notice-warning"><p>test function</p></div>');
$notice->showNotice();
}
/**
* Test WPDeskNoticeSuccess function.
*/
public function testWPDeskNoticeSuccess()
{
$notice = wpdesk_notice_success('test function');
$this->assertInstanceOf(Notice::class, $notice);
$this->expectOutputString('<div class="notice notice-success"><p>test function</p></div>');
$notice->showNotice();
} }
/** /**
...@@ -24,9 +84,19 @@ class TestFunctions extends WP_UnitTestCase ...@@ -24,9 +84,19 @@ class TestFunctions extends WP_UnitTestCase
*/ */
public function testWPDeskPermanentDismissibleNotice() public function testWPDeskPermanentDismissibleNotice()
{ {
$notice = wpdesk_permanent_dismissible_notice('test'); $notice = wpdesk_permanent_dismissible_notice(
'test function',
'test-notice',
Notice::NOTICE_TYPE_INFO
);
$this->assertInstanceOf(PermanentDismissibleNotice::class, $notice); $this->assertInstanceOf(PermanentDismissibleNotice::class, $notice);
$this->expectOutputString(
'<div class="notice notice-info is-dismissible" data-notice-name="test-notice" id="wpdesk-notice-test-notice"><p>test function</p></div>'
);
$notice->showNotice();
} }
} }
...@@ -12,6 +12,15 @@ class TestNotice extends WP_UnitTestCase ...@@ -12,6 +12,15 @@ class TestNotice extends WP_UnitTestCase
$notice = new Notice(Notice::NOTICE_TYPE_INFO, 'test', false, $notice_priority); $notice = new Notice(Notice::NOTICE_TYPE_INFO, 'test', false, $notice_priority);
$this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority)); $this->assertEquals($notice_priority, has_action('admin_notices', [$notice, 'showNotice'], $notice_priority));
$this->assertEquals(
Notice::ADMIN_FOOTER_BASE_PRIORITY + intval($notice_priority),
has_action(
'admin_footer',
[$notice, 'showNotice'],
Notice::ADMIN_FOOTER_BASE_PRIORITY + intval($notice_priority)
)
);
} }
public function testShowNotice() public function testShowNotice()
...@@ -21,6 +30,13 @@ class TestNotice extends WP_UnitTestCase ...@@ -21,6 +30,13 @@ class TestNotice extends WP_UnitTestCase
$this->expectOutputString('<div class="notice notice-info"><p>test</p></div>'); $this->expectOutputString('<div class="notice notice-info"><p>test</p></div>');
$notice->showNotice(); $notice->showNotice();
$this->assertFalse(
has_action('admin_notices', [$notice, 'showNotice'], 10)
);
$this->assertFalse(
has_action('admin_footer', [$notice, 'showNotice'], 10)
);
} }
public function testShowNoticeError() public function testShowNoticeError()
...@@ -102,4 +118,26 @@ class TestNotice extends WP_UnitTestCase ...@@ -102,4 +118,26 @@ class TestNotice extends WP_UnitTestCase
$this->assertEquals(20, $notice->getPriority()); $this->assertEquals(20, $notice->getPriority());
} }
public function testAddAttribute()
{
$notice = new Notice('test', Notice::NOTICE_TYPE_WARNING);
$notice->addAttribute('id', 'test_id');
$this->expectOutputString('<div class="notice notice-warning" id="test_id"><p>test</p></div>');
$notice->showNotice();
}
public function testAddAttributeClass()
{
$notice = new Notice('test', Notice::NOTICE_TYPE_WARNING);
$notice->addAttribute('class', 'test-class');
$this->expectOutputString('<div class="notice notice-warning test-class"><p>test</p></div>');
$notice->showNotice();
}
} }
...@@ -12,9 +12,9 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase ...@@ -12,9 +12,9 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase
$notice_priority = 11; $notice_priority = 11;
$notice = new PermanentDismissibleNotice( $notice = new PermanentDismissibleNotice(
PermanentDismissibleNotice::NOTICE_TYPE_INFO,
'test', 'test',
'test_name', 'test_name',
PermanentDismissibleNotice::NOTICE_TYPE_INFO,
$notice_priority $notice_priority
); );
...@@ -23,11 +23,13 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase ...@@ -23,11 +23,13 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase
public function testUndoDismiss() public function testUndoDismiss()
{ {
update_option(PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME, PermanentDismissibleNotice::OPTION_VALUE_DISMISSED); update_option(
PermanentDismissibleNotice::OPTION_NAME_PREFIX . self::NOTICE_NAME,
PermanentDismissibleNotice::OPTION_VALUE_DISMISSED
);
$notice = new PermanentDismissibleNotice( $notice = new PermanentDismissibleNotice(
PermanentDismissibleNotice::NOTICE_TYPE_INFO, PermanentDismissibleNotice::NOTICE_TYPE_INFO,
'test',
self::NOTICE_NAME self::NOTICE_NAME
); );
$notice->undoDismiss(); $notice->undoDismiss();
...@@ -42,12 +44,12 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase ...@@ -42,12 +44,12 @@ class TestPermanentDismissinleNotice extends WP_UnitTestCase
{ {
$notice = new PermanentDismissibleNotice( $notice = new PermanentDismissibleNotice(
'test', 'test',
PermanentDismissibleNotice::NOTICE_TYPE_INFO, 'test_name',
'test_name' PermanentDismissibleNotice::NOTICE_TYPE_INFO
); );
$this->expectOutputString( $this->expectOutputString(
'<div class="notice notice-info is-dismissible"data-notice-name="test_name"><p>test</p></div>' '<div class="notice notice-info is-dismissible" data-notice-name="test_name" id="wpdesk-notice-test_name"><p>test</p></div>'
); );
$notice->showNotice(); $notice->showNotice();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment