diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 570f3b9..fbe9ab3 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -44,8 +44,14 @@ + + + + + + @@ -74,41 +80,13 @@ - /src/facades/wordpress\.php$ + /src/Facades/wordpress\.php$ /tests/Unit/Doubles/WpCoreFunctionsMock\.php$ - - - - - - - - - - /tests/*\.php - - - - - - - - - - - - - - - /src/facades/wordpress\.php$ + /src/Facades/wordpress\.php$ - /src/messages/Whip_HostMessage\.php$ - /src/messages/Whip_UpgradePhpMessage\.php$ + /src/Messages/HostMessage\.php$ + /src/Messages/UpgradePhpMessage\.php$ - /src/Whip_Host\.php$ + /src/Host\.php$ + /src/Messages/UpgradePhpMessage\.php$ diff --git a/composer.json b/composer.json index c407e48..7aad5d8 100644 --- a/composer.json +++ b/composer.json @@ -28,11 +28,11 @@ "minimum-stability": "dev", "prefer-stable": true, "autoload": { - "classmap": [ - "src/" - ], + "psr-4": { + "Yoast\\WHIPv2\\": "src/" + }, "files": [ - "src/facades/wordpress.php" + "src/Facades/wordpress.php" ] }, "autoload-dev": { @@ -56,7 +56,7 @@ "Yoast\\WHIP\\Config\\Composer\\Actions::check_coding_standards" ], "check-cs-thresholds": [ - "@putenv YOASTCS_THRESHOLD_ERRORS=8", + "@putenv YOASTCS_THRESHOLD_ERRORS=10", "@putenv YOASTCS_THRESHOLD_WARNINGS=0", "Yoast\\WHIP\\Config\\Composer\\Actions::check_cs_thresholds" ], diff --git a/src/configs/default.php b/src/Configs/default.php similarity index 100% rename from src/configs/default.php rename to src/Configs/default.php diff --git a/src/configs/version.php b/src/Configs/version.php similarity index 100% rename from src/configs/version.php rename to src/Configs/version.php diff --git a/src/Whip_Configuration.php b/src/Configuration.php similarity index 54% rename from src/Whip_Configuration.php rename to src/Configuration.php index 97fa2c0..1d6fdc1 100644 --- a/src/Whip_Configuration.php +++ b/src/Configuration.php @@ -1,14 +1,14 @@ configuration = $configuration; @@ -35,12 +35,12 @@ public function __construct( $configuration = array() ) { /** * Retrieves the configured version of a particular requirement. * - * @param Whip_Requirement $requirement The requirement to check. + * @param Requirement $requirement The requirement to check. * * @return string|int The version of the passed requirement that was detected as a string. * If the requirement does not exist, this returns int -1. */ - public function configuredVersion( Whip_Requirement $requirement ) { + public function configuredVersion( Requirement $requirement ) { if ( ! $this->hasRequirementConfigured( $requirement ) ) { return -1; } @@ -51,11 +51,11 @@ public function configuredVersion( Whip_Requirement $requirement ) { /** * Determines whether the passed requirement is present in the configuration. * - * @param Whip_Requirement $requirement The requirement to check. + * @param Requirement $requirement The requirement to check. * * @return bool Whether or not the requirement is present in the configuration. */ - public function hasRequirementConfigured( Whip_Requirement $requirement ) { - return array_key_exists( $requirement->component(), $this->configuration ); + public function hasRequirementConfigured( Requirement $requirement ) { + return \array_key_exists( $requirement->component(), $this->configuration ); } } diff --git a/src/Exceptions/EmptyProperty.php b/src/Exceptions/EmptyProperty.php new file mode 100644 index 0000000..844372b --- /dev/null +++ b/src/Exceptions/EmptyProperty.php @@ -0,0 +1,20 @@ +', '<=', '>=' ) ) { parent::__construct( - sprintf( + \sprintf( 'Invalid operator of %s used. Please use one of the following operators: %s', $value, - implode( ', ', $validOperators ) + \implode( ', ', $validOperators ) ) ); } diff --git a/src/exceptions/Whip_InvalidType.php b/src/Exceptions/InvalidType.php similarity index 58% rename from src/exceptions/Whip_InvalidType.php rename to src/Exceptions/InvalidType.php index ad45e24..6ed1daf 100644 --- a/src/exceptions/Whip_InvalidType.php +++ b/src/Exceptions/InvalidType.php @@ -1,14 +1,13 @@ =5.3. Passed version comparison string: %s', $value ) diff --git a/src/facades/wordpress.php b/src/Facades/wordpress.php similarity index 60% rename from src/facades/wordpress.php rename to src/Facades/wordpress.php index 5bee96b..e5adc44 100644 --- a/src/facades/wordpress.php +++ b/src/Facades/wordpress.php @@ -5,6 +5,12 @@ * @package Yoast\WHIP */ +use Yoast\WHIPv2\MessageDismisser; +use Yoast\WHIPv2\Presenters\WPMessagePresenter; +use Yoast\WHIPv2\RequirementsChecker; +use Yoast\WHIPv2\VersionRequirement; +use Yoast\WHIPv2\WPDismissOption; + if ( ! function_exists( 'whip_wp_check_versions' ) ) { /** * Facade to quickly check if version requirements are met. @@ -19,11 +25,11 @@ function whip_wp_check_versions( $requirements ) { return; } - $config = include __DIR__ . '/../configs/default.php'; - $checker = new Whip_RequirementsChecker( $config ); + $config = include __DIR__ . '/../Configs/default.php'; + $checker = new RequirementsChecker( $config ); foreach ( $requirements as $component => $versionComparison ) { - $checker->addRequirement( Whip_VersionRequirement::fromCompareString( $component, $versionComparison ) ); + $checker->addRequirement( VersionRequirement::fromCompareString( $component, $versionComparison ) ); } $checker->check(); @@ -35,9 +41,9 @@ function whip_wp_check_versions( $requirements ) { $dismissThreshold = ( WEEK_IN_SECONDS * 4 ); $dismissMessage = __( 'Remind me again in 4 weeks.', 'default' ); - $dismisser = new Whip_MessageDismisser( time(), $dismissThreshold, new Whip_WPDismissOption() ); + $dismisser = new MessageDismisser( time(), $dismissThreshold, new WPDismissOption() ); - $presenter = new Whip_WPMessagePresenter( $checker->getMostRecentMessage(), $dismisser, $dismissMessage ); + $presenter = new WPMessagePresenter( $checker->getMostRecentMessage(), $dismisser, $dismissMessage ); // Prevent duplicate notices across multiple implementing plugins. if ( ! has_action( 'whip_register_hooks' ) ) { @@ -47,7 +53,7 @@ function whip_wp_check_versions( $requirements ) { /** * Fires during hooks registration for the message presenter. * - * @param Whip_WPMessagePresenter $presenter Message presenter instance. + * @param WPMessagePresenter $presenter Message presenter instance. */ do_action( 'whip_register_hooks', $presenter ); } diff --git a/src/Whip_Host.php b/src/Host.php similarity index 81% rename from src/Whip_Host.php rename to src/Host.php index af18121..fce2013 100644 --- a/src/Whip_Host.php +++ b/src/Host.php @@ -1,14 +1,11 @@ currentTime = $currentTime; $this->threshold = $threshold; $this->storage = $storage; @@ -71,6 +70,6 @@ public function isDismissed() { * @return bool True when the nonce is valid. */ public function verifyNonce( $nonce, $action ) { - return (bool) wp_verify_nonce( $nonce, $action ); + return (bool) \wp_verify_nonce( $nonce, $action ); } } diff --git a/src/Whip_MessageFormatter.php b/src/MessageFormatter.php similarity index 89% rename from src/Whip_MessageFormatter.php rename to src/MessageFormatter.php index b09c21e..b94d953 100644 --- a/src/Whip_MessageFormatter.php +++ b/src/MessageFormatter.php @@ -1,14 +1,11 @@ title() ) . '
'; - $message[] = Whip_MessageFormatter::paragraph( Whip_Host::message( $this->messageKey ) ); + $message[] = MessageFormatter::strong( $this->title() ) . '
'; + $message[] = MessageFormatter::paragraph( Host::message( $this->messageKey ) ); - return implode( "\n", $message ); + return \implode( "\n", $message ); } /** @@ -56,6 +57,6 @@ public function body() { */ public function title() { /* translators: 1: name. */ - return sprintf( __( 'A message from %1$s', $this->textdomain ), Whip_Host::name() ); + return \sprintf( \__( 'A message from %1$s', $this->textdomain ), Host::name() ); } } diff --git a/src/messages/Whip_InvalidVersionRequirementMessage.php b/src/Messages/InvalidVersionRequirementMessage.php similarity index 53% rename from src/messages/Whip_InvalidVersionRequirementMessage.php rename to src/Messages/InvalidVersionRequirementMessage.php index 1b33288..db30012 100644 --- a/src/messages/Whip_InvalidVersionRequirementMessage.php +++ b/src/Messages/InvalidVersionRequirementMessage.php @@ -1,19 +1,19 @@ requirement = $requirement; $this->detected = $detected; } @@ -41,7 +41,7 @@ public function __construct( Whip_VersionRequirement $requirement, $detected ) { * @return string Message. */ public function body() { - return sprintf( + return \sprintf( 'Invalid version detected for %s. Found %s but expected %s.', $this->requirement->component(), $this->detected, diff --git a/src/messages/Whip_NullMessage.php b/src/Messages/NullMessage.php similarity index 50% rename from src/messages/Whip_NullMessage.php rename to src/Messages/NullMessage.php index 1134036..bbb364c 100644 --- a/src/messages/Whip_NullMessage.php +++ b/src/Messages/NullMessage.php @@ -1,14 +1,13 @@ textdomain = $textdomain; + } + + /** + * Retrieves the message body to display. + * + * @return string The message to display. + */ + public function body() { + $textdomain = $this->textdomain; + + $message = array(); + + $message[] = MessageFormatter::strongParagraph( \__( 'Your site could be faster and more secure with a newer PHP version.', $textdomain ) ) . '
'; + $message[] = MessageFormatter::paragraph( \__( 'Hey, we\'ve noticed that you\'re running an outdated version of PHP. PHP is the programming language that WordPress and all its plugins and themes are built on. The version that is currently used for your site is no longer supported. Newer versions of PHP are both faster and more secure. In fact, your version of PHP no longer receives security updates, which is why we\'re sending you to this notice.', $textdomain ) ); + $message[] = MessageFormatter::paragraph( \__( 'Hosts have the ability to update your PHP version, but sometimes they don\'t dare to do that because they\'re afraid they\'ll break your site.', $textdomain ) ); + $message[] = MessageFormatter::strongParagraph( \__( 'To which version should I update?', $textdomain ) ) . '
'; + $message[] = MessageFormatter::paragraph( + \sprintf( + /* translators: 1: link open tag; 2: link close tag. */ + \__( 'You should update your PHP version to either 5.6 or to 7.0 or 7.1. On a normal WordPress site, switching to PHP 5.6 should never cause issues. We would however actually recommend you switch to PHP7. There are some plugins that are not ready for PHP7 though, so do some testing first. We have an article on how to test whether that\'s an option for you %1$shere%2$s. PHP7 is much faster than PHP 5.6. It\'s also the only PHP version still in active development and therefore the better option for your site in the long run.', $textdomain ), + '', + '' + ) + ); + + if ( Host::name() !== '' ) { + $hostMessage = new HostMessage( 'WHIP_MESSAGE_FROM_HOST_ABOUT_PHP', $textdomain ); + $message[] = $hostMessage->body(); + } + + $hostingPageUrl = Host::hostingPageUrl(); + + $message[] = MessageFormatter::strongParagraph( \__( 'Can\'t update? Ask your host!', $textdomain ) ) . '
'; + + if ( \function_exists( 'apply_filters' ) && \apply_filters( Host::HOSTING_PAGE_FILTER_KEY, false ) ) { + $message[] = MessageFormatter::paragraph( + \sprintf( + /* translators: 1: link open tag; 2: link close tag; 3: link open tag. */ + \__( 'If you cannot upgrade your PHP version yourself, you can send an email to your host. We have %1$sexamples here%2$s. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of the recommended %3$sWordPress hosting partners%2$s.', $textdomain ), + '', + '', + \sprintf( '', \esc_url( $hostingPageUrl ) ) + ) + ); + } + else { + $message[] = MessageFormatter::paragraph( + \sprintf( + /* translators: 1: link open tag; 2: link close tag; 3: link open tag. */ + \__( 'If you cannot upgrade your PHP version yourself, you can send an email to your host. We have %1$sexamples here%2$s. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of our recommended %3$sWordPress hosting partners%2$s, they\'ve all been vetted by the Yoast support team and provide all the features a modern host should provide.', $textdomain ), + '', + '', + \sprintf( '', \esc_url( $hostingPageUrl ) ) + ) + ); + } + + return \implode( "\n", $message ); + } +} diff --git a/src/Whip_MessagesManager.php b/src/MessagesManager.php similarity index 66% rename from src/Whip_MessagesManager.php rename to src/MessagesManager.php index da84e49..939c7ac 100644 --- a/src/Whip_MessagesManager.php +++ b/src/MessagesManager.php @@ -1,20 +1,20 @@ 0; + return isset( $GLOBALS['whip_messages'] ) && \count( $GLOBALS['whip_messages'] ) > 0; } /** @@ -62,18 +62,18 @@ public function deleteMessages() { /** * Gets the latest message. * - * @return Whip_Message The message. Returns a NullMessage if none is found. + * @return Message The message. Returns a NullMessage if none is found. */ public function getLatestMessage() { if ( ! $this->hasMessages() ) { - return new Whip_NullMessage(); + return new NullMessage(); } $messages = $this->sortByVersion( $this->listMessages() ); $this->deleteMessages(); - return array_pop( $messages ); + return \array_pop( $messages ); } /** @@ -84,7 +84,7 @@ public function getLatestMessage() { * @return array The sorted list of messages. */ private function sortByVersion( array $messages ) { - uksort( $messages, 'version_compare' ); + \uksort( $messages, 'version_compare' ); return $messages; } diff --git a/src/presenters/Whip_WPMessagePresenter.php b/src/Presenters/WPMessagePresenter.php similarity index 59% rename from src/presenters/Whip_WPMessagePresenter.php rename to src/Presenters/WPMessagePresenter.php index 17610fd..aa071f6 100644 --- a/src/presenters/Whip_WPMessagePresenter.php +++ b/src/Presenters/WPMessagePresenter.php @@ -1,14 +1,18 @@ message = $message; $this->dismisser = $dismisser; $this->dismissMessage = $dismissMessage; @@ -52,7 +56,7 @@ public function __construct( Whip_Message $message, Whip_MessageDismisser $dismi * @return void */ public function registerHooks() { - add_action( 'admin_notices', array( $this, 'renderMessage' ) ); + \add_action( 'admin_notices', array( $this, 'renderMessage' ) ); } /** @@ -61,21 +65,21 @@ public function registerHooks() { * @return void */ public function renderMessage() { - $dismissListener = new Whip_WPMessageDismissListener( $this->dismisser ); + $dismissListener = new WPMessageDismissListener( $this->dismisser ); $dismissListener->listen(); if ( $this->dismisser->isDismissed() ) { return; } - $dismissButton = sprintf( + $dismissButton = \sprintf( '%1$s', - esc_html( $this->dismissMessage ), - esc_url( $dismissListener->getDismissURL() ) + \esc_html( $this->dismissMessage ), + \esc_url( $dismissListener->getDismissURL() ) ); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- output correctly escaped directly above and in the `kses()` method. - printf( + \printf( '

%1$s

%2$s

', $this->kses( $this->message->body() ), $dismissButton @@ -91,7 +95,7 @@ public function renderMessage() { * @return string The cleaned message. */ public function kses( $message ) { - return wp_kses( + return \wp_kses( $message, array( 'a' => array( diff --git a/src/Whip_RequirementsChecker.php b/src/RequirementsChecker.php similarity index 67% rename from src/Whip_RequirementsChecker.php rename to src/RequirementsChecker.php index dabe06a..73f491b 100644 --- a/src/Whip_RequirementsChecker.php +++ b/src/RequirementsChecker.php @@ -1,14 +1,17 @@ requirements = array(); - $this->configuration = new Whip_Configuration( $configuration ); - $this->messageManager = new Whip_MessagesManager(); + $this->configuration = new Configuration( $configuration ); + $this->messageManager = new MessagesManager(); $this->textdomain = $textdomain; } /** * Adds a requirement to the list of requirements if it doesn't already exist. * - * @param Whip_Requirement $requirement The requirement to add. + * @param Requirement $requirement The requirement to add. * * @return void */ - public function addRequirement( Whip_Requirement $requirement ) { + public function addRequirement( Requirement $requirement ) { // Only allow unique entries to ensure we're not checking specific combinations multiple times. if ( $this->requirementExistsForComponent( $requirement->component() ) ) { return; @@ -84,7 +87,7 @@ public function hasRequirements() { * @return int The total amount of requirements. */ public function totalRequirements() { - return count( $this->requirements ); + return \count( $this->requirements ); } /** @@ -107,19 +110,19 @@ public function requirementExistsForComponent( $component ) { /** * Determines whether a requirement has been fulfilled. * - * @param Whip_Requirement $requirement The requirement to check. + * @param Requirement $requirement The requirement to check. * * @return bool Whether or not the requirement is fulfilled. */ - private function requirementIsFulfilled( Whip_Requirement $requirement ) { + private function requirementIsFulfilled( Requirement $requirement ) { $availableVersion = $this->configuration->configuredVersion( $requirement ); $requiredVersion = $requirement->version(); - if ( in_array( $requirement->operator(), array( '=', '==', '===' ), true ) ) { - return version_compare( $availableVersion, $requiredVersion, '>=' ); + if ( \in_array( $requirement->operator(), array( '=', '==', '===' ), true ) ) { + return \version_compare( $availableVersion, $requiredVersion, '>=' ); } - return version_compare( $availableVersion, $requiredVersion, $requirement->operator() ); + return \version_compare( $availableVersion, $requiredVersion, $requirement->operator() ); } /** @@ -143,17 +146,17 @@ public function check() { /** * Adds a message to the message manager for requirements that cannot be fulfilled. * - * @param Whip_Requirement $requirement The requirement that cannot be fulfilled. + * @param Requirement $requirement The requirement that cannot be fulfilled. * * @return void */ - private function addMissingRequirementMessage( Whip_Requirement $requirement ) { + private function addMissingRequirementMessage( Requirement $requirement ) { switch ( $requirement->component() ) { case 'php': - $this->messageManager->addMessage( new Whip_UpgradePhpMessage( $this->textdomain ) ); + $this->messageManager->addMessage( new UpgradePhpMessage( $this->textdomain ) ); break; default: - $this->messageManager->addMessage( new Whip_InvalidVersionRequirementMessage( $requirement, $this->configuration->configuredVersion( $requirement ) ) ); + $this->messageManager->addMessage( new InvalidVersionRequirementMessage( $requirement, $this->configuration->configuredVersion( $requirement ) ) ); break; } } @@ -170,7 +173,7 @@ public function hasMessages() { /** * Gets the most recent message from the message manager. * - * @return Whip_Message The latest message. + * @return Message The latest message. */ public function getMostRecentMessage() { return $this->messageManager->getLatestMessage(); diff --git a/src/Whip_VersionRequirement.php b/src/VersionRequirement.php similarity index 61% rename from src/Whip_VersionRequirement.php rename to src/VersionRequirement.php index ec0cc0d..f29c641 100644 --- a/src/Whip_VersionRequirement.php +++ b/src/VersionRequirement.php @@ -1,14 +1,17 @@ =<\s]+) # Matches anything except >, <, =, and whitespace. `x'; - if ( ! preg_match( $matcher, $comparisonString, $match ) ) { - throw new Whip_InvalidVersionComparisonString( $comparisonString ); + if ( ! \preg_match( $matcher, $comparisonString, $match ) ) { + throw new InvalidVersionComparisonString( $comparisonString ); } $version = $match[2]; $operator = $match[1]; - return new Whip_VersionRequirement( $component, $version, $operator ); + return new VersionRequirement( $component, $version, $operator ); } /** @@ -113,38 +116,38 @@ public static function fromCompareString( $component, $comparisonString ) { * * @return void * - * @throws Whip_EmptyProperty When any of the parameters is empty. - * @throws Whip_InvalidOperatorType When the $operator parameter is invalid. - * @throws Whip_InvalidType When any of the parameters is not of the expected type. + * @throws EmptyProperty When any of the parameters is empty. + * @throws InvalidOperatorType When the $operator parameter is invalid. + * @throws InvalidType When any of the parameters is not of the expected type. */ private function validateParameters( $component, $version, $operator ) { if ( empty( $component ) ) { - throw new Whip_EmptyProperty( 'Component' ); + throw new EmptyProperty( 'Component' ); } - if ( ! is_string( $component ) ) { - throw new Whip_InvalidType( 'Component', $component, 'string' ); + if ( ! \is_string( $component ) ) { + throw new InvalidType( 'Component', $component, 'string' ); } if ( empty( $version ) ) { - throw new Whip_EmptyProperty( 'Version' ); + throw new EmptyProperty( 'Version' ); } - if ( ! is_string( $version ) ) { - throw new Whip_InvalidType( 'Version', $version, 'string' ); + if ( ! \is_string( $version ) ) { + throw new InvalidType( 'Version', $version, 'string' ); } if ( empty( $operator ) ) { - throw new Whip_EmptyProperty( 'Operator' ); + throw new EmptyProperty( 'Operator' ); } - if ( ! is_string( $operator ) ) { - throw new Whip_InvalidType( 'Operator', $operator, 'string' ); + if ( ! \is_string( $operator ) ) { + throw new InvalidType( 'Operator', $operator, 'string' ); } $validOperators = array( '=', '==', '===', '<', '>', '<=', '>=' ); - if ( ! in_array( $operator, $validOperators, true ) ) { - throw new Whip_InvalidOperatorType( $operator, $validOperators ); + if ( ! \in_array( $operator, $validOperators, true ) ) { + throw new InvalidOperatorType( $operator, $validOperators ); } } } diff --git a/src/Whip_WPDismissOption.php b/src/WPDismissOption.php similarity index 64% rename from src/Whip_WPDismissOption.php rename to src/WPDismissOption.php index 6392323..aecd9df 100644 --- a/src/Whip_WPDismissOption.php +++ b/src/WPDismissOption.php @@ -1,14 +1,15 @@ optionName, $dismissedValue ); + return \update_option( $this->optionName, $dismissedValue ); } /** @@ -34,7 +35,7 @@ public function set( $dismissedValue ) { * @return int Returns the value of the option or an empty string when not set. */ public function get() { - $dismissedOption = get_option( $this->optionName ); + $dismissedOption = \get_option( $this->optionName ); if ( ! $dismissedOption ) { return 0; } diff --git a/src/Whip_WPMessageDismissListener.php b/src/WPMessageDismissListener.php similarity index 56% rename from src/Whip_WPMessageDismissListener.php rename to src/WPMessageDismissListener.php index 9eb6a80..b3d0bda 100644 --- a/src/Whip_WPMessageDismissListener.php +++ b/src/WPMessageDismissListener.php @@ -1,14 +1,15 @@ dismisser = $dismisser; } @@ -41,9 +42,9 @@ public function __construct( Whip_MessageDismisser $dismisser ) { public function listen() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is verified in the dismisser. - $action = ( isset( $_GET['action'] ) && is_string( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : null; + $action = ( isset( $_GET['action'] ) && \is_string( $_GET['action'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['action'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is verified in the dismisser. - $nonce = ( isset( $_GET['nonce'] ) && is_string( $_GET['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : ''; + $nonce = ( isset( $_GET['nonce'] ) && \is_string( $_GET['nonce'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['nonce'] ) ) : ''; if ( $action === self::ACTION_NAME && $this->dismisser->verifyNonce( $nonce, self::ACTION_NAME ) ) { $this->dismisser->dismiss(); @@ -56,10 +57,10 @@ public function listen() { * @return string The url for dismissing the message. */ public function getDismissURL() { - return sprintf( - admin_url( 'index.php?action=%1$s&nonce=%2$s' ), + return \sprintf( + \admin_url( 'index.php?action=%1$s&nonce=%2$s' ), self::ACTION_NAME, - wp_create_nonce( self::ACTION_NAME ) + \wp_create_nonce( self::ACTION_NAME ) ); } } diff --git a/src/exceptions/Whip_EmptyProperty.php b/src/exceptions/Whip_EmptyProperty.php deleted file mode 100644 index 06ed367..0000000 --- a/src/exceptions/Whip_EmptyProperty.php +++ /dev/null @@ -1,21 +0,0 @@ -textdomain = $textdomain; - } - - /** - * Retrieves the message body to display. - * - * @return string The message to display. - */ - public function body() { - $textdomain = $this->textdomain; - - $message = array(); - - $message[] = Whip_MessageFormatter::strongParagraph( __( 'Your site could be faster and more secure with a newer PHP version.', $textdomain ) ) . '
'; - $message[] = Whip_MessageFormatter::paragraph( __( 'Hey, we\'ve noticed that you\'re running an outdated version of PHP. PHP is the programming language that WordPress and all its plugins and themes are built on. The version that is currently used for your site is no longer supported. Newer versions of PHP are both faster and more secure. In fact, your version of PHP no longer receives security updates, which is why we\'re sending you to this notice.', $textdomain ) ); - $message[] = Whip_MessageFormatter::paragraph( __( 'Hosts have the ability to update your PHP version, but sometimes they don\'t dare to do that because they\'re afraid they\'ll break your site.', $textdomain ) ); - $message[] = Whip_MessageFormatter::strongParagraph( __( 'To which version should I update?', $textdomain ) ) . '
'; - $message[] = Whip_MessageFormatter::paragraph( - sprintf( - /* translators: 1: link open tag; 2: link close tag. */ - __( 'You should update your PHP version to either 5.6 or to 7.0 or 7.1. On a normal WordPress site, switching to PHP 5.6 should never cause issues. We would however actually recommend you switch to PHP7. There are some plugins that are not ready for PHP7 though, so do some testing first. We have an article on how to test whether that\'s an option for you %1$shere%2$s. PHP7 is much faster than PHP 5.6. It\'s also the only PHP version still in active development and therefore the better option for your site in the long run.', $textdomain ), - '', - '' - ) - ); - - if ( Whip_Host::name() !== '' ) { - $hostMessage = new Whip_HostMessage( 'WHIP_MESSAGE_FROM_HOST_ABOUT_PHP', $textdomain ); - $message[] = $hostMessage->body(); - } - - $hostingPageUrl = Whip_Host::hostingPageUrl(); - - $message[] = Whip_MessageFormatter::strongParagraph( __( 'Can\'t update? Ask your host!', $textdomain ) ) . '
'; - - if ( function_exists( 'apply_filters' ) && apply_filters( Whip_Host::HOSTING_PAGE_FILTER_KEY, false ) ) { - $message[] = Whip_MessageFormatter::paragraph( - sprintf( - /* translators: 1: link open tag; 2: link close tag; 3: link open tag. */ - __( 'If you cannot upgrade your PHP version yourself, you can send an email to your host. We have %1$sexamples here%2$s. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of the recommended %3$sWordPress hosting partners%2$s.', $textdomain ), - '', - '', - sprintf( '', esc_url( $hostingPageUrl ) ) - ) - ); - } - else { - $message[] = Whip_MessageFormatter::paragraph( - sprintf( - /* translators: 1: link open tag; 2: link close tag; 3: link open tag. */ - __( 'If you cannot upgrade your PHP version yourself, you can send an email to your host. We have %1$sexamples here%2$s. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of our recommended %3$sWordPress hosting partners%2$s, they\'ve all been vetted by the Yoast support team and provide all the features a modern host should provide.', $textdomain ), - '', - '', - sprintf( '', esc_url( $hostingPageUrl ) ) - ) - ); - } - - return implode( "\n", $message ); - } -} diff --git a/tests/Unit/BasicMessageTest.php b/tests/Unit/BasicMessageTest.php index ffc3601..96ef778 100644 --- a/tests/Unit/BasicMessageTest.php +++ b/tests/Unit/BasicMessageTest.php @@ -2,7 +2,7 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_BasicMessage; +use Yoast\WHIPv2\Messages\BasicMessage; /** * Message Unit tests. @@ -10,14 +10,14 @@ final class BasicMessageTest extends TestCase { /** - * Tests if Whip_BasicMessage correctly handles a string for its body argument. + * Tests if BasicMessage correctly handles a string for its body argument. * - * @covers Whip_BasicMessage::body + * @covers \Yoast\WHIPv2\Messages\BasicMessage::body * * @return void */ public function testMessageHasBody() { - $message = new Whip_BasicMessage( 'This is a message' ); + $message = new BasicMessage( 'This is a message' ); $this->assertNotEmpty( $message->body() ); } @@ -25,26 +25,26 @@ public function testMessageHasBody() { /** * Tests if an Exception is correctly thrown when an empty string is passed as argument. * - * @covers Whip_BasicMessage::validateParameters + * @covers \Yoast\WHIPv2\Messages\BasicMessage::validateParameters * * @return void */ public function testMessageCannotBeEmpty() { - $this->expectExceptionHelper( 'Whip_EmptyProperty', 'Message body cannot be empty.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\EmptyProperty', 'Message body cannot be empty.' ); - new Whip_BasicMessage( '' ); + new BasicMessage( '' ); } /** * Tests if an Exception is correctly thrown when an invalid type is passed as argument. * - * @covers Whip_BasicMessage::validateParameters + * @covers \Yoast\WHIPv2\Messages\BasicMessage::validateParameters * * @return void */ public function testMessageMustBeString() { - $this->expectExceptionHelper( 'Whip_InvalidType', 'Message body should be of type string. Found integer.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\InvalidType', 'Message body should be of type string. Found integer.' ); - new Whip_BasicMessage( 123 ); + new BasicMessage( 123 ); } } diff --git a/tests/Unit/ConfigurationTest.php b/tests/Unit/ConfigurationTest.php index 644ab60..2f81818 100644 --- a/tests/Unit/ConfigurationTest.php +++ b/tests/Unit/ConfigurationTest.php @@ -2,7 +2,7 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_Configuration; +use Yoast\WHIPv2\Configuration; /** * Configuration unit tests. @@ -10,28 +10,28 @@ final class ConfigurationTest extends TestCase { /** - * Tests the creation of a Whip_Configuration with invalid input. + * Tests the creation of a Configuration with invalid input. * - * @covers Whip_Configuration::__construct + * @covers \Yoast\WHIPv2\Configuration::__construct * * @return void */ public function testItThrowsAnErrorIfAFaultyConfigurationIsPassed() { - $this->expectExceptionHelper( 'Whip_InvalidType', 'Configuration should be of type array. Found string.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\InvalidType', 'Configuration should be of type array. Found string.' ); - new Whip_Configuration( 'Invalid configuration' ); + new Configuration( 'Invalid configuration' ); } /** - * Tests if Whip_Configuration correctly returns -1 when passed an unknown requirement. + * Tests if Configuration correctly returns -1 when passed an unknown requirement. * - * @covers Whip_Configuration::configuredVersion + * @covers \Yoast\WHIPv2\Configuration::configuredVersion * * @return void */ public function testItReturnsANegativeNumberIfRequirementCannotBeFound() { - $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); - $requirement = $this->getMockBuilder( 'Whip_Requirement' ) + $configuration = new Configuration( array( 'php' => '5.6' ) ); + $requirement = $this->getMockBuilder( '\Yoast\WHIPv2\Interfaces\Requirement' ) ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); @@ -44,15 +44,15 @@ public function testItReturnsANegativeNumberIfRequirementCannotBeFound() { } /** - * Tests if Whip_Configuration correctly returns the version number when passed a valid requirement. + * Tests if Configuration correctly returns the version number when passed a valid requirement. * - * @covers Whip_Configuration::configuredVersion + * @covers \Yoast\WHIPv2\Configuration::configuredVersion * * @return void */ public function testItReturnsAnEntryIfRequirementIsFound() { - $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); - $requirement = $this->getMockBuilder( 'Whip_Requirement' ) + $configuration = new Configuration( array( 'php' => '5.6' ) ); + $requirement = $this->getMockBuilder( '\Yoast\WHIPv2\Interfaces\Requirement' ) ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); @@ -67,13 +67,13 @@ public function testItReturnsAnEntryIfRequirementIsFound() { /** * Tests if hasRequirementConfigures correctly returns true/false when called with valid/invalid values. * - * @covers Whip_Configuration::hasRequirementConfigured + * @covers \Yoast\WHIPv2\Configuration::hasRequirementConfigured * * @return void */ public function testIfRequirementIsConfigured() { - $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); - $requirement = $this->getMockBuilder( 'Whip_Requirement' ) + $configuration = new Configuration( array( 'php' => '5.6' ) ); + $requirement = $this->getMockBuilder( '\Yoast\WHIPv2\Interfaces\Requirement' ) ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); @@ -82,7 +82,7 @@ public function testIfRequirementIsConfigured() { ->method( 'component' ) ->will( $this->returnValue( 'php' ) ); - $falseRequirement = $this->getMockBuilder( 'Whip_Requirement' ) + $falseRequirement = $this->getMockBuilder( '\Yoast\WHIPv2\Interfaces\Requirement' ) ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); diff --git a/tests/Unit/Doubles/DismissStorageMock.php b/tests/Unit/Doubles/DismissStorageMock.php index 4fab54b..b91c627 100644 --- a/tests/Unit/Doubles/DismissStorageMock.php +++ b/tests/Unit/Doubles/DismissStorageMock.php @@ -2,12 +2,12 @@ namespace Yoast\WHIP\Tests\Unit\Doubles; -use Whip_DismissStorage; +use Yoast\WHIPv2\Interfaces\DismissStorage; /** * Test helper. */ -final class DismissStorageMock implements Whip_DismissStorage { +final class DismissStorageMock implements DismissStorage { /** * Holds the dismissed state. diff --git a/tests/Unit/MessageDismisserTest.php b/tests/Unit/MessageDismisserTest.php index 4b76ccb..04cf022 100644 --- a/tests/Unit/MessageDismisserTest.php +++ b/tests/Unit/MessageDismisserTest.php @@ -2,8 +2,8 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_MessageDismisser; use Yoast\WHIP\Tests\Unit\Doubles\DismissStorageMock; +use Yoast\WHIPv2\MessageDismisser; /** * Message Dismisser unit tests. @@ -11,17 +11,17 @@ final class MessageDismisserTest extends TestCase { /** - * Tests if Whip_MessageDismisser correctly updates Whip_DismissStorage. + * Tests if MessageDismisser correctly updates DismissStorage. * - * @covers Whip_MessageDismisser::__construct - * @covers Whip_MessageDismisser::dismiss + * @covers \Yoast\WHIPv2\MessageDismisser::__construct + * @covers \Yoast\WHIPv2\MessageDismisser::dismiss * * @return void */ public function testDismiss() { $currentTime = \time(); $storage = new DismissStorageMock(); - $dismisser = new Whip_MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage ); + $dismisser = new MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage ); $this->assertSame( 0, $storage->get() ); @@ -35,8 +35,8 @@ public function testDismiss() { * * @dataProvider versionNumbersProvider * - * @covers Whip_MessageDismisser::__construct - * @covers Whip_MessageDismisser::isDismissed + * @covers \Yoast\WHIPv2\MessageDismisser::__construct + * @covers \Yoast\WHIPv2\MessageDismisser::isDismissed * * @param int $savedTime The saved time. * @param int $currentTime The current time. @@ -47,7 +47,7 @@ public function testDismiss() { public function testIsDismissibleWithVersions( $savedTime, $currentTime, $expected ) { $storage = new DismissStorageMock(); $storage->set( $savedTime ); - $dismisser = new Whip_MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage ); + $dismisser = new MessageDismisser( $currentTime, ( \WEEK_IN_SECONDS * 4 ), $storage ); $this->assertSame( $expected, $dismisser->isDismissed() ); } diff --git a/tests/Unit/MessagesManagerTest.php b/tests/Unit/MessagesManagerTest.php index a69d27a..3fc7f95 100644 --- a/tests/Unit/MessagesManagerTest.php +++ b/tests/Unit/MessagesManagerTest.php @@ -2,7 +2,7 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_MessagesManager; +use Yoast\WHIPv2\MessagesManager; /** * Message Manager unit tests. @@ -13,12 +13,12 @@ final class MessagesManagerTest extends TestCase { * Creates a MessagesManager, calls hasMessages and tests if it returns false * without a message, true when given a message. * - * @covers Whip_MessagesManager::hasMessages + * @covers \Yoast\WHIPv2\MessagesManager::hasMessages * * @return void */ public function testHasMessages() { - $manager = new Whip_MessagesManager(); + $manager = new MessagesManager(); $this->assertFalse( $manager->hasMessages() ); diff --git a/tests/Unit/RequirementsCheckerTest.php b/tests/Unit/RequirementsCheckerTest.php index 7b750c8..e51c824 100644 --- a/tests/Unit/RequirementsCheckerTest.php +++ b/tests/Unit/RequirementsCheckerTest.php @@ -5,8 +5,8 @@ use Error; use Exception; use stdClass; -use Whip_RequirementsChecker; -use Whip_VersionRequirement; +use Yoast\WHIPv2\RequirementsChecker; +use Yoast\WHIPv2\VersionRequirement; /** * Requirements checker unit tests. @@ -14,25 +14,25 @@ final class RequirementsCheckerTest extends TestCase { /** - * Tests if Whip_RequirementsChecker is successfully created when given valid arguments. + * Tests if RequirementsChecker is successfully created when given valid arguments. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::totalRequirements + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::totalRequirements * * @return void */ public function testItReceivesAUsableRequirementObject() { - $checker = new Whip_RequirementsChecker(); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); + $checker = new RequirementsChecker(); + $checker->addRequirement( new VersionRequirement( 'php', '5.2' ) ); $this->assertTrue( $checker->hasRequirements() ); $this->assertSame( 1, $checker->totalRequirements() ); } /** - * Tests if Whip_RequirementsChecker throws an error when passed an invalid requirement. + * Tests if RequirementsChecker throws an error when passed an invalid requirement. * - * @covers Whip_RequirementsChecker::addRequirement + * @covers RequirementsChecker::addRequirement * @requires PHP 7 * * @return void @@ -44,7 +44,7 @@ public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassed() { $exceptionCaught = false; - $checker = new Whip_RequirementsChecker(); + $checker = new RequirementsChecker(); try { $checker->addRequirement( new stdClass() ); @@ -56,9 +56,9 @@ public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassed() { } /** - * Tests if Whip_RequirementsChecker throws an error when passed an invalid requirement. + * Tests if RequirementsChecker throws an error when passed an invalid requirement. * - * @covers Whip_RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement * * @return void */ @@ -69,7 +69,7 @@ public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassedInPHP5() { $exceptionCaught = false; - $checker = new Whip_RequirementsChecker(); + $checker = new RequirementsChecker(); try { $checker->addRequirement( new stdClass() ); @@ -81,41 +81,41 @@ public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassedInPHP5() { } /** - * Tests if Whip_RequirementsChecker only saves unique components. + * Tests if RequirementsChecker only saves unique components. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::totalRequirements + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::totalRequirements * * @return void */ public function testItOnlyContainsUniqueComponents() { - $checker = new Whip_RequirementsChecker(); + $checker = new RequirementsChecker(); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.2' ) ); + $checker->addRequirement( new VersionRequirement( 'mysql', '5.6' ) ); $this->assertTrue( $checker->hasRequirements() ); $this->assertSame( 2, $checker->totalRequirements() ); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '6' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '6' ) ); $this->assertSame( 2, $checker->totalRequirements() ); } /** - * Tests if Whip_RequirementsChecker::requirementExistsForComponent correctly + * Tests if RequirementsChecker::requirementExistsForComponent correctly * returns true for existing components. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::requirementExistsForComponent + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::requirementExistsForComponent * * @return void */ public function testIfRequirementExists() { - $checker = new Whip_RequirementsChecker(); + $checker = new RequirementsChecker(); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.2' ) ); + $checker->addRequirement( new VersionRequirement( 'mysql', '5.6' ) ); $this->assertTrue( $checker->requirementExistsForComponent( 'php' ) ); $this->assertFalse( $checker->requirementExistsForComponent( 'mongodb' ) ); @@ -126,17 +126,17 @@ public function testIfRequirementExists() { * * Verifies that a php upgrade message is created and successfully transferred to a variable. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::check - * @covers Whip_RequirementsChecker::hasMessages - * @covers Whip_RequirementsChecker::getMostRecentMessage + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::check + * @covers \Yoast\WHIPv2\RequirementsChecker::hasMessages + * @covers \Yoast\WHIPv2\RequirementsChecker::getMostRecentMessage * * @return void */ public function testCheckIfPHPRequirementIsNotFulfilled() { - $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); + $checker = new RequirementsChecker( array( 'php' => 4 ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.6' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.6' ) ); $checker->check(); $this->assertTrue( $checker->hasMessages() ); @@ -155,22 +155,22 @@ public function testCheckIfPHPRequirementIsNotFulfilled() { } $this->assertFalse( $checker->hasMessages() ); - $this->assertInstanceOf( 'Whip_UpgradePhpMessage', $recentMessage ); + $this->assertInstanceOf( '\Yoast\WHIPv2\Messages\UpgradePhpMessage', $recentMessage ); } /** * Tests if there no message when the requirement is fulfilled. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::check - * @covers Whip_RequirementsChecker::getMostRecentMessage + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::check + * @covers \Yoast\WHIPv2\RequirementsChecker::getMostRecentMessage * * @return void */ public function testCheckIfRequirementIsFulfilled() { - $checker = new Whip_RequirementsChecker( array( 'php' => \phpversion() ) ); + $checker = new RequirementsChecker( array( 'php' => \phpversion() ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.2' ) ); $checker->check(); $this->assertEmpty( $checker->getMostRecentMessage()->body() ); @@ -181,17 +181,17 @@ public function testCheckIfRequirementIsFulfilled() { * * Verifies that an invalid version message is created and successfully transferred to a variable. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::check - * @covers Whip_RequirementsChecker::getMostRecentMessage - * @covers Whip_RequirementsChecker::hasMessages + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::check + * @covers \Yoast\WHIPv2\RequirementsChecker::getMostRecentMessage + * @covers \Yoast\WHIPv2\RequirementsChecker::hasMessages * * @return void */ public function testCheckIfRequirementIsNotFulfilled() { - $checker = new Whip_RequirementsChecker( array( 'mysql' => 4 ) ); + $checker = new RequirementsChecker( array( 'mysql' => 4 ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); + $checker->addRequirement( new VersionRequirement( 'mysql', '5.6' ) ); $checker->check(); $this->assertTrue( $checker->hasMessages() ); @@ -201,23 +201,23 @@ public function testCheckIfRequirementIsNotFulfilled() { $this->assertNotEmpty( $recentMessage ); $this->assertFalse( $checker->hasMessages() ); - $this->assertInstanceOf( 'Whip_InvalidVersionRequirementMessage', $recentMessage ); + $this->assertInstanceOf( '\Yoast\WHIPv2\Messages\InvalidVersionRequirementMessage', $recentMessage ); $this->assertStringStartsWith( 'Invalid version detected', $recentMessage->body() ); } /** * Tests if a specific comparison with a non-default operator is correctly handled. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::check - * @covers Whip_RequirementsChecker::hasMessages + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::check + * @covers \Yoast\WHIPv2\RequirementsChecker::hasMessages * * @return void */ public function testCheckIfRequirementIsFulfilledWithSpecificComparison() { - $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); + $checker = new RequirementsChecker( array( 'php' => 4 ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2', '<' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.2', '<' ) ); $checker->check(); $this->assertFalse( $checker->hasMessages() ); @@ -226,16 +226,16 @@ public function testCheckIfRequirementIsFulfilledWithSpecificComparison() { /** * Tests if a specific comparison with a non-default operator is correctly handled. * - * @covers Whip_RequirementsChecker::addRequirement - * @covers Whip_RequirementsChecker::check - * @covers Whip_RequirementsChecker::hasMessages + * @covers \Yoast\WHIPv2\RequirementsChecker::addRequirement + * @covers \Yoast\WHIPv2\RequirementsChecker::check + * @covers \Yoast\WHIPv2\RequirementsChecker::hasMessages * * @return void */ public function testCheckIfRequirementIsNotFulfilledWithSpecificComparison() { - $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); + $checker = new RequirementsChecker( array( 'php' => 4 ) ); - $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2', '>=' ) ); + $checker->addRequirement( new VersionRequirement( 'php', '5.2', '>=' ) ); $checker->check(); $this->assertTrue( $checker->hasMessages() ); diff --git a/tests/Unit/VersionRequirementTest.php b/tests/Unit/VersionRequirementTest.php index 4188f20..1add33a 100644 --- a/tests/Unit/VersionRequirementTest.php +++ b/tests/Unit/VersionRequirementTest.php @@ -2,7 +2,7 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_VersionRequirement; +use Yoast\WHIPv2\VersionRequirement; /** * Version requirements unit tests. @@ -10,133 +10,133 @@ final class VersionRequirementTest extends TestCase { /** - * Creates a new Whip_VersionRequirement with component php and version 5.2 and + * Creates a new VersionRequirement with component php and version 5.2 and * tests if this is correctly created. * - * @covers Whip_VersionRequirement::component - * @covers Whip_VersionRequirement::version + * @covers \Yoast\WHIPv2\VersionRequirement::component + * @covers \Yoast\WHIPv2\VersionRequirement::version * * @return void */ public function testNameAndVersionAreNotEmpty() { - $requirement = new Whip_VersionRequirement( 'php', '5.2' ); + $requirement = new VersionRequirement( 'php', '5.2' ); $this->assertNotEmpty( $requirement->component() ); $this->assertNotEmpty( $requirement->version() ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with an empty component. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testComponentCannotBeEmpty() { - $this->expectExceptionHelper( 'Whip_EmptyProperty', 'Component cannot be empty.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\EmptyProperty', 'Component cannot be empty.' ); - new Whip_VersionRequirement( '', '5.2' ); + new VersionRequirement( '', '5.2' ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with an empty version. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testVersionCannotBeEmpty() { - $this->expectExceptionHelper( 'Whip_EmptyProperty', 'Version cannot be empty.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\EmptyProperty', 'Version cannot be empty.' ); - new Whip_VersionRequirement( 'php', '' ); + new VersionRequirement( 'php', '' ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with a false type for a component. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testComponentMustBeString() { - $this->expectExceptionHelper( 'Whip_InvalidType', 'Component should be of type string. Found integer.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\InvalidType', 'Component should be of type string. Found integer.' ); - new Whip_VersionRequirement( 123, '5.2' ); + new VersionRequirement( 123, '5.2' ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with a false type for a version. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testVersionMustBeString() { - $this->expectExceptionHelper( 'Whip_InvalidType', 'Version should be of type string. Found integer.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\InvalidType', 'Version should be of type string. Found integer.' ); - new Whip_VersionRequirement( 'php', 123 ); + new VersionRequirement( 'php', 123 ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with an empty operator. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testOperatorCannotBeEmpty() { - $this->expectExceptionHelper( 'Whip_EmptyProperty', 'Operator cannot be empty.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\EmptyProperty', 'Operator cannot be empty.' ); - new Whip_VersionRequirement( 'php', '5.6', '' ); + new VersionRequirement( 'php', '5.6', '' ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with a false type for an operator. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testOperatorMustBeString() { - $this->expectExceptionHelper( 'Whip_InvalidType', 'Operator should be of type string. Found integer.' ); + $this->expectExceptionHelper( '\Yoast\WHIPv2\Exceptions\InvalidType', 'Operator should be of type string. Found integer.' ); - new Whip_VersionRequirement( 'php', '5.2', 6 ); + new VersionRequirement( 'php', '5.2', 6 ); } /** - * Tests if an Exception message is correctly thrown when a Whip_VersionRequirement + * Tests if an Exception message is correctly thrown when a VersionRequirement * is created with an invalid operator. * - * @covers Whip_VersionRequirement::validateParameters + * @covers \Yoast\WHIPv2\VersionRequirement::validateParameters * * @return void */ public function testOperatorMustBeValid() { $this->expectExceptionHelper( - 'Whip_InvalidOperatorType', + '\Yoast\WHIPv2\Exceptions\InvalidOperatorType', 'Invalid operator of -> used. Please use one of the following operators: =, ==, ===, <, >, <=, >=' ); - new Whip_VersionRequirement( 'php', '5.2', '->' ); + new VersionRequirement( 'php', '5.2', '->' ); } /** - * Creates a new Whip_VersionRequirement and tests if this is correctly created with its given arguments. + * Creates a new VersionRequirement and tests if this is correctly created with its given arguments. * - * @covers Whip_VersionRequirement::component - * @covers Whip_VersionRequirement::version - * @covers Whip_VersionRequirement::operator + * @covers \Yoast\WHIPv2\VersionRequirement::component + * @covers \Yoast\WHIPv2\VersionRequirement::version + * @covers \Yoast\WHIPv2\VersionRequirement::operator * * @return void */ public function testGettingComponentProperties() { - $requirement = new Whip_VersionRequirement( 'php', '5.6' ); + $requirement = new VersionRequirement( 'php', '5.6' ); $this->assertSame( 'php', $requirement->component() ); $this->assertSame( '5.6', $requirement->version() ); @@ -148,9 +148,9 @@ public function testGettingComponentProperties() { * * @dataProvider dataFromCompareString * - * @covers Whip_VersionRequirement::component - * @covers Whip_VersionRequirement::version - * @covers Whip_VersionRequirement::operator + * @covers \Yoast\WHIPv2\VersionRequirement::component + * @covers \Yoast\WHIPv2\VersionRequirement::version + * @covers \Yoast\WHIPv2\VersionRequirement::operator * * @param string $expectation The expected output string. * @param string $component The component for this version requirement. @@ -159,7 +159,7 @@ public function testGettingComponentProperties() { * @return void */ public function testFromCompareString( $expectation, $component, $compareString ) { - $requirement = Whip_VersionRequirement::fromCompareString( $component, $compareString ); + $requirement = VersionRequirement::fromCompareString( $component, $compareString ); $this->assertSame( $expectation[0], $requirement->component() ); $this->assertSame( $expectation[1], $requirement->version() ); @@ -188,16 +188,16 @@ public static function dataFromCompareString() { * Tests whether fromCompareString() correctly throws an exception when provided * with an invalid comparison string. * - * @covers Whip_VersionRequirement::fromCompareString + * @covers \Yoast\WHIPv2\VersionRequirement::fromCompareString * * @return void */ public function testFromCompareStringException() { $this->expectExceptionHelper( - 'Whip_InvalidVersionComparisonString', + '\Yoast\WHIPv2\Exceptions\InvalidVersionComparisonString', 'Invalid version comparison string. Example of a valid version comparison string: >=5.3. Passed version comparison string: > 2.3' ); - Whip_VersionRequirement::fromCompareString( 'php', '> 2.3' ); + VersionRequirement::fromCompareString( 'php', '> 2.3' ); } } diff --git a/tests/Unit/WPMessageDismissListenerTest.php b/tests/Unit/WPMessageDismissListenerTest.php index 00ff2ae..964d2dc 100644 --- a/tests/Unit/WPMessageDismissListenerTest.php +++ b/tests/Unit/WPMessageDismissListenerTest.php @@ -2,12 +2,12 @@ namespace Yoast\WHIP\Tests\Unit; -use Whip_WPMessageDismissListener; +use Yoast\WHIPv2\WPMessageDismissListener; /** * Message Dismiss Listener unit tests. * - * @coversDefaultClass Whip_WPMessageDismissListener + * @coversDefaultClass WPMessageDismissListener * * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded -- Acronym throws the count off. */ @@ -16,7 +16,7 @@ final class WPMessageDismissListenerTest extends TestCase { /** * Tests the listen method. * - * @covers ::listen + * @covers \Yoast\WHIPv2\WPMessageDismissListener::listen * * @dataProvider listenProvider * @@ -29,11 +29,11 @@ final class WPMessageDismissListenerTest extends TestCase { * @return void */ public function testDismiss( $action, $nonce, $verifyNonceTimes, $isCorrectNonce, $dismissTimes ) { - $dismisser = $this->getMockBuilder( 'Whip_MessageDismisser' ) + $dismisser = $this->getMockBuilder( '\Yoast\WHIPv2\MessageDismisser' ) ->disableOriginalConstructor() ->getMock(); - $instance = new Whip_WPMessageDismissListener( $dismisser ); + $instance = new WPMessageDismissListener( $dismisser ); $_GET['action'] = $action; $_GET['nonce'] = $nonce; @@ -57,7 +57,7 @@ public function testDismiss( $action, $nonce, $verifyNonceTimes, $isCorrectNonce public static function listenProvider() { return array( 'correct action and nonce' => array( - 'action' => Whip_WPMessageDismissListener::ACTION_NAME, + 'action' => WPMessageDismissListener::ACTION_NAME, 'nonce' => 'the_right_nonce', 'verifyNonceTimes' => 1, 'isCorrectNonce' => true, @@ -71,7 +71,7 @@ public static function listenProvider() { 'dismissTimes' => 0, ), 'correct action incorrect nonce' => array( - 'action' => Whip_WPMessageDismissListener::ACTION_NAME, + 'action' => WPMessageDismissListener::ACTION_NAME, 'nonce' => 'wrong_nonce', 'verifyNonceTimes' => 1, 'isCorrectNonce' => false,