Skip to content

Commit

Permalink
Merge branch 'main' into #187
Browse files Browse the repository at this point in the history
Signed-off-by: Namith Jawahar <[email protected]>
  • Loading branch information
namithj authored Dec 20, 2024
2 parents ae2f867 + c91e36b commit a094256
Show file tree
Hide file tree
Showing 43 changed files with 3,821 additions and 46 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/generate-pot-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Generate POT PR

on:
workflow_dispatch:
push:
branches:
- main

jobs:
generate-pot:
name: Generate POT PR
if: github.repository == 'aspirepress/aspireupdate'
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Set up PHP environment
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"

- name: Setup WP-CLI
uses: godaddy-wordpress/setup-wp-cli@1

- name: Configure git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Andy Fragen"
- name: Check if remote branch exists
run: echo "REMOTE_BRANCH_EXISTS=$([[ -z $(git ls-remote --heads origin generate-pot) ]] && echo "0" || echo "1")" >> $GITHUB_ENV

- name: Create branch to base pull request on
if: env.REMOTE_BRANCH_EXISTS == 0
run: |
git checkout -b generate-pot
- name: Fetch existing branch to add commits to
if: env.REMOTE_BRANCH_EXISTS == 1
run: |
git fetch --all --prune
git checkout generate-pot
git pull --no-rebase
- name: Generate POT
run: |
wp i18n make-pot . "./languages/${{ github.event.repository.name }}.pot" --headers='{"Report-Msgid-Bugs-To":"https://github.com/${{ github.event.repository.full_name }}/issues"}'
- name: Check if there are changes
run: echo "CHANGES_DETECTED=$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")" >> $GITHUB_ENV

- name: Commit changes
if: env.CHANGES_DETECTED == 1
run: |
git add "./languages/${{ github.event.repository.name }}.pot"
git commit -m "Generate POT - $(date +'%Y-%m-%d')"
git push origin generate-pot
- name: Create pull request
if: env.CHANGES_DETECTED == 1
uses: repo-sync/pull-request@v2
with:
source_branch: generate-pot
destination_branch: ${{ github.event.repository.default_branch }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: Generate POT
pr_body: "This is an automated pull-request"
26 changes: 0 additions & 26 deletions .github/workflows/generate-pot.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions includes/class-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function reset_settings() {
network_admin_url( 'index.php?page=aspireupdate-settings' )
)
);
exit;
! defined( 'AP_RUN_TESTS' ) && exit;
}
}

Expand Down Expand Up @@ -279,7 +279,7 @@ public function update_settings() {
network_admin_url( 'index.php?page=aspireupdate-settings' )
)
);
exit;
! defined( 'AP_RUN_TESTS' ) && exit;
}
}

Expand Down Expand Up @@ -324,7 +324,7 @@ public function admin_enqueue_scripts( $hook ) {
[
'ajax_url' => network_admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'aspireupdate-ajax' ),
'domain' => Utilities::get_top_level_domain(),
'domain' => Utilities::get_site_domain(),
'line_ending' => PHP_EOL,
'unexpected_error' => esc_html__( 'Unexpected Error', 'aspireupdate' ),
]
Expand Down Expand Up @@ -506,6 +506,8 @@ public function register_settings() {
/**
* The Fields API which any CMS should have in its core but something we dont, hence this ugly hack.
*
* @codeCoverageIgnore Test with E2E tests instead.
*
* @param array $args The Field Parameters.
*
* @return void Echos the Field HTML.
Expand Down
6 changes: 6 additions & 0 deletions includes/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct() {
/**
* Enable API Rewrites based on the Users settings.
*
* @codeCoverageIgnore Side-effects are from other methods already covered by tests.
*
* @return void
*/
private function api_rewrite() {
Expand All @@ -52,6 +54,8 @@ private function api_rewrite() {
/**
* Ajax action to clear the Log file.
*
* @codeCoverageIgnore Cannot be tested. Results in script termination.
*
* @return void
*/
public function clear_log() {
Expand Down Expand Up @@ -82,6 +86,8 @@ public function clear_log() {
/**
* Ajax action to read the Log file.
*
* @codeCoverageIgnore Cannot be tested. Results in script termination.
*
* @return void
*/
public function read_log() {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static function verify_filesystem( $wp_filesystem ) {
/**
* Log error in file write fails only if debug is set to true. This is a valid use case.
*/
error_log( 'AspireUpdate - Could not open or write to the file system. Check file system permissions to debug log directory.' );
error_log( 'AspireUpdate - Could not open or write to the file system. Check file system permissions to debug log directory.' ); // @codeCoverageIgnore
// phpcs:enable
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions includes/class-themes-screens.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function admin_enqueue_scripts( $hook ) {
public function redirect_to_theme_install() {

$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : false;
if ( $nonce && ! wp_verify_nonce( $nonce, 'query-themes' ) ) {
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'query-themes' ) ) {
return;
}

Expand All @@ -105,7 +105,7 @@ public function redirect_to_theme_install() {
$admin_settings = Admin_Settings::get_instance();
if ( $admin_settings->get_setting( 'enable', false ) ) {
wp_safe_redirect( admin_url( 'theme-install.php' ) );
exit;
! defined( 'AP_RUN_TESTS' ) && exit;
}
}
}
13 changes: 5 additions & 8 deletions includes/class-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
* The Class for Admin Settings Page and functions to access Settings Values.
*/
class Utilities {

/**
* Get the top level domain name from the site URL.
* Get the domain name from the site URL.
*
* @return string the top level domain name.
* @return string The domain name.
*/
public static function get_top_level_domain() {
$site_url = get_site_url();
$domain_name = wp_parse_url( $site_url, PHP_URL_HOST );
$domain_parts = explode( '.', $domain_name );
return sanitize_text_field( implode( '.', array_slice( $domain_parts, -2 ) ) );
public static function get_site_domain() {
$site_url = network_site_url();
return wp_parse_url( $site_url, PHP_URL_HOST );
}

/**
Expand Down
24 changes: 24 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,28 @@
<rule ref="WordPress.PHP.NoSilencedErrors.Discouraged">
<exclude-pattern>includes/class-filesystem-direct\.php</exclude-pattern>
</rule>

<!-- Exclude test classes from naming conventions. -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/tests/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>/tests/phpunit/*</exclude-pattern>
</rule>

<!-- Exclude test files from overriding globals sniff. -->
<rule ref="WordPress.WP.GlobalVariablesOverride.Prohibited">
<exclude-pattern>/tests/phpunit/tests/*</exclude-pattern>
</rule>

<!-- Exclude test files from some filesystem sniffs. -->
<rule ref="WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents">
<exclude-pattern>/tests/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents">
<exclude-pattern>/tests/phpunit/*</exclude-pattern>
</rule>
<rule ref="WordPress.WP.AlternativeFunctions.unlink_unlink">
<exclude-pattern>/tests/phpunit/*</exclude-pattern>
</rule>
</ruleset>
7 changes: 7 additions & 0 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ function _manually_load_plugin() {

// Start up the WP testing environment.
require "{$_tests_dir}/includes/bootstrap.php";

// Load unit test mocks and fakes.
require __DIR__ . '/includes/class-ap-fake-filesystem.php';

// Load unit test abstract classes.
require __DIR__ . '/includes/AdminSettings_UnitTestCase.php';
require __DIR__ . '/includes/Debug_UnitTestCase.php';
32 changes: 32 additions & 0 deletions tests/phpunit/includes/AdminSettings_UnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Abstract base test class for \AspireUpdate\Admin_Settings.
*
* All \AspireUpdate\Admin_Settings unit tests should inherit from this class.
*/
abstract class AdminSettings_UnitTestCase extends WP_UnitTestCase {
/**
* The Name of the Option.
*
* @var string
*/
protected static $option_name = 'aspireupdate_settings';

/**
* The Slug of the Option's page.
*
* @var string
*/
protected static $options_page = 'aspireupdate-settings';

/**
* Deletes settings before each test runs.
*
* @return void
*/
public function set_up() {
parent::set_up();

delete_site_option( self::$option_name );
}
}
Loading

0 comments on commit a094256

Please sign in to comment.