From 31506959a7b6a99afbf87b74081c259b8cf05e97 Mon Sep 17 00:00:00 2001 From: Brooke Date: Mon, 19 Jun 2023 13:37:44 -0700 Subject: [PATCH 01/91] Date data should be in UTC before passing to strtotime() PHP's `strtotime()` uses the epoch time which is expecting the time format in UTC instead of local time. This PR updates `$date` to use `$post->post_date_gmt` instead of `$post->post_date` for proper timezone conversations. Fixes #1006 --- admin/apple-actions/index/class-export.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/apple-actions/index/class-export.php b/admin/apple-actions/index/class-export.php index bf7e9ddf..dfdad36e 100644 --- a/admin/apple-actions/index/class-export.php +++ b/admin/apple-actions/index/class-export.php @@ -341,8 +341,8 @@ public function format_byline( $post, $author = '', $date = '' ) { } // Get the date. - if ( empty( $date ) && ! empty( $post->post_date ) ) { - $date = $post->post_date; + if ( empty( $date ) && ! empty( $post->post_date_gmt ) ) { + $date = $post->post_date_gmt; } // Set the default date format. From 7fc9add9bf1db469f1f6605e4501d8fd7e8f53e6 Mon Sep 17 00:00:00 2001 From: Daniel Gregory Date: Tue, 25 Jul 2023 12:26:50 +0100 Subject: [PATCH 02/91] Use options.php instead of null --- admin/class-admin-apple-bulk-export-page.php | 2 +- admin/class-admin-apple-themes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/class-admin-apple-bulk-export-page.php b/admin/class-admin-apple-bulk-export-page.php index 76cb25d8..536cc919 100644 --- a/admin/class-admin-apple-bulk-export-page.php +++ b/admin/class-admin-apple-bulk-export-page.php @@ -52,7 +52,7 @@ public function __construct( $settings ) { */ public function register_page() { add_submenu_page( - null, // Parent, if null, it won't appear in any menu. + 'options.php', // Parent, if 'options.php', it won't appear in any menu. __( 'Bulk Export', 'apple-news' ), // Page title. __( 'Bulk Export', 'apple-news' ), // Menu title. /** diff --git a/admin/class-admin-apple-themes.php b/admin/class-admin-apple-themes.php index fb36ef12..43a08ab5 100644 --- a/admin/class-admin-apple-themes.php +++ b/admin/class-admin-apple-themes.php @@ -478,7 +478,7 @@ public function setup_theme_pages() { // Add the edit theme page. add_submenu_page( - null, + 'options.php', __( 'Apple News Edit Theme', 'apple-news' ), __( 'Edit Theme', 'apple-news' ), /** This filter is documented in admin/class-admin-apple-settings.php */ From a988b0b280cb937aae6f7ba7ed4f834a3d7f7b33 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:50:53 -0600 Subject: [PATCH 03/91] Refactor node-tests workflow with a common GitHub Action The node-tests workflow steps have been replaced with a shared GitHub Action from 'alleyinteractive'. This simplifies the workflow file making it more readable and maintainable. Additional configurations like ci mode, node version, and working directory are enabled; hence enhancing the node-tests setup process. --- .github/workflows/node-tests.yml | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/.github/workflows/node-tests.yml b/.github/workflows/node-tests.yml index 55dd44e5..6251c548 100644 --- a/.github/workflows/node-tests.yml +++ b/.github/workflows/node-tests.yml @@ -4,25 +4,10 @@ on: pull_request: jobs: - npm-ci: - name: (npm) Install, build, and test - runs-on: ubuntu-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - all_but_latest: true - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - - name: Install node dependencies (npm ci) - run: npm ci - - name: Run npm lint - run: npm run lint - - name: Run npm test - run: npm run test - - name: Run npm build - run: npm run build + node-tests: + uses: alleyinteractive/.github/.github/workflows/node-tests.yml@main + with: + ci: true + node: 16 + run-audit: false + working-directory: ./ From 8b86909cf9d8e2258328c54676e144e17a80a30c Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:54:39 -0600 Subject: [PATCH 04/91] Refactor PHPUnit GitHub workflow for simplicity The PHPUnit GitHub workflow was significantly simplified by reducing the amount of work done in the YAML file. The previous workflow was manually setting up the test environment (downloading WordPress, setting up MySQL, etc.) within this file. The updated workflow uses a custom GitHub action that handles these setup steps, resulting in a cleaner and easier to read workflow file. Moreover, the PHP versions and WordPress version for testing have been updated to reflect more current versions. --- .github/workflows/phpunit.yml | 57 +++++++---------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 04663c50..48e674cc 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -1,51 +1,16 @@ -name: Unit Tests +name: Testing Suite + on: pull_request: - workflow_dispatch: + jobs: - tests: - name: "PHP: ${{ matrix.php }} (MU: ${{ matrix.multisite }})" - runs-on: ubuntu-latest + php-tests: strategy: - fail-fast: true matrix: - multisite: [0, 1] - php: ['8.0', '7.4', '7.3', '7.2', '7.1'] - env: - WP_CORE_DIR: /tmp/wordpress/ - WP_MULTISITE: ${{ matrix.multisite }} - services: - mysql: - image: mysql:5.7 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - all_but_latest: true - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd - coverage: none - - name: Install dependencies - uses: ramsey/composer-install@v2 - - name: Set up WordPress - run: | - bash <(curl -s "https://raw.githubusercontent.com/wp-cli/sample-plugin/master/bin/install-wp-tests.sh") wordpress_unit_tests root '' 127.0.0.1 - rm -rf "${WP_CORE_DIR}wp-content/plugins" - mkdir -p "${WP_CORE_DIR}wp-content/plugins/publish-to-apple-news" - rsync -a --exclude=.git . "${WP_CORE_DIR}wp-content/plugins/publish-to-apple-news" - cd ${WP_CORE_DIR}wp-content/plugins/publish-to-apple-news && composer install - - name: Run tests - shell: bash - run: | - cd ${WP_CORE_DIR}/wp-content/plugins/publish-to-apple-news - composer run phpunit + php: ['8.2', '8.1', '8.0', '7.4'] + wordpress: ["latest"] + uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main + with: + command: "test" + php: ${{ matrix.php }} + wordpress: ${{ matrix.wordpress }} From dd693811df212eafaaece485b107babc7eb4d467 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:14:50 -0600 Subject: [PATCH 05/91] "Update composer script for testing Added new script 'test' to composer.json file. This script combines two existing scripts, 'phpcs' and 'phpunit', making it more efficient to run both scripts for testing. Also, 'phpcs' script has been updated with '--basepath=.' argument to set the base directory for relative paths." --- composer.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 948c07b6..f69ebc83 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,12 @@ }, "scripts": { "phpcbf" : "phpcbf .", - "phpcs" : "phpcs .", - "phpunit" : "phpunit" + "phpcs" : "phpcs . --basepath=.", + "phpunit" : "phpunit", + "test": [ + "@phpcs", + "@phpunit" + ] }, "config": { "allow-plugins": { From faf3c865a135ad1dc949ddabb2d4637485d3e6e4 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:24:31 -0600 Subject: [PATCH 06/91] Update phpcs command in composer.json The basepath option was removed from the phpcs command in composer.json. The basepath option was found to be unnecessary because phpcs runs relative to the project root by default. Thus, removing this option simplifies the command without changing its functionality. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f69ebc83..c32c3285 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "scripts": { "phpcbf" : "phpcbf .", - "phpcs" : "phpcs . --basepath=.", + "phpcs" : "phpcs .", "phpunit" : "phpunit", "test": [ "@phpcs", From 55477bb9eeebe0868492b67f2577d6ca32872390 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 14:42:53 -0600 Subject: [PATCH 07/91] Update composer dependencies and PHP version This commit updates the composer.json file. The dependencies versions have been changed to more recent versions and the required PHP version has been updated too. These changes support more recent and secure code usage conventions. --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index c32c3285..cc5b1382 100644 --- a/composer.json +++ b/composer.json @@ -5,13 +5,13 @@ "type" : "wordpress-plugin", "license" : "GPL-3.0-or-later", "require" : { - "composer/installers": "~1.0", - "php": ">=7.1" + "composer/installers": "^1.12.0", + "php": "^8.0" }, "require-dev": { - "phpspec/prophecy": "~1.0", - "alleyinteractive/alley-coding-standards": "^0.3.0", - "yoast/phpunit-polyfills": "^1.0" + "phpspec/prophecy": "^1.17.0", + "alleyinteractive/alley-coding-standards": "^2.0.1", + "yoast/phpunit-polyfills": "^2.0" }, "scripts": { "phpcbf" : "phpcbf .", From a03727662bedece62c302c5a4a523247ed3749bd Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:00:25 -0600 Subject: [PATCH 08/91] Simplify PHPCS action in workflow file Refactored the PHP Coding Standards action block in Github workflow file (.github/workflows/phpcs.yml). Removed redundant steps, and migrated job definition to use the prepared PHP coding standards action. This change provides a cleaner and less error-prone setup, allowing more focus on PHP Coding Standards execution. --- .github/workflows/phpcs.yml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 38a3269e..634e1e89 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -1,25 +1,17 @@ name: PHP Coding Standards + on: pull_request: - workflow_dispatch: + jobs: phpcs: - runs-on: ubuntu-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - all_but_latest: true - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - coverage: none - - name: Validate Composer package - run: composer validate --strict - - name: Install dependencies - uses: ramsey/composer-install@v2 - - name: Run PHPCS - run: composer phpcs + strategy: + matrix: + php: [ 8.0 ] + wordpress: [ "latest" ] + uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main + with: + command: "phpcs" + php: ${{ matrix.php }} + wordpress: ${{ matrix.wordpress }} + working-directory: ./ From 6d14b470badf484dda1fb58bb31333b160380622 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:05:25 -0600 Subject: [PATCH 09/91] Remove WordPress matrix from PHPCS workflow Removed the WordPress version matrix from the PHP Code Sniffer (PHPCS) GitHub Actions workflow. This is because we no longer need to test against different WordPress versions, simplifying the workflow and reducing the resources needed for testing. --- .github/workflows/phpcs.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 634e1e89..10727c9f 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -8,10 +8,7 @@ jobs: strategy: matrix: php: [ 8.0 ] - wordpress: [ "latest" ] uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main with: command: "phpcs" php: ${{ matrix.php }} - wordpress: ${{ matrix.wordpress }} - working-directory: ./ From fae39945ced95ed3e5ade45402c51073901dd10a Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:09:00 -0600 Subject: [PATCH 10/91] Remove redundant "phpcs" command from workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "command: phpcs" line was removed from the phpcs.yml workflow file. This change was necessary as the command is already specified in the php-coding-standards.yml workflow from alleyinteractive repository and doesn’t need to be defined twice. This refactoring helps to avoid confusion and potential command conflicts in the future. --- .github/workflows/phpcs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 10727c9f..0115c7f9 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -10,5 +10,4 @@ jobs: php: [ 8.0 ] uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main with: - command: "phpcs" php: ${{ matrix.php }} From f967836d9a662b27979381bca1a919393f17655a Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:40:54 -0600 Subject: [PATCH 11/91] Add null checks and private variables for to address PHP notices and deprecations Added null checks in `function-coauthors.php` and `class-components.php` to prevent possible undefined behaviour when handling non-initialized variables. This makes the code more robust and resilient to potential errors. Moreover, added private string variables in `test-class-table.php` and private `Admin_Apple_Themes` variable to the `test-class-admin-apple-themes.php` which improves the readability and structure of these files. --- includes/apple-exporter/builders/class-components.php | 4 ++++ tests/admin/test-class-admin-apple-themes.php | 1 + tests/apple-exporter/components/test-class-table.php | 2 ++ tests/mocks/function-coauthors.php | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/includes/apple-exporter/builders/class-components.php b/includes/apple-exporter/builders/class-components.php index d8d27a81..a8bf0b53 100644 --- a/includes/apple-exporter/builders/class-components.php +++ b/includes/apple-exporter/builders/class-components.php @@ -526,6 +526,10 @@ private function get_components_from_node( $node ) { */ private function get_image_full_size_url( $url ) { + if(null === $url) { + return ''; + } + // Strip URL formatting for easier matching. $url = urldecode( $url ); diff --git a/tests/admin/test-class-admin-apple-themes.php b/tests/admin/test-class-admin-apple-themes.php index 34811397..a0cbc851 100644 --- a/tests/admin/test-class-admin-apple-themes.php +++ b/tests/admin/test-class-admin-apple-themes.php @@ -16,6 +16,7 @@ * A class which is used to test the Admin_Apple_Themes class. */ class Admin_Apple_Themes_Test extends Apple_News_Testcase { + private Admin_Apple_Themes $themes; /** * A helper function to create the default theme. diff --git a/tests/apple-exporter/components/test-class-table.php b/tests/apple-exporter/components/test-class-table.php index 70468b7b..2172314c 100644 --- a/tests/apple-exporter/components/test-class-table.php +++ b/tests/apple-exporter/components/test-class-table.php @@ -18,6 +18,8 @@ * @subpackage Tests */ class Apple_News_Table_Test extends Apple_News_Component_TestCase { + private string $html; + private string $html_caption; /** * A fixture containing operations to be run before each test. diff --git a/tests/mocks/function-coauthors.php b/tests/mocks/function-coauthors.php index c7c56a0e..fa5c2e9c 100644 --- a/tests/mocks/function-coauthors.php +++ b/tests/mocks/function-coauthors.php @@ -29,6 +29,10 @@ function coauthors( $between = ', ', $between_last = ' and ', $before = '', $aft // Get last index. $last_index = count( $apple_news_coauthors ) - 1; + if(null === $between) { + $between = ', '; + } + // Compute output. $output = $before . implode( $between, array_slice( $apple_news_coauthors, 0, $last_index ) ) From c4c762889f26f4aa1c30a54f93083223372cb317 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:50:35 -0600 Subject: [PATCH 12/91] Downgrade PHP version requirement in composer.json PHP version requirement in composer.json was changed from "^8.0" to "^7.4" to ensure compatibility with older PHP environments. This will allow the project to be integrated into systems that have not yet updated to the newest PHP version. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cc5b1382..ceae6650 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license" : "GPL-3.0-or-later", "require" : { "composer/installers": "^1.12.0", - "php": "^8.0" + "php": "^7.4" }, "require-dev": { "phpspec/prophecy": "^1.17.0", From ec87ffa823a3c8309c7763f183932de3668c782a Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:52:57 -0600 Subject: [PATCH 13/91] "Configure PHP CodeSniffer to run only in non-draft PRs" This update adjusts the GitHub Action for running PHP CodeSniffer to trigger only for non-draft pull requests on 'develop' branch. The purpose is to minimize unnecessary runs and provide feedback only when code is ready for review. --- .github/workflows/phpcs.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 0115c7f9..6929e16a 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -2,12 +2,16 @@ name: PHP Coding Standards on: pull_request: + branches: + - develop + types: [ opened, synchronize, reopened, ready_for_review ] jobs: phpcs: strategy: matrix: php: [ 8.0 ] + if: github.event.pull_request.draft == false uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main with: php: ${{ matrix.php }} From 4dd25844aa7b0124b869e8036d0f6e52e94a57b0 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:56:59 -0600 Subject: [PATCH 14/91] Update GitHub Actions to refine pull request triggers This commit updates the GitHub workflow for PHPunit, PHPCS, and node tests. The workflows are now triggered only pull requests towards the develop branch and exclude draft pull requests. This prevents unnecessary running of these workflows on every pull request. Additionally, the PHP version for PHPCS has been updated from 8.0 to 8.2 to align with the latest PHP version usage. --- .github/workflows/node-tests.yml | 4 ++++ .github/workflows/phpcs.yml | 2 +- .github/workflows/phpunit.yml | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node-tests.yml b/.github/workflows/node-tests.yml index 6251c548..e0c79509 100644 --- a/.github/workflows/node-tests.yml +++ b/.github/workflows/node-tests.yml @@ -2,9 +2,13 @@ name: Node Tests on: pull_request: + branches: + - develop + types: [ opened, synchronize, reopened, ready_for_review ] jobs: node-tests: + if: github.event.pull_request.draft == false uses: alleyinteractive/.github/.github/workflows/node-tests.yml@main with: ci: true diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 6929e16a..1ebaa122 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -10,7 +10,7 @@ jobs: phpcs: strategy: matrix: - php: [ 8.0 ] + php: [ 8.2 ] if: github.event.pull_request.draft == false uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main with: diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 48e674cc..7abb72b5 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -2,6 +2,9 @@ name: Testing Suite on: pull_request: + branches: + - develop + types: [ opened, synchronize, reopened, ready_for_review ] jobs: php-tests: @@ -9,6 +12,7 @@ jobs: matrix: php: ['8.2', '8.1', '8.0', '7.4'] wordpress: ["latest"] + if: github.event.pull_request.draft == false uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main with: command: "test" From fd06ac3e620f27779ac9f113d3f24f25e4098e94 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:58:38 -0600 Subject: [PATCH 15/91] Add multisite testing to GitHub Actions An addition to the test matrix in the GitHub Actions configuration for PHPUnit was made to include multisite setups. This change ensures that the codebase is compatible with WordPress multisite environments. --- .github/workflows/phpunit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 7abb72b5..097c7b9a 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -10,6 +10,7 @@ jobs: php-tests: strategy: matrix: + multisite: [0, 1] php: ['8.2', '8.1', '8.0', '7.4'] wordpress: ["latest"] if: github.event.pull_request.draft == false From 0066034e067bc7d94d2d5d0c1dc4133fbcc366d2 Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:08:14 -0600 Subject: [PATCH 16/91] Add PHP docblocks for HTML and caption fields in Table_Test and Themes_Test classes --- tests/admin/test-class-admin-apple-themes.php | 8 +++++++- tests/apple-exporter/components/test-class-table.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/admin/test-class-admin-apple-themes.php b/tests/admin/test-class-admin-apple-themes.php index a0cbc851..3e580c41 100644 --- a/tests/admin/test-class-admin-apple-themes.php +++ b/tests/admin/test-class-admin-apple-themes.php @@ -13,9 +13,15 @@ use Apple_Exporter\Theme; /** - * A class which is used to test the Admin_Apple_Themes class. + * */ class Admin_Apple_Themes_Test extends Apple_News_Testcase { + + /** + * Admin themes. + * + * @var Admin_Apple_Themes + */ private Admin_Apple_Themes $themes; /** diff --git a/tests/apple-exporter/components/test-class-table.php b/tests/apple-exporter/components/test-class-table.php index 2172314c..6bd4d485 100644 --- a/tests/apple-exporter/components/test-class-table.php +++ b/tests/apple-exporter/components/test-class-table.php @@ -18,7 +18,17 @@ * @subpackage Tests */ class Apple_News_Table_Test extends Apple_News_Component_TestCase { + /** + * The HTML code to display + * . + * @var string $html + */ private string $html; + /** + * The caption for the HTML. + * + * @var string $html_caption + */ private string $html_caption; /** From 1410294bb8179c00d627f7b40867745ae851b83a Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:18:21 -0600 Subject: [PATCH 17/91] Fix failing unit tests due to unset defaults Amended default conditions from null checks to empty checks in function-coauthors.php and class-components.php. Previously, there were no defaults set when running unit tests which led to unexpected fails. This change will ensure that unit tests pass even when certain parameters are not explicitly set. --- includes/apple-exporter/builders/class-components.php | 2 +- tests/mocks/function-coauthors.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/apple-exporter/builders/class-components.php b/includes/apple-exporter/builders/class-components.php index a8bf0b53..8aa77c02 100644 --- a/includes/apple-exporter/builders/class-components.php +++ b/includes/apple-exporter/builders/class-components.php @@ -526,7 +526,7 @@ private function get_components_from_node( $node ) { */ private function get_image_full_size_url( $url ) { - if(null === $url) { + if( empty( $url ) ) { return ''; } diff --git a/tests/mocks/function-coauthors.php b/tests/mocks/function-coauthors.php index fa5c2e9c..64abd311 100644 --- a/tests/mocks/function-coauthors.php +++ b/tests/mocks/function-coauthors.php @@ -29,7 +29,9 @@ function coauthors( $between = ', ', $between_last = ' and ', $before = '', $aft // Get last index. $last_index = count( $apple_news_coauthors ) - 1; - if(null === $between) { + // Default was not set when running unit tests, + // causing failures. + if(empty( $between)) { $between = ', '; } From f59d6beac877ac74f8be5c057a975d3bad36904f Mon Sep 17 00:00:00 2001 From: Damian Taggart <4309872+attackant@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:20:16 -0600 Subject: [PATCH 18/91] "PHPCBF changes updated class imports and formatting across multiple modules" Removed unnecessary aliases from class imports for improved readability and simplified access statements. Change usage of 'dirname( FILE )' to '__DIR__' for cleaner calls. Also made minor formatting updates, such as making spaces consistent around parentheses and adding increment from prefix to postfix form in for loops for better standardization. The changes were done to increase the code quality without affecting the functional behavior of the codebase. --- admin/apple-actions/class-action.php | 1 - admin/apple-actions/class-api-action.php | 7 +++--- admin/apple-actions/index/class-delete.php | 3 +-- admin/apple-actions/index/class-get.php | 2 +- admin/apple-actions/index/class-push.php | 6 ++--- admin/class-admin-apple-index-page.php | 3 +-- admin/class-admin-apple-news.php | 6 ++--- admin/class-admin-apple-notice.php | 2 +- admin/class-admin-apple-settings.php | 2 +- admin/class-automation.php | 4 ++-- admin/partials/field-meta-component-order.php | 4 ++-- admin/partials/index.php | 1 - ...dmin-apple-settings-section-post-types.php | 1 - .../class-admin-apple-settings-section.php | 2 +- includes/REST/apple-news-delete.php | 4 ++-- includes/REST/apple-news-publish.php | 4 ++-- includes/REST/apple-news-update.php | 4 ++-- includes/REST/apple-news-user-can-publish.php | 2 +- .../builders/class-component-layouts.php | 3 +-- .../builders/class-components.php | 22 +++++++++---------- .../apple-exporter/builders/class-layout.php | 1 - .../builders/class-metadata.php | 2 +- .../class-exporter-content-settings.php | 1 - .../apple-exporter/class-exporter-content.php | 1 - .../components/class-advertisement.php | 1 - .../apple-exporter/components/class-audio.php | 3 +-- .../apple-exporter/components/class-body.php | 1 - .../components/class-component.php | 6 ++--- .../apple-exporter/components/class-date.php | 2 -- .../components/class-divider.php | 2 -- .../components/class-end-of-article.php | 1 - .../components/class-gallery.php | 4 ++-- .../components/class-heading.php | 2 -- .../apple-exporter/components/class-intro.php | 2 -- .../components/class-link-button.php | 1 - .../apple-exporter/components/class-slug.php | 1 - .../apple-exporter/components/class-title.php | 2 -- .../apple-exporter/components/class-tweet.php | 1 - .../apple-exporter/components/class-video.php | 2 +- .../class-jetpack-tiled-gallery.php | 2 +- includes/apple-push-api/class-api.php | 3 +-- includes/apple-push-api/class-credentials.php | 1 - .../apple-push-api/class-mime-builder.php | 3 +-- .../apple-push-api/request/class-request.php | 10 ++++----- .../builders/test-class-components.php | 4 ++-- .../components/test-class-advertisement.php | 2 +- .../components/test-class-audio.php | 2 +- .../components/test-class-divider.php | 2 +- .../components/test-class-table.php | 1 + .../components/test-class-tweet.php | 2 +- tests/bootstrap.php | 4 ++-- tests/mocks/function-coauthors.php | 2 +- 52 files changed, 63 insertions(+), 94 deletions(-) diff --git a/admin/apple-actions/class-action.php b/admin/apple-actions/class-action.php index 6e4dcdf5..00a93a1e 100644 --- a/admin/apple-actions/class-action.php +++ b/admin/apple-actions/class-action.php @@ -50,5 +50,4 @@ abstract public function perform(); protected function get_setting( $name ) { return $this->settings->get( $name ); } - } diff --git a/admin/apple-actions/class-api-action.php b/admin/apple-actions/class-api-action.php index 5512e3d0..a4da4de4 100644 --- a/admin/apple-actions/class-api-action.php +++ b/admin/apple-actions/class-api-action.php @@ -12,9 +12,9 @@ require_once plugin_dir_path( __FILE__ ) . 'class-action-exception.php'; require_once plugin_dir_path( __FILE__ ) . '../../includes/apple-push-api/autoload.php'; -use Apple_Actions\Action as Action; -use Apple_Push_API\API as API; -use Apple_Push_API\Credentials as Credentials; +use Apple_Actions\Action; +use Apple_Push_API\API; +use Apple_Push_API\Credentials; /** * A base class that API-related actions can extend. @@ -88,5 +88,4 @@ protected function is_api_configuration_valid() { return true; } - } diff --git a/admin/apple-actions/index/class-delete.php b/admin/apple-actions/index/class-delete.php index 6c33645b..e9d4fb2c 100644 --- a/admin/apple-actions/index/class-delete.php +++ b/admin/apple-actions/index/class-delete.php @@ -10,7 +10,7 @@ require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php'; -use Apple_Actions\API_Action as API_Action; +use Apple_Actions\API_Action; /** * A class to handle a delete request from the admin. @@ -103,5 +103,4 @@ private function delete() { return $e->getMessage(); } } - } diff --git a/admin/apple-actions/index/class-get.php b/admin/apple-actions/index/class-get.php index 03ce4b64..66f22194 100644 --- a/admin/apple-actions/index/class-get.php +++ b/admin/apple-actions/index/class-get.php @@ -10,7 +10,7 @@ require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php'; -use Apple_Actions\API_Action as API_Action; +use Apple_Actions\API_Action; /** * A class to handle a get request from the admin. diff --git a/admin/apple-actions/index/class-push.php b/admin/apple-actions/index/class-push.php index 739d4b36..bd753bc6 100644 --- a/admin/apple-actions/index/class-push.php +++ b/admin/apple-actions/index/class-push.php @@ -11,9 +11,9 @@ require_once plugin_dir_path( __FILE__ ) . '../class-api-action.php'; require_once plugin_dir_path( __FILE__ ) . 'class-export.php'; -use \Admin_Apple_Notice; -use \Admin_Apple_Sections; -use \Apple_Actions\API_Action; +use Admin_Apple_Notice; +use Admin_Apple_Sections; +use Apple_Actions\API_Action; /** * A class to handle a push request from the admin. diff --git a/admin/class-admin-apple-index-page.php b/admin/class-admin-apple-index-page.php index 2370a734..51adeb3c 100644 --- a/admin/class-admin-apple-index-page.php +++ b/admin/class-admin-apple-index-page.php @@ -15,7 +15,7 @@ require_once plugin_dir_path( __FILE__ ) . 'apple-actions/index/class-section.php'; require_once plugin_dir_path( __FILE__ ) . 'class-admin-apple-news-list-table.php'; -use \Apple_Exporter\Workspace as Workspace; +use Apple_Exporter\Workspace; /** * A class to manage the index page of the Apple News admin interface. @@ -441,5 +441,4 @@ private function reset_action( $id ) { // This can only succeed. $this->notice_success( __( 'Your article status has been successfully reset!', 'apple-news' ) ); } - } diff --git a/admin/class-admin-apple-news.php b/admin/class-admin-apple-news.php index a4cd6eb5..fc39a0e4 100644 --- a/admin/class-admin-apple-news.php +++ b/admin/class-admin-apple-news.php @@ -183,11 +183,11 @@ public function __construct() { // Prevent Yoast Duplicate Post plugin from cloning apple_news meta. add_filter( 'duplicate_post_meta_keys_filter', - function( $meta_keys ) { + function ( $meta_keys ) { return is_array( $meta_keys ) ? array_filter( $meta_keys, - function( $key ) { + function ( $key ) { return substr( $key, 0, 11 ) !== 'apple_news_'; } ) @@ -197,7 +197,7 @@ function( $key ) { add_action( 'rest_api_init', - function() { + function () { $post_types = ! empty( self::$settings->post_types ) ? self::$settings->post_types : []; foreach ( $post_types as $post_type ) { diff --git a/admin/class-admin-apple-notice.php b/admin/class-admin-apple-notice.php index 0b3d153a..a8976f63 100644 --- a/admin/class-admin-apple-notice.php +++ b/admin/class-admin-apple-notice.php @@ -56,7 +56,7 @@ public static function clear( $notifications ) { // Sort and JSON-encode the removal array to simplify comparison. $notifications = array_map( - function( $value ) { + function ( $value ) { ksort( $value ); return wp_json_encode( $value ); }, diff --git a/admin/class-admin-apple-settings.php b/admin/class-admin-apple-settings.php index da5b06ee..8dbc5adb 100644 --- a/admin/class-admin-apple-settings.php +++ b/admin/class-admin-apple-settings.php @@ -13,7 +13,7 @@ require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-post-types.php'; require_once plugin_dir_path( __FILE__ ) . 'settings/class-admin-apple-settings-section-developer-tools.php'; -use Apple_Exporter\Settings as Settings; +use Apple_Exporter\Settings; /** * This class is in charge of creating a WordPress page to manage the diff --git a/admin/class-automation.php b/admin/class-automation.php index 13ac5819..77b7df58 100644 --- a/admin/class-automation.php +++ b/admin/class-automation.php @@ -133,7 +133,7 @@ public static function filter__apple_news_article_metadata( $metadata, $post_id $metadata_rules = array_values( array_filter( self::get_automation_for_post( $post_id ), - function( $rule ) { + function ( $rule ) { return 'article_metadata' === self::get_fields()[ $rule['field'] ]['location'] ?? ''; } ) @@ -179,7 +179,7 @@ public static function get_automation_for_post( int $post_id ): array { return array_values( array_filter( self::get_automation_rules(), - function( $rule ) use ( $post_id ) { + function ( $rule ) use ( $post_id ) { return has_term( $rule['term_id'] ?? '', $rule['taxonomy'] ?? '', $post_id ); } ) diff --git a/admin/partials/field-meta-component-order.php b/admin/partials/field-meta-component-order.php index af97fe6a..1f4b0b98 100644 --- a/admin/partials/field-meta-component-order.php +++ b/admin/partials/field-meta-component-order.php @@ -18,7 +18,7 @@