Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #14

Open
2 tasks done
Tracked by #4
carstingaxion opened this issue Sep 20, 2023 · 1 comment
Open
2 tasks done
Tracked by #4

Add unit tests #14

carstingaxion opened this issue Sep 20, 2023 · 1 comment

Comments

@carstingaxion
Copy link
Member

carstingaxion commented Sep 20, 2023

Write php unit tests for all code in inc/virtual-uploads/namespace.php

Checklist
  • tests/virtual-uploads/namespaceTest.php ✅ Commit e09b552
• Import the necessary testing framework and the functions from inc/virtual-uploads/namespace.php. • Write a test case for each function in inc/virtual-uploads/namespace.php. Each test case should call the function with a specific set of inputs and check if the output is as expected. • Make sure to cover all possible edge cases in the test cases.
Sandbox Execution Logs
trunk init 1/3 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done





















✔ 9 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.25 (4 github-workflow files)
  checkov 2.4.9 (1 json, 6 yaml files)
  git-diff-check (25 files)
  markdownlint 0.36.0 (2 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.0 (1 lockfile file)
  prettier 3.0.3 (1 json, 2 markdown, 6 yaml files)
  trivy 0.45.1 (1 lockfile, 6 yaml files)
  trufflehog 3.56.1 (25 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt tests/virtual-uploads/namespaceTest.php 2/3 ✓
Found no applicable linters for the requested path
trunk check --fix tests/virtual-uploads/namespaceTest.php 3/3 ✓


Checked 1 file
✔ No issues
• Add a new section for running the unit tests. Include the command to run the tests and any necessary setup instructions.
Sandbox Execution Logs
trunk init 1/3 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done























✔ 9 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.25 (4 github-workflow files)
  checkov 2.4.9 (1 json, 6 yaml files)
  git-diff-check (24 files)
  markdownlint 0.36.0 (2 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.0 (1 lockfile file)
  prettier 3.0.3 (1 json, 2 markdown, 6 yaml files)
  trivy 0.45.1 (1 lockfile, 6 yaml files)
  trufflehog 3.56.1 (24 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt README.md 2/3 ✓

 ✔ Formatted README.md
Re-checking autofixed files...



Checked 1 file
✔ No issues
trunk check --fix README.md 3/3 ✓





  ISSUES  
README.md:2:0
 2:0  low  First line in a file should be a top-level heading  markdownlint/MD041
Checked 1 file
1 existing issue
@sweep-ai
Copy link

sweep-ai bot commented Sep 20, 2023

Here's the PR! #15.

⚡ Sweep Free Trial: I'm creating this ticket using GPT-4. You have 4 GPT-4 tickets left for the month and 2 for the day. For more GPT-4 tickets, visit [our payment portal.](https://buy.stripe.com/6oE5npbGVbhC97afZ4)

Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

<?php
/**
* Figuren_Theater Routes Virtual_Uploads.
*
* @package figuren-theater/ft-routes
*/
namespace Figuren_Theater\Routes\Virtual_Uploads;
use ABSPATH;
use FT_ROOT_DIR;
use function add_action;
use function add_filter;
use function apply_filters;
use function get_current_blog_id;
use function get_sites;
use function get_site_url;
use function got_mod_rewrite;
use function insert_with_markers;
use function is_super_admin;
use function is_wp_error;
use function wp_list_pluck;
use Mercator;
use WP_CONTENT_DIR;
/**
* Name of the virtual uploads folder per domain.
*
* Normally in a WPMU all uploads are saved to
* a folderstructure including the site_ID.
*
* This is not nice and could be a security concern.
* In addition it's not very helpful for SEO
* when all attachments are hosted on a different domain.
*
* So let's give each domain a personell, but virtual folder
* directly in the root of the domain.
*
* This folder is rewritten to WordPress' native folders.
*/
const FOLDER = '__media';
/**
* Bootstrap module, when enabled.
*
* @return void
*/
function bootstrap() :void {
add_action( 'init', __NAMESPACE__ . '\\load', 0 );
}
/**
* (CORE-BUG) Non-WP rewrites not saved on a multisite install
*
* @see https://core.trac.wordpress.org/ticket/19896
* @date 2011 !!!!
*
* Some clarification here though:
*
* add_rewrite_rule(
* sanitize_title( $region ) . '/([0-9]{4})/([0-9]{1,2})/([^/]+)(?:/([0-9]+))?/?$',
* 'index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&page=$matches[4]' ,
* 'top'
* );
*
* works because the index.php? makes it a wp_rewrite
*
* Without it, it's considered a non wp rule and would be written to .htaccess.
* However with multisite, that doesn't/can't happen so this doesn't even
* register as a rewrite rule as it is never written to .htaccess.
*
* add_rewrite_rule(
* sanitize_title( $region ) . '/?$',
* '$matches[1]' ,
* 'top'
* );
*
* add_rewrite_rule('^uploads/([^/]*)?','content/uploads/sites/'.get_current_blog_id().'/$1','top');
*
* @return void
*/
function load() :void {
/*
* filter (visible) URL path from
* assets.figuren.theater/uploads/site/(ID)/2022/03/some-image.jpg
* to a domain-specific folder called
* domain.tld/__media/2022/03/some-image.jpg
*/
add_filter( 'upload_dir', __NAMESPACE__ . '\\filter__upload_dir', 0 );
// Write rewrite-rules to .htaccess,
// on all of the following actions.
$_action_hooks = [
// when Site is created.
'wp_initialize_site',
// when homeurl|siteurl is updated.
'update_option_siteurl',
'update_option_home',
'update_option_rewrite_rules',
// when Domainmapping is CUD.
'mercator.mapping.created',
'mercator.mapping.updated',
'mercator.mapping.deleted',
// MU actions.
'make_spam_blog',
'make_ham_blog',
'archive_blog',
'unarchive_blog',
// when Site is deleted.
'make_delete_blog',
'make_undelete_blog',
];
array_map(
function( string $action ) : void {
add_action( $action, __NAMESPACE__ . '\\update_htaccess', 910 );
},
$_action_hooks
);
}
/**
* '__media' is a ugly hardcoded virtual directory
*
* ... to help with proper rewrite rules for media below
* the prefered domainname of the currently viewed site.
*
* It is used and needs to be updated at the following locations:
* - /.htaccess
* - /content/mu-plugins/FT/ft-routes/inc/virtual-uploads/namespace.php
* - /content/mu-plugins/Figuren_Theater/src/FeaturesRepo/UtilityFeature__managed_core_options.php
*
* @package figuren-theater/ft-routes
*/
/**
* Filters the uploads directory data.
*
* @since 2.10
* @since 3.0 Also set the values for 'basedir' and 'path'.
*
* @param array<mixed> $upload_dir {
* Array of information about the upload directory.
*
* @type string $path Base directory and subdirectory or full path to upload directory.
* @type string $url Base URL and subdirectory or absolute URL to upload directory.
* @type string $subdir Subdirectory if uploads use year/month folders option is on.
* @type string $basedir Path without subdir.
* @type string $baseurl URL path without subdir.
* @type string|false $error False or error message.
* }
*
* @return array<mixed> Updated array of information about the upload directory.
*/
function filter__upload_dir( array $upload_dir ) :array {
// For some unresearched reasons,
// the old 'blogs.dir' 'dropped in' sometimes,
// so remove it.
$upload_dir['basedir'] = WP_CONTENT_DIR . '/uploads/sites/' . get_current_blog_id();
$upload_dir['path'] = $upload_dir['basedir'] . $upload_dir['subdir'];
$old_baseurl = $upload_dir['baseurl'];
$upload_dir['baseurl'] = get_site_url( null, '/' . FOLDER, 'https' );
$upload_dir['url'] = str_replace( $old_baseurl, $upload_dir['baseurl'], $upload_dir['url'] );
return $upload_dir;
}
/**
* Write the site id as a mapping ref for __media
* everytime a new site is created.
*
* CLONED (and modified) from //wp-admin\includes\misc.php#L237
*
* Updates the htaccess file with the current rules if it is writable.
*
* Always writes to the file if it exists and is writable to ensure that we
* blank out old rules.
*
* @since 1.5.0
*
* @return void
*/
function update_htaccess() :void {
if ( ! is_super_admin() ) {
return;
}
// Ensure get_home_path() is declared.
require_once ABSPATH . 'wp-admin/includes/file.php';
$htaccess_file = FT_ROOT_DIR . '/.htaccess';
/*
* Check wether it is needed, allowed and possible
* to update the root .htaccess file.
*/
if ( ! can_update_htaccess( $htaccess_file ) ) {
return;
}
add_filter( 'insert_with_markers_inline_instructions', __NAMESPACE__ . '\\htaccess_instructions', 10, 2 );
insert_with_markers(
$htaccess_file,
__NAMESPACE__,
explode( "\n", generate_htaccess_rules() )
);
}
/**
* Check wether it is needed, allowed and possible
* to update the root .htaccess file.
*
* If the file doesn't already exist check for write access to the directory
* and whether we have some rules. Else check for write access to the file.
*
* @package [package]
* @since 2.11
*
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @param string $htaccess Absolute path to root .htaccess file.
*
* @return bool Allowed to write to .htaccess?
*/
function can_update_htaccess( string $htaccess ) : bool {
global $wp_rewrite;
// Ensure got_mod_rewrite() is declared.
require_once ABSPATH . 'wp-admin/includes/misc.php';
if ( ! got_mod_rewrite() ) {
return false;
}
if ( ! file_exists( $htaccess ) && is_writable( dirname( $htaccess ) ) && $wp_rewrite->using_mod_rewrite_permalinks() ) { // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable
return true;
}
if ( is_writable( $htaccess ) ) { // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable
return true;
}
return false;
}
/**
* Prevent l10n of htaccess dev-instructions via insert_with_markers().
*
* Normally the lines returned by this function come localised from WordPress core,
* which leads to regular but unnneccessary changes of the htaccess file.
*
* This filter prevents this behaviour.
*
* @package [package]
* @since 2.11
*
* @param array<string> $instructions Array of comment lines to add next to our htaccess rules.
* @param string $marker Name of the marker referenced.
*
* @return array<string> Unchanged, but un-localised default text.
*/
function htaccess_instructions( array $instructions, string $marker ) : array {
return [
'#----------------------------------------------------------------------',
'# Handle upload_url redirects with custom URLs',
'# based on __media',
'#',
'# "__media" is a ugly hardcoded virtual directory',
'#',
'# ... to help with proper rewrite rules for media below ',
'# the prefered domainname of the currently viewed site.',
'#',
'# It is used and needs to be updated at the following locations:',
'# - /.htaccess (automatically done)',
'# - /content/mu-plugins/FT/ft-routes/inc/virtual-uploads/namespace.php',
'# - /content/mu-plugins/Figuren_Theater/src/FeaturesRepo/UtilityFeature__managed_core_options.php',
'#',
"# The directives (lines) between 'BEGIN $marker' and 'END $marker' are",
'# dynamically generated, and should only be modified via WordPress filters.',
'# Any changes to the directives between these markers will be overwritten.',
'#----------------------------------------------------------------------',
];
}
/**
* Retrieves mod_rewrite-formatted rewrite rules to write to .htaccess.
*
* Does not actually write to the .htaccess file, but creates the rules for
* the process that will.
*
* Will add the non_wp_rules property rules to the .htaccess file before
* the WordPress rewrite rules one.
*
* @since 1.5.0
*
* @return string
*/
function generate_htaccess_rules() : string {
$args = [
'orderby' => 'path_length',
'no_found_rows' => false,
];
// Get all our sites.
$ft_sites = wp_list_pluck( get_sites( $args ), 'siteurl', 'id' );
$rules = "<IfModule mod_rewrite.c>\n";
$rules .= "RewriteEngine On\n";
$rules .= "RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/\n\n";
// Add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all).
foreach ( $ft_sites as $site_id => $domain ) {
$rules .= generate_domain_rule( $site_id, $domain );
}
/**
* NOT WORKING # all requests, that are not '/__media/'
* RewriteCond %{REQUEST_URI} !^/__media/$ [NC]
*
* WORKING # all requests, that do not only be '/__media/',
* without following folders and file.
*/
$rules .= 'RewriteCond %{REQUEST_URI} !/(' . FOLDER . ")/$ [NC]\n";
$rules .= 'RewriteCond %{REQUEST_URI} /' . FOLDER . "/(.*)$ [NC]\n";
$rules .= 'RewriteRule ' . FOLDER . "/(.*)$ content/uploads/sites/%{ENV:FT_SITE_ID}/$1 [L]\n";
$rules .= '</IfModule>';
/**
* Filters the list of rewrite rules formatted for output to an .htaccess file.
*
* @since 1.5.0
*
* @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
*/
return apply_filters( __NAMESPACE__ . '\\generate_htaccess_rules', $rules );
}
/**
* Generates a domain rule for Apache mod_rewrite based on the site ID and domain.
*
* This function generates a domain rule for Apache mod_rewrite based on the provided site ID
* and domain. The domain rule is constructed by retrieving mappings for the site ID and appending
* them to the rule string. The resulting domain rule is returned as a string.
*
* @param int $site_id The ID of the site.
* @param string $domain The domain for which the rule is generated.
* @return string The generated domain rule.
*/
function generate_domain_rule( int $site_id, string $domain ) : string {
$mappings = Mercator\Mapping::get_by_site( $site_id );
$rules = '';
// Check if there are mappings for the site.
if ( ! empty( $mappings ) && ! is_wp_error( $mappings ) ) {
foreach ( $mappings as $mapping ) {
// Append each mapping domain as a RewriteCond rule to the rules string.
$rules .= 'RewriteCond %{HTTP_HOST} ^' . _mask( $mapping->get_domain() ) . "\.(.*)$ [NC,OR]\n";
}
}
// Append the domain itself as a RewriteCond rule to the rules string.
$rules .= 'RewriteCond %{HTTP_HOST} ^' . _mask( $domain ) . "\.(.*)$ [NC]\n";
// Check if the domain represents a subdirectory installation.
$maybepath = _is_subdir_install( $domain );
if ( $maybepath ) {
// Append the subdirectory path as a RewriteCond rule to the rules string.
$rules .= 'RewriteCond %{REQUEST_URI} ^' . $maybepath . "/(.*)$ [NC]\n";
}
// Append the site ID as an environment variable to the rules string.
$rules .= 'RewriteRule . - [E=FT_SITE_ID:' . $site_id . "]\n\n";
return $rules;
}
/**
* Masks the given URL by replacing the scheme and removing the top-level domain.
*
* This function takes a URL as input and masks it by removing the scheme ('https://' or 'http://')
* and the top-level domain. The resulting masked URL is returned as a string with dots replaced by '\.'.
*
* @param string $url The URL to be masked.
*
* @return string The masked URL.
*/
function _mask( string $url ) : string {
// Convert URL to an array by splitting it at each dot.
$_url = explode( '.', $url );
// Clean up the first array entry, removing the scheme ('https://' or 'http://').
$_url = str_replace( [ 'https://', 'http://' ], '', $_url );
// Remove the last part from the URL array, which represents the top-level domain.
array_pop( $_url );
// Join the URL array back together with masked dots ('\.').
return join( '\.', $_url );
}
/**
* Checks if the given URL represents a subdirectory installation.
*
* This function examines the URL and determines if it represents a subdirectory installation
* based on the presence of a forward slash (/) in the last part of the URL. If a subdirectory
* is detected, the function returns the subdirectory path, otherwise it returns false.
*
* @param string $url The URL to be checked.
*
* @return string|bool The subdirectory path if it exists, otherwise false.
*/
function _is_subdir_install( string $url ) : string|bool {
// Convert URL to an array by splitting it at each dot.
$_url = explode( '.', $url );
// Remove the last part from the URL array, which represents the top-level domain, e.g. '.test|.theater|.whatever'.
$last_part = array_pop( $_url );
// Check if the last part of the URL contains a forward slash (/).
$path = strpos( $last_part, '/' );
if ( $path ) {
// If a subdirectory is found, return the subdirectory path.
return substr( $last_part, $path );
}
// If no subdirectory is found, return false.
return false;
}

ft-routes/plugin.php

Lines 1 to 18 in 26ab97c

<?php
/**
* Plugin Name: figuren.theater | Routes
* Plugin URI: https://github.com/figuren-theater/ft-routes
* Description: Modern tales of browser headers, domains, mappings and its pathes. Including some (still needed) historic patches for a nice WordPress Multisite setup like figuren.theater.
* Author: figuren.theater
* Author URI: https://figuren.theater
* Text Domain: figurentheater
* Domain Path: /languages
* Version: 1.1.3
*
* @package figuren-theater/ft-routes
*/
namespace Figuren_Theater\Routes;
const DIRECTORY = __DIR__;

<?php
/**
* Figuren_Theater Routes Disable_Public_JSON_REST_API.
*
* @package figuren-theater/ft-routes
*/
namespace Figuren_Theater\Routes\Disable_Public_JSON_REST_API;
use function add_action;
use function add_filter;
use function is_user_logged_in;
use function remove_action;
/**
* Bootstrap module, when enabled.
*
* @return void
*/
function bootstrap() :void {
add_action( 'init', __NAMESPACE__ . '\\load', 0 );
}
/**
* Load the modifications to the REST API.
*
* @return void
*/
function load() :void {
// Disable some endpoints for unauthenticated users.
add_filter( 'rest_endpoints', __NAMESPACE__ . '\\disable_default_endpoints', 1000 );
/*
* Remove REST API info from head and HTTP-headers
* taken from
* https://gist.github.com/timwhitlock/ef62645c41ca61718fb2be7adcb641c6
* https://github.com/dmchale/disable-json-api/blob/master/disable-json-api.php
*
* nice explanation
* und furter infos
* https://wordpress.stackexchange.com/questions/211467/remove-json-api-links-in-header-html
*
* also remove actions added by wp-includes/default-filters.php
*/
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
// Disables oembed, which needs the REST API.
remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
}
/*
* Directly from the 'REST API Handbook'
* https://developer.wordpress.org/rest-api/frequently-asked-questions/#require-authentication-for-all-requests
*
* and originated in this interesting (!) thread
* https://stackoverflow.com/questions/41191655/safely-disable-wp-rest-api
*
* Can I disable the REST API?
*
* You should not disable the REST API;
* doing so will break WordPress Admin functionality
* that depends on the API being active.
* However, you may use a filter to require that
* API consumers be authenticated,
* which effectively prevents anonymous external access.
* See below for more information.
*
* Require Authentication for All Requests
*
* You can require authentication for all REST API requests
* by adding an is_user_logged_in check to
* the rest_authentication_errors filter.
*
* ```
* add_filter( 'rest_authentication_errors', function( $result ) {
* // If a previous authentication check was applied,
* // pass that result along without modification.
* if ( true === $result || is_wp_error( $result ) ) {
* return $result;
* }
*
* // No authentication has been performed yet.
* // Return an error if user is not logged in.
* if ( ! is_user_logged_in() ) {
* return new WP_Error(
* 'rest_not_logged_in',
* __( 'You are not currently logged in.' ),
* array( 'status' => 401 )
* );
* }
*
* // Our custom authentication check should have no effect
* // on logged-in requests
* return $result;
* });
* ```
*/
/**
* Filters the array of available REST API endpoints.
*
* AGAIN inspired by the great stackoverflow-post
* change the filter to make it a little less forcing
*
* Disable some endpoints for unauthenticated users.
*
* @param array<string, mixed> $endpoints The available endpoints. An array of matching regex patterns, each mapped to an array of callbacks for the endpoint. These take the format or `'/path/regex' => array( array( $callback, $bitmask ).
*
* @return array<string, mixed> $endpoints
*/
function disable_default_endpoints( array $endpoints ) :array {
if ( is_user_logged_in() ) {
return $endpoints;
}
$endpoints_to_remove = [
'/wp-site-health/v1',
/**
* Disable oembeds of f.t-domains for privacy reasons

ft-routes/README.md

Lines 1 to 114 in 26ab97c

<!-- PROJECT LOGO -->
<br />
<div align="center">
<a href="https://github.com/figuren-theater/ft-routes">
<img src="https://raw.githubusercontent.com/figuren-theater/logos/main/favicon.png" alt="figuren.theater Logo" width="100" height="100">
</a>
<h1 align="center">figuren.theater | Routes</h1>
<p align="center">
Modern tales of browser headers, domains, mappings and its pathes. Including some (still needed) historic patches for a nice WordPress Multisite setup like <a href="https://figuren.theater">figuren.theater</a>.
<br /><br /><br />
<a href="https://meta.figuren.theater/blog"><strong>Read our blog</strong></a>
<br />
<br />
<a href="https://figuren.theater">See the network in action</a>
<a href="https://mein.figuren.theater">Join the network</a>
<a href="https://websites.fuer.figuren.theater">Create your own network</a>
</p>
</div>
## About
This is the long desc
* [x] *list closed tracking-issues or `docs` files here*
* [ ] Do you have any [ideas](https://github.com/figuren-theater/ft-routes/issues/new) ?
## Background & Motivation
...
## Install
1. Install via command line
```sh
composer require figuren-theater/ft-routes
```
## Usage
### API
```php
Figuren_Theater::API\get_...()
```
## Plugins included
This package contains the following plugins.
Thoose are completely managed by code and lack of their typical UI.
* [Mercator](https://github.com/humanmade/Mercator/)
WordPress multisite domain mapping for the modern era.
* ~~[Mercator GUI](https://github.com/humanmade/Mercator-GUI)~~ [Mercator-GUI](https://github.com/carstingaxion/Mercator-GUI)
A GUI component for Mercator domain mapping
## What does this package do in addition?
Accompaniying the core functionality of the mentioned plugins, theese **best practices** are included with this package.
- [X] Set base rewrites to german slugs for search, authors and pagination.
- [X] Include `/wp` as base directory in `network_url()` calls.
- [X] Use a virtual `/__media` folder per Domain, which rewrites internally to `content/uploads/sites/SITES_ID`.
- [X] Use aliased domains in `<meta rel="canonical" />` tags, generated by WordPress (by default) or even when outputted by *Yoasts WordPress SEO* Plugin
- [X] Disable most of the public JSON REST API.
## Built with & uses
- [dependabot](/.github/dependabot.yml)
- [code-quality](https://github.com/figuren-theater/code-quality/)
A set of status checks to ensure high and consitent code-quality for the figuren.theater platform.
- ....
## Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## Versioning
We use [Semantic Versioning](http://semver.org/). For the versions
available, see the [tags on this repository](https://github.com/figuren-theater/ft-routes/tags).
## Authors
- **Carsten Bach** - *Provided idea & code* - [figuren.theater/crew](https://figuren.theater/crew/)
See also the list of [contributors](https://github.com/figuren-theater/ft-routes/contributors)
who participated in this project.
## License
This project is licensed under the **GPL-3.0-or-later**, see the [LICENSE](/LICENSE) file for
details
## Acknowledgments
- [altis](https://github.com/search?q=org%3Ahumanmade+altis) by humanmade, as our digital role model and inspiration
- [@roborourke](https://github.com/roborourke) for his clear & understandable [coding guidelines](https://docs.altis-dxp.com/guides/code-review/standards/)
- [python-project-template](https://github.com/rochacbruno/python-project-template) for their nice template->repo renaming workflow

ft-routes/composer.json

Lines 1 to 82 in 26ab97c

{
"name": "figuren-theater/ft-routes",
"description": "Modern tales of browser headers, domains, mappings and its pathes. Including some (still needed) historic patches for a nice WordPress Multisite setup like figuren.theater.",
"license": "GPL-3.0-or-later",
"type": "wordpress-muplugin",
"keywords": [
"wordpress",
"routing",
"domain-aliasing",
"rewriting"
],
"authors": [
{
"name": "figuren.theater",
"email": "info@figuren.theater"
},
{
"name": "Carsten Bach",
"email": "mail@carsten-bach.de",
"homepage": "https://carsten-bach.de",
"role": "Developer"
}
],
"homepage": "https://websites.fuer.figuren.theater",
"support": {
"email": "info@figuren.theater",
"issues": "https://github.com/figuren-theater/ft-routes/issues",
"source": "https://github.com/figuren-theater/ft-routes"
},
"require": {
"php": ">=7.1",
"humanmade/mercator": "dev-master",
"humanmade/mercator-gui": "dev-master",
"koodimonni/composer-dropin-installer": "^1.4"
},
"require-dev": {
"figuren-theater/code-quality": "*"
},
"suggest": {
"wpackagist-plugin/cache-enabler": "Allow the cache-deletion of (Mercator) aliased domains."
},
"repositories": [
{
"type": "git",
"url": "https://github.com/carstingaxion/Mercator-GUI"
}
],
"autoload": {
"classmap": [
"inc/"
],
"files": [
"inc/disable-public-json-rest-api/namespace.php",
"inc/mercator/namespace.php",
"inc/network_site_url-fix/namespace.php",
"inc/noblogredirect-fix/namespace.php",
"inc/virtual-uploads/namespace.php",
"inc/namespace.php"
]
},
"config": {
"allow-plugins": {
"composer/installers": true,
"koodimonni/composer-dropin-installer": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
}
},
"extra": {
"altis": {
"install-overrides": [
"humanmade/mercator",
"humanmade/mercator-gui"
]
},
"dropin-paths": {
"content/": [
"package:figuren-theater/ft-routes:templates/htdocs/wp-content/sunrise.php"
]
}
}


Step 2: ⌨️ Coding

  • tests/virtual-uploads/namespaceTest.php ✅ Commit e09b552
• Import the necessary testing framework and the functions from inc/virtual-uploads/namespace.php. • Write a test case for each function in inc/virtual-uploads/namespace.php. Each test case should call the function with a specific set of inputs and check if the output is as expected. • Make sure to cover all possible edge cases in the test cases.
Sandbox Execution Logs
trunk init 1/3 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done





















✔ 9 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.25 (4 github-workflow files)
  checkov 2.4.9 (1 json, 6 yaml files)
  git-diff-check (25 files)
  markdownlint 0.36.0 (2 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.0 (1 lockfile file)
  prettier 3.0.3 (1 json, 2 markdown, 6 yaml files)
  trivy 0.45.1 (1 lockfile, 6 yaml files)
  trufflehog 3.56.1 (25 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt tests/virtual-uploads/namespaceTest.php 2/3 ✓
Found no applicable linters for the requested path
trunk check --fix tests/virtual-uploads/namespaceTest.php 3/3 ✓


Checked 1 file
✔ No issues
• Add a new section for running the unit tests. Include the command to run the tests and any necessary setup instructions.
Sandbox Execution Logs
trunk init 1/3 ✓
⡿ Downloading Trunk 1.16.0...
⡿ Downloading Trunk 1.16.0...
⢿ Downloading Trunk 1.16.0...
⣻ Downloading Trunk 1.16.0...
⣽ Downloading Trunk 1.16.0...
⣾ Downloading Trunk 1.16.0...
⣷ Downloading Trunk 1.16.0...
✔ Downloading Trunk 1.16.0... done
⡿ Verifying Trunk sha256...
✔ Verifying Trunk sha256... done
⡿ Unpacking Trunk...
✔ Unpacking Trunk... done























✔ 9 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.25 (4 github-workflow files)
  checkov 2.4.9 (1 json, 6 yaml files)
  git-diff-check (24 files)
  markdownlint 0.36.0 (2 markdown files) (created .markdownlint.yaml)
  osv-scanner 1.4.0 (1 lockfile file)
  prettier 3.0.3 (1 json, 2 markdown, 6 yaml files)
  trivy 0.45.1 (1 lockfile, 6 yaml files)
  trufflehog 3.56.1 (24 files)
  yamllint 1.32.0 (6 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt README.md 2/3 ✓

 ✔ Formatted README.md
Re-checking autofixed files...



Checked 1 file
✔ No issues
trunk check --fix README.md 3/3 ✓





  ISSUES  
README.md:2:0
 2:0  low  First line in a file should be a top-level heading  markdownlint/MD041
Checked 1 file
1 existing issue

Step 3: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-unit-tests.

Here is the 1st review

Thanks for your effort in adding unit tests and updating the README. However, there are a few changes that need to be made:
  • In the namespaceTest.php file, the test cases are incomplete. For each test function, you need to provide specific inputs and expected outputs for the function being tested. Also, you need to add assertions to check if the output of the function matches the expected output. Please refer to the PHPUnit documentation for examples on how to do this.

  • In the README.md file, please specify that the tests are located in the tests directory when giving instructions on how to run the tests.

Keep up the good work!

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.
Join Our Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants