Skip to content

Commit

Permalink
Merge pull request #638 from Flynsarmy/fileHelperTest
Browse files Browse the repository at this point in the history
Add some FilesHelper tests
  • Loading branch information
leonstafford authored Aug 25, 2020
2 parents 1efd2bd + bc05963 commit 5b82df5
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 30 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"wp-coding-standards/wpcs": "*",
"phpcompatibility/php-compatibility": "*",
"php-parallel-lint/php-parallel-lint": "*",
"10up/wp_mock": "^0.4.2"
"10up/wp_mock": "^0.4.2",
"mikey179/vfsstream": "^1.6"
},
"autoload": {
"psr-4": {
Expand Down
92 changes: 69 additions & 23 deletions composer.lock

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

18 changes: 12 additions & 6 deletions src/FilesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static function delete_dir_with_files( string $dir ) : void {
}

/**
* Get public URLs for all files in a local directory
* Get public URLs for all files in a local directory.
*
* @return string[] list of URLs
* @return string[] list of relative, urlencoded URLs
*/
public static function getListOfLocalFilesByDir( string $dir ) : array {
$files = [];
Expand Down Expand Up @@ -71,6 +71,12 @@ public static function getListOfLocalFilesByDir( string $dir ) : array {
return $files;
}

/**
* Ensure a given filepath has an allowed filename and extension.
*
* @return bool True if the given file does not have a disallowed filename
* or extension.
*/
public static function filePathLooksCrawlable( string $file_name ) : bool {
$filenames_to_ignore = [
'__MACOSX',
Expand Down Expand Up @@ -176,10 +182,11 @@ function( $file_extension ) {
}

/**
* Clean all detected URLs before use
* Clean all detected URLs before use. Accepts relative and absolute URLs
* both with and without starting or trailing slashes.
*
* @param string[] $urls list of URLs
* @return string[] list of URLs
* @param string[] $urls list of absolute or relative URLs
* @return string[] list of relative URLs
* @throws WP2StaticException
*/
public static function cleanDetectedURLs( array $urls ) : array {
Expand Down Expand Up @@ -232,4 +239,3 @@ function ( $url ) use ( $home_url ) {
return $cleaned_urls;
}
}

Loading

0 comments on commit 5b82df5

Please sign in to comment.