From b6359eb90fbd1d87eaf9385a4fd5f702b345c069 Mon Sep 17 00:00:00 2001 From: Themis Beris Date: Thu, 28 May 2020 17:32:24 +0300 Subject: [PATCH] Hreflang generator should respect http protocol * The links that are generated should adhere to the requested http protocol (http or https). * We update the travis.yml to run tests on all branches. * Update codeception to version 4. * Change all tests to use the newly introduced BaseTestCase class. * Fix ReverseHardLinkTest crashing test. * Remove unused `_boostrap.php` of codeception.yml. * Bump plugin version. --- .travis.yml | 8 +- codeception.yml | 1 - composer.json | 6 +- .../transifex-live-integration-hreflang.php | 22 +- .../transifex-live-integration-rewrite.php | 21 +- ...transifex-live-integration-wp-services.php | 18 + includes/transifex-live-integration-util.php | 13 +- readme.txt | 6 +- .../_generated/AcceptanceTesterActions.php | 4 +- .../_generated/FunctionalTesterActions.php | 4 +- .../_support/_generated/UnitTesterActions.php | 675 +++++++++++++++++- tests/unit/BaseTestCase.php | 15 + tests/unit/CalculateDefaultsTest.php | 6 +- tests/unit/GenerateLanguageUrlMapTest.php | 8 +- tests/unit/GenerateTokenizedUrlTest.php | 8 +- tests/unit/PrerenderCheckTest.php | 10 +- tests/unit/ReplaceSubdomainTest.php | 8 +- tests/unit/ReverseHardLinkTest.php | 59 +- transifex-live-integration.php | 6 +- 19 files changed, 808 insertions(+), 90 deletions(-) create mode 100644 includes/lib/transifex-live-integration-wp-services.php create mode 100644 tests/unit/BaseTestCase.php diff --git a/.travis.yml b/.travis.yml index b039acd2..7b206c5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,3 @@ -branches: - only: - - master - - devel - sudo: required dist: trusty language: php @@ -27,7 +22,8 @@ addons: before_script: - sudo whoami - pwd - - COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/codeception:2.5.5" + - COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/module-asserts:1.2" + - COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/codeception:4.1.5" - sudo ln -s /home/travis/.config/composer/vendor/bin/codecept /usr/local/bin/codecept - sudo apt-add-repository multiverse && sudo apt-get update - sudo add-apt-repository -y ppa:chris-lea/node.js diff --git a/codeception.yml b/codeception.yml index 3a8fca81..acb3d04f 100644 --- a/codeception.yml +++ b/codeception.yml @@ -6,7 +6,6 @@ paths: support: tests/_support envs: tests/_envs settings: - bootstrap: _bootstrap.php colors: true memory_limit: 1024M extensions: diff --git a/composer.json b/composer.json index 169df87d..86fe4e81 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,10 @@ { "require": { "psy/psysh": "@stable", - "codeception/codeception": "^2.1" + "codeception/codeception": "^4.0" + }, + "require-dev": { + "codeception/module-asserts": "^1.2", + "phpunit/phpunit": "^7.0" } } diff --git a/includes/lib/transifex-live-integration-hreflang.php b/includes/lib/transifex-live-integration-hreflang.php index c92ebc2b..09d2e641 100644 --- a/includes/lib/transifex-live-integration-hreflang.php +++ b/includes/lib/transifex-live-integration-hreflang.php @@ -20,19 +20,19 @@ class Transifex_Live_Integration_Hreflang { /* * A key/value array that maps Transifex locale->plugin code - * @var language_map array + * @var language_map array */ private $language_map; /* * A list of Transifex locales, for enabled languages - * @var languages array + * @var languages array */ private $languages; /* * The site_url with a placeholder for language - * @var tokenized_url string + * @var tokenized_url string */ private $tokenized_url; private $rewrite_options; @@ -99,8 +99,16 @@ private function generate_languages_hreflang( $raw_url, $languages, $ret = [ ]; foreach ($languages as $language) { $arr = [ ]; - - $arr['href'] = $url_map[$language]; + $site_url = site_url(); + $href_link = $url_map[$language]; + $href_link_parts = explode(':', $href_link); + if (count($href_link_parts) && ($href_link_parts[0] === 'http' || $href_link_parts[0] === 'https')) { + $protocol = Transifex_Live_Integration_Util::get_http_requested_protocol(); + $href_link_parts[0] = $protocol; + $arr['href'] = implode($href_link_parts, ':'); + } else { + $arr['href'] = $url_map[$language]; + } $arr['hreflang'] = $hreflang_map[$language]; array_push( $ret, $arr ); } @@ -126,7 +134,7 @@ public function render_hreflang() { $source_url = rtrim( $unslashed_source_url, '/' ) . '/'; $hreflang_out = ''; $hreflang_out .= <<\n +\n SOURCE; $hreflangs = $this->generate_languages_hreflang( $source_url_path, $this->languages, $this->language_map, $this->hreflang_map ); foreach ($hreflangs as $hreflang) { @@ -142,4 +150,4 @@ public function render_hreflang() { } -?> \ No newline at end of file +?> diff --git a/includes/lib/transifex-live-integration-rewrite.php b/includes/lib/transifex-live-integration-rewrite.php index 4086e4a2..59d761d2 100644 --- a/includes/lib/transifex-live-integration-rewrite.php +++ b/includes/lib/transifex-live-integration-rewrite.php @@ -17,7 +17,7 @@ class Transifex_Live_Integration_Rewrite { private $source_language; /** - * List of languages used by rewrite + * List of languages used by rewrite * @var array */ private $language_codes; @@ -38,8 +38,14 @@ class Transifex_Live_Integration_Rewrite { */ public function __construct( $settings, $rewrite_options ) { Plugin_Debug::logTrace(); + if ( !defined( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE' ) ) { + define( 'TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE', dirname( __FILE__, 3)); + } + include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/common/transifex-live-integration-validators.php'; include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE . '/includes/override/transifex-live-integration-generate-rewrite-rules.php'; + include_once TRANSIFEX_LIVE_INTEGRATION_DIRECTORY_BASE .'/includes/lib/transifex-live-integration-wp-services.php'; + $this->rewrite_options = [ ]; $this->languages_regex = $settings['languages_regex']; $this->source_language = $settings['source_language']; @@ -97,6 +103,7 @@ public function __construct( $settings, $rewrite_options ) { $this->rewrite_pattern = $pattern; } } + $this->wp_services = new Transifex_Live_Integration_WP_Services(); } public function get_language_url( $atts ) { @@ -138,7 +145,7 @@ function wp_hook() { /* * This function takes any WP link and associated language configuration and returns a localized url - * + * * @param string $lang Current language * @param string $link The url to localize * @param array $languages_map A key/value array that maps Transifex locale->plugin code @@ -146,7 +153,7 @@ function wp_hook() { * @return string Returns modified link */ - static function reverse_hard_link( $lang, $link, $languages_map, $source_lang, + function reverse_hard_link( $lang, $link, $languages_map, $source_lang, $pattern ) { Plugin_Debug::logTrace(); if ( !(isset( $pattern )) ) { @@ -170,7 +177,7 @@ static function reverse_hard_link( $lang, $link, $languages_map, $source_lang, if ( count( $m ) > 1 ) { $link = str_replace( $m[1], $lang, $m[0] ); } else { - $site_host = parse_url(site_url())['host']; + $site_host = parse_url($this->wp_services->get_site_url())['host']; $parsed_url = parse_url($link); $link_host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; // change only wordpress links - not links reffering to other domains @@ -188,11 +195,11 @@ static function reverse_hard_link( $lang, $link, $languages_map, $source_lang, } /* - * WP pre_post_link filter, adds lang to permalink + * WP pre_post_link filter, adds lang to permalink * @param string $permalink The permalink to filter * @param object $post The post object * @param ??? $leavename what this is I dont even know - * @return string filtered permalink + * @return string filtered permalink */ function pre_post_link_hook( $permalink, $post, $leavename ) { @@ -331,7 +338,7 @@ function home_url_hook( $url ) { $retlink = $this->reverse_hard_link( $this->lang, $url, $this->languages_map, $this->source_language, $this->rewrite_pattern ); return $retlink; } - + /* * WP the_content_hook hook, filters links using the the_content function * @param string $string The string to filter diff --git a/includes/lib/transifex-live-integration-wp-services.php b/includes/lib/transifex-live-integration-wp-services.php new file mode 100644 index 00000000..b5c12828 --- /dev/null +++ b/includes/lib/transifex-live-integration-wp-services.php @@ -0,0 +1,18 @@ +expectException(MyException::class, function() { + * $this->doSomethingBad(); + * }); + * + * $I->expectException(new MyException(), function() { + * $this->doSomethingBad(); + * }); + * ``` + * If you want to check message or exception code, you can pass them with exception instance: + * ```php + * expectException(new MyException("Don't do bad things"), function() { + * $this->doSomethingBad(); + * }); + * ``` + * + * @deprecated Use expectThrowable() instead + * @param $exception string or \Exception + * @param $callback + * @see \Codeception\Module\Asserts::expectException() + */ + public function expectException($exception, $callback) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Handles and checks throwables (Exceptions/Errors) called inside the callback function. + * Either throwable class name or throwable instance should be provided. + * + * ```php + * expectThrowable(MyThrowable::class, function() { + * $this->doSomethingBad(); + * }); + * + * $I->expectThrowable(new MyException(), function() { + * $this->doSomethingBad(); + * }); + * ``` + * If you want to check message or throwable code, you can pass them with throwable instance: + * ```php + * expectThrowable(new MyError("Don't do bad things"), function() { + * $this->doSomethingBad(); + * }); + * ``` + * + * @param $throwable string or \Throwable + * @param $callback + * @see \Codeception\Module\Asserts::expectThrowable() + */ + public function expectThrowable($throwable, $callback) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('expectThrowable', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -24,9 +90,10 @@ abstract protected function getScenario(); * @param $expected * @param $actual * @param string $message + * @param float $delta * @see \Codeception\Module\Asserts::assertEquals() */ - public function assertEquals($expected, $actual, $message = null) { + public function assertEquals($expected, $actual, $message = null, $delta = null) { return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args())); } @@ -39,9 +106,10 @@ public function assertEquals($expected, $actual, $message = null) { * @param $expected * @param $actual * @param string $message + * @param float $delta * @see \Codeception\Module\Asserts::assertNotEquals() */ - public function assertNotEquals($expected, $actual, $message = null) { + public function assertNotEquals($expected, $actual, $message = null, $delta = null) { return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args())); } @@ -91,17 +159,6 @@ public function assertGreaterThan($expected, $actual, $message = null) { } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @deprecated - * @see \Codeception\Module\Asserts::assertGreaterThen() - */ - public function assertGreaterThen($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThen', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -117,17 +174,6 @@ public function assertGreaterThanOrEqual($expected, $actual, $message = null) { } - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @deprecated - * @see \Codeception\Module\Asserts::assertGreaterThenOrEqual() - */ - public function assertGreaterThenOrEqual($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThenOrEqual', func_get_args())); - } - - /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -203,6 +249,22 @@ public function assertRegExp($pattern, $string, $message = null) { } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that string match with pattern + * + * Alias of assertRegExp + * @param string $pattern + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertMatchesRegularExpression() + */ + public function assertMatchesRegularExpression($pattern, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertMatchesRegularExpression', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -218,6 +280,52 @@ public function assertNotRegExp($pattern, $string, $message = null) { } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that string not match with pattern + * + * Alias of assertNotRegExp + * @param string $pattern + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertDoesNotMatchRegularExpression() + */ + public function assertDoesNotMatchRegularExpression($pattern, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertDoesNotMatchRegularExpression', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that a string starts with the given prefix. + * + * @param string $prefix + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertStringStartsWith() + */ + public function assertStringStartsWith($prefix, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that a string doesn't start with the given prefix. + * + * @param string $prefix + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertStringStartsNotWith() + */ + public function assertStringStartsNotWith($prefix, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -288,6 +396,20 @@ public function assertTrue($condition, $message = null) { } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the condition is NOT true (everything but true) + * + * @param $condition + * @param string $message + * @see \Codeception\Module\Asserts::assertNotTrue() + */ + public function assertNotTrue($condition, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotTrue', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -302,6 +424,20 @@ public function assertFalse($condition, $message = null) { } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the condition is NOT false (everything but false) + * + * @param $condition + * @param string $message + * @see \Codeception\Module\Asserts::assertNotFalse() + */ + public function assertNotFalse($condition, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotFalse', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -330,6 +466,137 @@ public function assertFileNotExists($filename, $message = null) { } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if file doesn't exist + * + * Alias of assertFileNotExists + * @param string $filename + * @param string $message + * @see \Codeception\Module\Asserts::assertFileDoesNotExist() + */ + public function assertFileDoesNotExist($filename, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileDoesNotExist', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $expected + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertGreaterOrEquals() + */ + public function assertGreaterOrEquals($expected, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $expected + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertLessOrEquals() + */ + public function assertLessOrEquals($expected, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertIsEmpty() + */ + public function assertIsEmpty($actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $key + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertArrayHasKey() + */ + public function assertArrayHasKey($key, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $key + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertArrayNotHasKey() + */ + public function assertArrayNotHasKey($key, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $expectedCount + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertCount() + */ + public function assertCount($expectedCount, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $class + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertInstanceOf() + */ + public function assertInstanceOf($class, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $class + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertNotInstanceOf() + */ + public function assertNotInstanceOf($class, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $type + * @param $actual + * @param $description + * @see \Codeception\Module\Asserts::assertInternalType() + */ + public function assertInternalType($type, $actual, $description = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args())); + } + + /** * [!] Method is generated. Documentation taken from corresponding module. * @@ -341,4 +608,356 @@ public function assertFileNotExists($filename, $message = null) { public function fail($message) { return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertStringContainsString() + */ + public function assertStringContainsString($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringContainsString', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertStringNotContainsString() + */ + public function assertStringNotContainsString($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringNotContainsString', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertStringContainsStringIgnoringCase() + */ + public function assertStringContainsStringIgnoringCase($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringContainsStringIgnoringCase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertStringNotContainsStringIgnoringCase() + */ + public function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringNotContainsStringIgnoringCase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @since 1.1.0 of module-asserts + * @see \Codeception\Module\Asserts::assertStringEndsWith() + */ + public function assertStringEndsWith($suffix, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringEndsWith', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @since 1.1.0 of module-asserts + * @see \Codeception\Module\Asserts::assertStringEndsNotWith() + */ + public function assertStringEndsNotWith($suffix, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringEndsNotWith', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsArray() + */ + public function assertIsArray($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsArray', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsBool() + */ + public function assertIsBool($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsBool', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsFloat() + */ + public function assertIsFloat($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsFloat', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsInt() + */ + public function assertIsInt($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsInt', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNumeric() + */ + public function assertIsNumeric($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNumeric', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsObject() + */ + public function assertIsObject($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsObject', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsResource() + */ + public function assertIsResource($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsResource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsString() + */ + public function assertIsString($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsString', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsScalar() + */ + public function assertIsScalar($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsScalar', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsCallable() + */ + public function assertIsCallable($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsCallable', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotArray() + */ + public function assertIsNotArray($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotArray', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotBool() + */ + public function assertIsNotBool($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotBool', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotFloat() + */ + public function assertIsNotFloat($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotFloat', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotInt() + */ + public function assertIsNotInt($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotInt', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotNumeric() + */ + public function assertIsNotNumeric($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotNumeric', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotObject() + */ + public function assertIsNotObject($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotObject', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotResource() + */ + public function assertIsNotResource($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotResource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotString() + */ + public function assertIsNotString($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotString', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotScalar() + */ + public function assertIsNotScalar($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotScalar', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertIsNotCallable() + */ + public function assertIsNotCallable($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotCallable', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertEqualsCanonicalizing() + */ + public function assertEqualsCanonicalizing($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEqualsCanonicalizing', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertNotEqualsCanonicalizing() + */ + public function assertNotEqualsCanonicalizing($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEqualsCanonicalizing', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertEqualsIgnoringCase() + */ + public function assertEqualsIgnoringCase($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEqualsIgnoringCase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertNotEqualsIgnoringCase() + */ + public function assertNotEqualsIgnoringCase($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEqualsIgnoringCase', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertEqualsWithDelta() + */ + public function assertEqualsWithDelta($expected, $actual, $delta, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEqualsWithDelta', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Codeception\Module\Asserts::assertNotEqualsWithDelta() + */ + public function assertNotEqualsWithDelta($expected, $actual, $delta, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEqualsWithDelta', func_get_args())); + } } diff --git a/tests/unit/BaseTestCase.php b/tests/unit/BaseTestCase.php new file mode 100644 index 00000000..310ad7b6 --- /dev/null +++ b/tests/unit/BaseTestCase.php @@ -0,0 +1,15 @@ +data as $d) { $result = Transifex_Live_Integration_Common::generate_language_url_map($d['raw_url'], $d['tokenized_url'], $d['language_map']); diff --git a/tests/unit/GenerateTokenizedUrlTest.php b/tests/unit/GenerateTokenizedUrlTest.php index ff6323c0..95b78ae6 100644 --- a/tests/unit/GenerateTokenizedUrlTest.php +++ b/tests/unit/GenerateTokenizedUrlTest.php @@ -1,11 +1,13 @@ data as $d) { $result = Transifex_Live_Integration_Admin_Util::generate_tokenized_url($d['site_url'], $d['url_option_setting']); diff --git a/tests/unit/PrerenderCheckTest.php b/tests/unit/PrerenderCheckTest.php index 76958658..dc43416f 100644 --- a/tests/unit/PrerenderCheckTest.php +++ b/tests/unit/PrerenderCheckTest.php @@ -1,11 +1,13 @@ $bot_types, 'whitelist' => $whitelist, 'result' => false - ], [ // Standard Googlebot + ], [ // Standard Googlebot 'agent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 'fragment' => false, 'bot_types' => $bot_types, @@ -65,7 +67,7 @@ protected function setUp() ]; } - public function testMe() + public function testMe() { foreach ($this->data as $i) { $result = Transifex_Live_Integration_Util::prerender_check($i['agent'], $i['fragment'], $i['bot_types'], $i['whitelist']); diff --git a/tests/unit/ReplaceSubdomainTest.php b/tests/unit/ReplaceSubdomainTest.php index 7a806da4..e0badd60 100644 --- a/tests/unit/ReplaceSubdomainTest.php +++ b/tests/unit/ReplaceSubdomainTest.php @@ -1,11 +1,13 @@ data as $d) { $result = Transifex_Live_Integration_Util::replace_lang_subdomain( diff --git a/tests/unit/ReverseHardLinkTest.php b/tests/unit/ReverseHardLinkTest.php index 9e8d0bdb..8e8ae6f9 100644 --- a/tests/unit/ReverseHardLinkTest.php +++ b/tests/unit/ReverseHardLinkTest.php @@ -1,21 +1,27 @@ data = [[ //1 - 'lang' => 'zh_CN', - 'link' => 'http://www.mydomain.com/page-markup-and-formatting', - 'languages_map' => ["zh_CN" => "zh_CN", "de_DE" => "de_DE" ], - 'souce_lang' => 'en', - 'pattern' => '/http:\/\/www.mydomain.com\/(zh_CN|de_DE)\//', - 'result' => 'http://www.mydomain.com/zh_CN/page-markup-and-formatting' + 'host' => 'http://www.mydomain.com', + 'lang' => 'zh_CN', + 'link' => 'http://www.mydomain.com/page-markup-and-formatting', + 'languages_map' => ["zh_CN" => "zh_CN", "de_DE" => "de_DE" ], + 'souce_lang' => 'en', + 'pattern' => '/http:\/\/www.mydomain.com\/(zh_CN|de_DE)\//', + 'result' => 'http://www.mydomain.com/zh_CN/page-markup-and-formatting' ], [ //2 + 'host' => 'http://www.mydomain.com', 'lang' => 'zh_CN', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "zh_CN", "de_DE" => "de_DE" ], @@ -24,6 +30,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/page-markup-and-formatting' ], [ //3 + 'host' => 'http://www.mydomain.com', 'lang' => 'zh_HK', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "zh_CN", "de_DE" => "de_DE" ], @@ -32,6 +39,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/page-markup-and-formatting' ], [ //4 + 'host' => 'http://www.mydomain.com', 'lang' => 'cn', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de_DE" ], @@ -40,6 +48,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/cn/page-markup-and-formatting' ], [ //5 + 'host' => 'http://www.mydomain.com', 'lang' => 'zh_CN', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => [ ], @@ -48,6 +57,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/page-markup-and-formatting' ], [ //6 + 'host' => 'http://www.mydomain.com', 'lang' => null, 'link' => 'http://www.mydomain.com/', 'languages_map' => null, @@ -56,6 +66,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/' ], [ //7 + 'host' => 'http://www.mydomain.com', 'lang' => 'zh_CN', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de_DE" ], @@ -64,6 +75,7 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/page-markup-and-formatting' ], [ //8 + 'host' => 'http://www.mydomain.com', 'lang' => 'zh_CN', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "zh_CN", "de_DE" => "de_DE" ], @@ -72,6 +84,7 @@ protected function setUp() { 'result' => 'http://zh_CN.mydomain.com/page-markup-and-formatting' ], [ //9 + 'host' => 'http://www.mydomain.com', 'lang' => 'cn', 'link' => 'http://www.mydomain.com/page-markup-and-formatting', 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de_DE" ], @@ -80,6 +93,7 @@ protected function setUp() { 'result' => 'http://cn.mydomain.com/page-markup-and-formatting' ], [ //10 plex case + 'host' => 'http://www.mydomain.com', 'lang' => 'de', 'link' => 'http://www.mydomain.com/page-markup-and-formatting-de', 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de" ], @@ -88,25 +102,48 @@ protected function setUp() { 'result' => 'http://www.mydomain.com/de/page-markup-and-formatting-de' ], [ //11 + 'host' => 'http://www.mydomain.com', 'lang' => 'de', 'link' => 'http://www.mydomain.com/page-markup-and-formatting-de', 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de" ], 'souce_lang' => 'en', 'pattern' => '/http:\/\/(cn|de|www).mydomain.com\/.*/', 'result' => 'http://de.mydomain.com/page-markup-and-formatting-de' + ], + [ //12 external link, leave intact + 'host' => 'http://www.mydomain.com', + 'lang' => 'de', + 'link' => 'http://www.another.com/page-markup-and-formatting-de', + 'languages_map' => ["zh_CN" => "cn", "de_DE" => "de" ], + 'souce_lang' => 'en', + 'pattern' => '/http:\/\/www.mydomain.com\/(cn|de)\//', + 'result' => 'http://www.another.com/page-markup-and-formatting-de' ] ]; } public function testMe() { $counter = 0; + $output = new \Codeception\Lib\Console\Output([]); foreach ($this->data as $i) { + $rewrite = \Codeception\Stub::makeEmptyExcept( + Transifex_Live_Integration_Rewrite::class, + 'reverse_hard_link', [ + 'wp_services' => \Codeception\Stub::make( + Transifex_Live_Integration_WP_Services::class, [ + 'get_site_url' => $i['host'] + ] + ) + ], + $this + ); + $counter = $counter + 1; - $result = Transifex_Live_Integration_Rewrite::reverse_hard_link( - $i['lang'], $i['link'], $i['languages_map'], $i['souce_lang'], $i['pattern'] + $result = $rewrite->reverse_hard_link( + $i['lang'], $i['link'], $i['languages_map'], + $i['souce_lang'], $i['pattern'] ); -// eval(\Psy\sh()); $this->assertEquals( $i['result'], $result, 'Test Number:' . $counter ); } } diff --git a/transifex-live-integration.php b/transifex-live-integration.php index d20a1560..fa51957e 100755 --- a/transifex-live-integration.php +++ b/transifex-live-integration.php @@ -5,13 +5,13 @@ * * @link http://docs.transifex.com/developer/integrations/wordpress * @package TransifexLiveIntegration - * @version 1.3.21 + * @version 1.3.22 * * @wordpress-plugin * Plugin Name: International SEO by Transifex * Plugin URI: http://docs.transifex.com/developer/integrations/wordpress * Description: Translate your WordPress powered website using Transifex. - * Version: 1.3.21 + * Version: 1.3.22 * License: GNU General Public License * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Text Domain: transifex-live-integration @@ -75,7 +75,7 @@ } define( 'LANG_PARAM', 'lang' ); -$version = '1.3.21'; +$version = '1.3.22'; require_once( dirname( __FILE__ ) . '/transifex-live-integration-main.php' ); Transifex_Live_Integration::do_plugin( is_admin(), $version );