From c609c486da216fbe962cbdd2466074b61f611a5e Mon Sep 17 00:00:00 2001 From: Lars Gersmann Date: Mon, 24 Jul 2023 16:57:49 +0200 Subject: [PATCH] fix: corrected indentation --- impex-cli/impex-cli.php | 42 +++++++++---------- .../profiles/export-profile-base.php | 8 ++-- .../tests/phpunit/impex-unittestcase.php | 10 ++--- .../test-impex-export-extension-db-tables.php | 2 +- .../test-impex-export-rest-controller.php | 6 +-- .../tests/phpunit/test-impex-export.php | 8 ++-- ...test-impex-import-extension-attachment.php | 2 +- .../test-impex-import-extension-content.php | 18 ++++---- .../test-impex-import-extension-db-table.php | 4 +- .../test-impex-import-rest-controller.php | 12 +++--- .../tests/phpunit/test-impex-import.php | 16 +++---- .../test-impex-profile-rest-controller.php | 2 +- .../tests/phpunit/wp-tests-config.php | 6 +-- 13 files changed, 68 insertions(+), 68 deletions(-) diff --git a/impex-cli/impex-cli.php b/impex-cli/impex-cli.php index a9cbec6..fd72f93 100755 --- a/impex-cli/impex-cli.php +++ b/impex-cli/impex-cli.php @@ -4,8 +4,8 @@ # Description: commandline tool to import/export wordpress data by interacting with the cm4all-wp-impex wordpress plugin # # This file is part of cm4all-wp-impex. -# -# Usage: see impex-cli/impex-cli.php help +# +# Usage: see impex-cli/impex-cli.php help # # Requires PHP: 8.0, php-curl extension # Author: Lars Gersmann @@ -205,7 +205,7 @@ function help($options, $message = null, ...$args) echo "Usage: impex-cli.php [operation] [sub-operation?] -rest-url=[wordpress-restapi-url] [options] [arguments] -operation: +operation: help show this help export export wordpress data using the impex wordpress plugin to a directory @@ -214,24 +214,24 @@ function help($options, $message = null, ...$args) arguments: [directory] (required) directory to export to - import import wordpress data (in impex format) from a directory + import import wordpress data (in impex format) from a directory options: -profile=[import-profile] (default='all') import profile to use -options=[import options in JSON format] (default='{}') provide options to the import process arguments: [directory] (required) impex directory to import from - export-profile + export-profile sub-operations: (required) - list json list of known impex export profiles + list json list of known impex export profiles - import-profile + import-profile sub-operations: (required) - list json list of known impex import profiles + list json list of known impex import profiles global options: - -username=[wordpress-username] - -password=[wordpress-password] + -username=[wordpress-username] + -password=[wordpress-password] -rest-url=[wordpress-restapi-url] (required) url of wordpress rest endpoint example: -rest-url=http://localhost:8888/wp-json @@ -239,7 +239,7 @@ function help($options, $message = null, ...$args) -CURLOPT_VERBOSE prints additional php-curl debug informations stderr -H=[header] additional header to send to the wordpress rest api may occur multiple times - example: -H='x-foo: bar' + example: -H='x-foo: bar' see https://ionos-wordpress.github.io/cm4all-wp-impex/impex-cli.html for more. "; @@ -354,8 +354,8 @@ function import($options, $import_directory, ...$args) $import_options = $options['options'] ?? '{}'; try { $import_options = json_decode( - json: $import_options, - associative: true, + json: $import_options, + associative: true, flags: JSON_THROW_ON_ERROR, ); } catch(Exception $ex) { @@ -467,14 +467,14 @@ function ($curl) use ($slice, $slice_contents, $chunk_dir, $slice_file, $options "import/$import_id/consume", \CURLOPT_POST, ); - + $postConsumeCallbacks = $result['callbacks'] ?? []; foreach($postConsumeCallbacks as $index => $postConsumeCallback) { _log( - $options, - 'Executing post consume callback(path=%s, method=%s) with data(=%s)', - $postConsumeCallback['path'], - $postConsumeCallback['method'], + $options, + 'Executing post consume callback(path=%s, method=%s) with data(=%s)', + $postConsumeCallback['path'], + $postConsumeCallback['method'], json_encode($postConsumeCallback['data']), ); [$result, $status, $error] = _curl( @@ -483,7 +483,7 @@ function ($curl) use ($slice, $slice_contents, $chunk_dir, $slice_file, $options $postConsumeCallback['method']==='post' ? \CURLOPT_POST : null, fn ($curl) => curl_setopt($curl, \CURLOPT_POSTFIELDS, http_build_query($postConsumeCallback['data'])) ); - + if ($error) { _log($options, "Warning : Failed to update metadata : HTTP status(=%s) : %s", $status, $error); } @@ -664,7 +664,7 @@ function _saveSlicesChunk($options, $export_directory, $response, $chunk) // if we are running in cli mode and not as phpunit test then run main if (php_sapi_name() === "cli" && !str_ends_with($_SERVER['argv'][0], 'phpunit')) { main($argv); -} +} /* main([ @@ -677,4 +677,4 @@ function _saveSlicesChunk($options, $export_directory, $response, $chunk) "-profile=all", "~/Sync/tmp/snapshots/my-export", ]); -*/ \ No newline at end of file +*/ diff --git a/plugins/cm4all-wp-impex/profiles/export-profile-base.php b/plugins/cm4all-wp-impex/profiles/export-profile-base.php index e5552a3..5859bf9 100644 --- a/plugins/cm4all-wp-impex/profiles/export-profile-base.php +++ b/plugins/cm4all-wp-impex/profiles/export-profile-base.php @@ -22,16 +22,16 @@ // export most common used wp options $profile->addTask( - 'common wp_options', - WpOptionsExporter::PROVIDER_NAME, + 'common wp_options', + WpOptionsExporter::PROVIDER_NAME, [WpOptionsExporter::OPTION_SELECTOR => [ 'page_on_front', // wordpress homepage 'show_on_front', // what should be shown ('page'| 'post' ...) 'page_for_posts', // posts homepage 'blogname', // aka website title - 'blogdescription', + 'blogdescription', 'site_logo', // website logo 'site_icon' // website icon ],], -); \ No newline at end of file +); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/impex-unittestcase.php b/plugins/cm4all-wp-impex/tests/phpunit/impex-unittestcase.php index 569f198..d62837e 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/impex-unittestcase.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/impex-unittestcase.php @@ -22,16 +22,16 @@ public function setUp() self::_resetImpex(); } - /** + /** * Triggers the ImpEx actions for provider and profile registration so that all by default loaded prviders and profiles will be available. - * + * * Regularly the Implex plugin will trigger the actions * - Impex::WP_ACTION_REGISTER_PROVIDERS * - Impex::WP_ACTION_REGISTER_PROFILES - * automatically. - * + * automatically. + * * But ImpexUnitTestcase->setUp resets all registered providers/profiles for convenience. - * + * * So we need to trigger the registration actions again in rare cases */ protected function __invokeImpexActions(): void diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-extension-db-tables.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-extension-db-tables.php index 7f4dcd9..3d532de 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-extension-db-tables.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-extension-db-tables.php @@ -34,7 +34,7 @@ function testDbExporter(): void // system('mysql --user=' . DB_USER . ' --password=' . DB_PASSWORD . ' ' . DB_NAME . ' < ' . __DIR__ . '/fixtures/adapter/db/cmplz-plugin.sql'); /* - this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements + this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables) therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements. diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-rest-controller.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-rest-controller.php index 8426e4b..53e75c3 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-rest-controller.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export-rest-controller.php @@ -121,7 +121,7 @@ public function test_get_item() $request->set_body(\wp_json_encode(['profile' => $profile->name])); $create_response = $this->server->dispatch($request); - // try to get it + // try to get it $request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexExportRESTController::REST_BASE . '/' . $create_response->data['id']); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->status); @@ -222,7 +222,7 @@ public function test_get_item_slices() { \wp_set_current_user($this->user); - // create export + // create export $alphabet = range('a', 'z'); $profile = $this->__createExportProfile('single-slice-export-profile', ['provider-alphabet' => $alphabet]); @@ -244,7 +244,7 @@ public function test_get_item_slices() $response = $this->server->dispatch($request); $this->assertEquals(404, $response->status); - // get export slices using rest pagination api + // get export slices using rest pagination api $request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexExportRESTController::REST_BASE . '/' . $export_id . '/slice'); $request->set_query_params(['offset' => 1, 'per_page' => 2, 'page' => 2]); $response = $this->server->dispatch($request); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export.php index e66e2cb..a3f3bac 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-export.php @@ -18,9 +18,9 @@ function setUp() parent::setUp(); /* - CAVEAT : tables created using WordPress install/upgrade mechanism - (https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use - the wp phpunit filter making the table temporary. + CAVEAT : tables created using WordPress install/upgrade mechanism + (https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use + the wp phpunit filter making the table temporary. => so we need to drop the table manually to have a consistent setup */ @@ -92,7 +92,7 @@ function testExportDbTablesInstalled(): void global $wpdb; /* - this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements + this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables) therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements. diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-attachment.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-attachment.php index d0fb622..507384d 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-attachment.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-attachment.php @@ -166,7 +166,7 @@ function ($uploads) { - // create initial attachment + // create initial attachment $post = $this->factory->post->create_and_get(); $attachment_id = $this->factory->attachment->create_upload_object(__DIR__ . '/fixtures/uploads/images/' . self::IMAGE, $post->ID); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-content.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-content.php index b28f675..256e214 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-content.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-content.php @@ -187,7 +187,7 @@ function testContentImporterUsers() $this->assertIsObject($t); } - // test import with valid user options + // test import with valid user options $new_id_exported_user2 = self::factory()->user->create(['role' => 'editor', 'user_login' => 'new_id_exported_user2']); $users_before_import = \get_users(); $this->assertCount(6, $users_before_import); @@ -207,7 +207,7 @@ function testContentImporterUsers() $this->assertEmpty(array_filter($users_before_import, fn ($user) => $user->data->user_login === 'non_existing_user')); $this->assertCount(1, array_filter($users_after_import, fn ($user) => $user->data->user_login === 'non_existing_user')); - // test imported post is attached to user + // test imported post is attached to user // $post = \get_page_by_title('post from exported_user', \OBJECT, 'post'); // \get_page_by_title iss deprecated since wp 6.2 $posts = \get_posts([ @@ -278,7 +278,7 @@ function testContentImporterUsers() function testContentImporterCategories() { - /* + /* setup test data */ $slices = (function (): array { @@ -323,7 +323,7 @@ function testContentImporterCategories() $this->assertTrue(in_array('simple', array_column($categories, 'name')), 'only category "simple" should exist'); $this->assertEmpty(\get_posts(), 'no posts should exist'); - // execute import + // execute import $retVal = call_user_func($provider->callback, $slices[0], [], $importContext,); $this->assertTrue($retVal, 'importer callback expected to return successful'); @@ -405,7 +405,7 @@ function testContentImporterTerms() $this->assertCount(4, $terms, 'only terms "food", "fruits", "apples" and "pears" should exist'); $this->assertEmpty(\get_posts(), 'no posts should exist'); - // execute import + // execute import $retVal = call_user_func($provider->callback, $slices[0], [], $importContext,); $this->assertTrue($retVal, 'importer callback expected to return successful'); @@ -428,7 +428,7 @@ function testContentImporterTerms() $success = \unregister_taxonomy('products'); $this->assertTrue($success, 'taxonomy "products" should be unregistered'); - // execute import + // execute import $retVal = call_user_func($provider->callback, $slices[0], [], $importContext,); $this->assertTrue($retVal, 'importer callback expected to return successful'); @@ -523,7 +523,7 @@ function testContentImporterTags() $tags = \get_tags(['hide_empty' => false,]); $this->assertCount(2, $tags, 'only terms "alpha", and "beta" should exist'); - // execute import + // execute import $retVal = call_user_func($provider->callback, $slices[0], [], $importContext,); $this->assertTrue($retVal, 'importer callback expected to return successful'); @@ -551,7 +551,7 @@ function testContentImporterNavMenu(): void $user = self::factory()->user->create(['user_login' => 'editor']); \wp_set_current_user($user); - // create a nav menu + // create a nav menu $navmenu_id = \wp_create_nav_menu('my navmenu'); // create some posts and attach them to the nav menu @@ -609,7 +609,7 @@ function testContentImporterNavMenu(): void $provider = __registerContentImportProvider(); $importContext = $this->_createImpexImportTransformationContextMock(); - // execute import + // execute import $retVal = call_user_func($provider->callback, $slices[0], [], $importContext,); $this->assertTrue($retVal, 'importer callback expected to return successful'); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-db-table.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-db-table.php index ffd45ea..9753960 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-db-table.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-extension-db-table.php @@ -97,7 +97,7 @@ function testImport_OPTION_COPY_DATA_FROM_TABLE_WITH_PREFIX(): void { global $wpdb; - // drop (previously created by this function) table if exists + // drop (previously created by this function) table if exists $wpdb->query("DROP TABLE IF EXISTS live_cmplz_cookies"); // register importer/exporter @@ -143,7 +143,7 @@ function testImport_OPTION_COPY_DATA_FROM_TABLE_WITH_PREFIX(): void $source_table = "{$wpdb->prefix}cmplz_cookies"; /* - this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements + this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables) therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements. diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-rest-controller.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-rest-controller.php index 5d2b247..051716b 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-rest-controller.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import-rest-controller.php @@ -113,7 +113,7 @@ public function test_get_item() // create import $import_id = Impex::getInstance()->Import->create(Impex::getInstance()->Import->addProfile('dummy-import'))->id; - // try to get it + // try to get it $request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexImportRESTController::REST_BASE . '/' . $import_id); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->status); @@ -218,8 +218,8 @@ public function test_delete_item() } /* - testcase is obsolete since it utilizes the removed WordPress Importer - @TODO : adapt testcase to new ContentImporter + testcase is obsolete since it utilizes the removed WordPress Importer + @TODO : adapt testcase to new ContentImporter */ public function _test_upsert_item_slices() { @@ -255,7 +255,7 @@ function ($_) use ($EXPORT_PATH) { if ($slice_json[Impex::SLICE_TAG] === 'attachment') { $attachment_filename = $EXPORT_PATH . '/' . basename($slice_file, '.json') . '-' . basename($slice_json[Impex::SLICE_DATA]); - // ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file + // ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file $uploadedAttachment = tempnam(sys_get_temp_dir(), 'impex_import_'); $success = file_put_contents($uploadedAttachment, file_get_contents($attachment_filename)); @@ -281,7 +281,7 @@ function ($_) use ($EXPORT_PATH) { )); $this->assertEquals(count($slice_filenames), $inserted_slices, 'all uploaded chunks should be in the database'); - // try to insert the slices again + // try to insert the slices again foreach ($slice_filenames as $index => $slice_filename) { $slice_file = $EXPORT_PATH . '/' . $slice_filename; @@ -296,7 +296,7 @@ function ($_) use ($EXPORT_PATH) { if ($slice_json[Impex::SLICE_TAG] === 'attachment') { $attachment_filename = $EXPORT_PATH . '/' . basename($slice_file, '.json') . '-' . basename($slice_json[Impex::SLICE_DATA]); - // ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file + // ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file $uploadedAttachment = tempnam(sys_get_temp_dir(), 'impex_import_'); $success = file_put_contents($uploadedAttachment, file_get_contents($attachment_filename)); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import.php index cc63b58..0622554 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-import.php @@ -36,9 +36,9 @@ function setUp() } /* - CAVEAT : tables created using WordPress install/upgrade mechanism - (https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use - the wp phpunit filter making the table temporary. + CAVEAT : tables created using WordPress install/upgrade mechanism + (https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use + the wp phpunit filter making the table temporary. => so we need to drop the table manually to have a consistent setup */ @@ -170,7 +170,7 @@ function testImportDbTablesInstalled(): void global $wpdb; /* - this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements + this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables) therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements. @@ -182,8 +182,8 @@ function testImportDbTablesInstalled(): void } /* - testcase is obsolete since it utilizes the removed WordPress Importer - @TODO : adapt testcase to new ContentImporter + testcase is obsolete since it utilizes the removed WordPress Importer + @TODO : adapt testcase to new ContentImporter */ function _testConsume() { @@ -216,7 +216,7 @@ function ($_) use ($EXPORT_PATH) { } - // read in slices + // read in slices $slices = array_map(function ($slice_filename) use ($EXPORT_PATH) { return json_decode(file_get_contents($EXPORT_PATH . '/' . $slice_filename), JSON_OBJECT_AS_ARRAY); }, array_filter( @@ -228,7 +228,7 @@ function ($_) use ($EXPORT_PATH) { return is_file($EXPORT_PATH . '/' . $_); } )); - // inject them into import chunks table + // inject them into import chunks table global $wpdb; foreach ($slices as $position => $slice) { diff --git a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-profile-rest-controller.php b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-profile-rest-controller.php index 1ea1aad..c67a75a 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/test-impex-profile-rest-controller.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/test-impex-profile-rest-controller.php @@ -102,7 +102,7 @@ public function test_get_item() \wp_set_current_user($this->user); $profile = $this->__createExportProfile('export-profile-1', ['provider-a' => ['a']]); - // try to get it + // try to get it $request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexExportProfileRESTController::REST_BASE . '/' . $profile->name); $response = $this->server->dispatch($request); $this->assertEquals(200, $response->status); diff --git a/plugins/cm4all-wp-impex/tests/phpunit/wp-tests-config.php b/plugins/cm4all-wp-impex/tests/phpunit/wp-tests-config.php index dbecfdb..915c5a9 100644 --- a/plugins/cm4all-wp-impex/tests/phpunit/wp-tests-config.php +++ b/plugins/cm4all-wp-impex/tests/phpunit/wp-tests-config.php @@ -22,14 +22,14 @@ // Test with WordPress debug mode (default). define( 'WP_DEBUG', true ); -// This is configurable by setting the WP_PHPUNIT__TABLE_PREFIX environment variable. -// If set, this will take precedence over what is set in your tests config file. +// This is configurable by setting the WP_PHPUNIT__TABLE_PREFIX environment variable. +// If set, this will take precedence over what is set in your tests config file. // If not, and the $table_prefix variable is not set in your tests config file then it will use wptests_ as a fallback. $table_prefix = 'wp_'; // Only numbers, letters, and underscores please! #define( 'WPLANG', '' ); -/* minimal set of constants required by wp php unit */ +/* minimal set of constants required by wp php unit */ define( 'WP_TESTS_DOMAIN', 'example.org' ); define( 'WP_TESTS_EMAIL', 'admin@example.org' ); define( 'WP_TESTS_TITLE', 'Test Blog' );