Skip to content

Commit

Permalink
Refactor Code and Improve Test Cases
Browse files Browse the repository at this point in the history
### Changed
- Refactored test cases.
  • Loading branch information
smileBeda committed May 29, 2024
1 parent 006b7eb commit 691d978
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ This is NOT the changelog of the WordPress Plugin you ultimately develop!
- Updated minimum WordPress version requirement to 4.0.
- Refactored how metaboxes are registered and saved, improving code clarity .
- Renamed keys for shortcodes, taxonomies, and custom post types using a configurable slug.
- Replaced specific metabox class with a more generic example .
- Replaced specific metabox class with a more generic example.
- Refactored Test Cases.

### Removed
- Unused function imports across multiple files.

### Fixed
- Incorrect author information in several files.
- Require `wp-admin/includes/file.php` if WP_Filesystem is unavailable.

## [v5-alpha] - 2024-05-26

Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
}
tests_add_filter(
'muplugins_loaded',
function() use ( $_plugin_slug ) {
require_once dirname( dirname( __FILE__ ) ) . '/src/' . $_plugin_slug . '.php';
function () use ( $_plugin_slug ) {
require_once dirname( __DIR__ ) . '/src/' . $_plugin_slug . '.php';
}
);

Expand Down
49 changes: 34 additions & 15 deletions tests/class-filesystem-utilitytest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<?php
/**
* The PHPUnit Tests for the WP_Filesystem_Utility class
*
* This file adds test cases for the WP_Filesystem_Utility class.
* This file includes:
* - Strict Typing declaration,
* - Definition of WP_Filesystem_UtilityTest,
* - One testcase method for the Base64 Encoded Method of the WP_Filesystem_Utility class.
*
* @link https://site.tld
* @since 1.0.0 Introduced on 2023-08-01 15:30
* @package Plugins\PluginName\Tests
* @author Your Name <[email protected]>
*/

/**
* Declare strict typing
*
* @see https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict
*/
declare( strict_types = 1 );

namespace Company\Plugins\PluginName\Tests;

Expand All @@ -7,24 +28,22 @@

class WP_Filesystem_UtilityTest extends TestCase {

public function testGetBase64EncodedContents() {
$filesystemUtility = new WP_Filesystem_Utility();
public function testGetBase64EncodedContents() {
$filesystemUtility = new WP_Filesystem_Utility();

// Replace with the actual path to the SVG file you want to test
$svgFilePath = __DIR__ . '/../src/public/icons/cpt-icon.svg';
// Replace with the actual path to the SVG file you want to test
$svgFilePath = __DIR__ . '/../src/public/icons/cpt-icon.svg';

// Ensure that the file exists before testing
$this->assertFileExists($svgFilePath);
// Ensure that the file exists before testing
$this->assertFileExists( $svgFilePath );

// Get the expected base64 encoded content
$expectedBase64Content = base64_encode(file_get_contents($svgFilePath));
// Get the expected base64 encoded content
$expectedBase64Content = base64_encode( file_get_contents( $svgFilePath ) );

// Call the method to get base64 encoded content
$actualBase64Content = $filesystemUtility->get_base64_encoded_contents($svgFilePath);
// Call the method to get base64 encoded content
$actualBase64Content = $filesystemUtility->get_base64_encoded_contents( $svgFilePath );

// Check if the actual content matches the expected content
$this->assertEquals($expectedBase64Content, $actualBase64Content);
}

// Add more test cases as needed for other methods/functions in WP_Filesystem_Utility
// Check if the actual content matches the expected content
$this->assertEquals( $expectedBase64Content, $actualBase64Content );
}
}

0 comments on commit 691d978

Please sign in to comment.