✨feature: Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Logo sanitizer tests.
|
||||
*
|
||||
* @package LogoSoup\Tests
|
||||
*/
|
||||
|
||||
use LogoSoup\Support\Logo_Sanitizer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests collection sanitization.
|
||||
*/
|
||||
class LogoSanitizerTest extends TestCase {
|
||||
/**
|
||||
* Test invalid rows are removed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_sanitize_collection_skips_invalid_entries() {
|
||||
$sanitized = Logo_Sanitizer::sanitize_collection(
|
||||
array(
|
||||
array(
|
||||
'id' => '4',
|
||||
'url' => 'https://example.com/logo.svg',
|
||||
'alt' => '<b>Alpha</b>',
|
||||
'link' => 'https://example.com',
|
||||
),
|
||||
array(
|
||||
'alt' => 'Missing URL',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertCount( 1, $sanitized );
|
||||
$this->assertSame( 'Alpha', $sanitized[0]['alt'] );
|
||||
$this->assertSame( 4, $sanitized[0]['id'] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Settings tests.
|
||||
*
|
||||
* @package LogoSoup\Tests
|
||||
*/
|
||||
|
||||
use LogoSoup\Settings;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests settings sanitization.
|
||||
*/
|
||||
class SettingsTest extends TestCase {
|
||||
/**
|
||||
* Test invalid layout falls back to default.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_sanitize_rejects_unknown_layout() {
|
||||
$sanitized = Settings::sanitize(
|
||||
array(
|
||||
'default_layout' => 'not-real',
|
||||
'default_speed' => 300,
|
||||
'default_gray' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 'carousel', $sanitized['default_layout'] );
|
||||
$this->assertSame( 80, $sanitized['default_speed'] );
|
||||
$this->assertTrue( $sanitized['default_gray'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test advanced normalization options are sanitized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_sanitize_normalization_options() {
|
||||
$sanitized = Settings::sanitize(
|
||||
array(
|
||||
'base_size' => 400,
|
||||
'scale_factor' => '1.37',
|
||||
'density_aware' => 1,
|
||||
'density_factor' => '4.2',
|
||||
'crop_to_content' => 1,
|
||||
'align_by' => 'visual-center-y',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 160, $sanitized['base_size'] );
|
||||
$this->assertSame( 1.37, $sanitized['scale_factor'] );
|
||||
$this->assertTrue( $sanitized['density_aware'] );
|
||||
$this->assertSame( 1.0, $sanitized['density_factor'] );
|
||||
$this->assertTrue( $sanitized['crop_to_content'] );
|
||||
$this->assertSame( 'visual-center-y', $sanitized['align_by'] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap.
|
||||
*
|
||||
* @package LogoSoup\Tests
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'sanitize_key' ) ) {
|
||||
/**
|
||||
* Sanitize key.
|
||||
*
|
||||
* @param string $key Raw key.
|
||||
* @return string
|
||||
*/
|
||||
function sanitize_key( $key ) {
|
||||
$key = strtolower( (string) $key );
|
||||
|
||||
return preg_replace( '/[^a-z0-9_\-]/', '', $key );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sanitize_text_field' ) ) {
|
||||
/**
|
||||
* Sanitize text.
|
||||
*
|
||||
* @param string $value Raw value.
|
||||
* @return string
|
||||
*/
|
||||
function sanitize_text_field( $value ) {
|
||||
return trim( wp_strip_all_tags( (string) $value ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'absint' ) ) {
|
||||
/**
|
||||
* Convert to absolute integer.
|
||||
*
|
||||
* @param mixed $maybeint Value.
|
||||
* @return int
|
||||
*/
|
||||
function absint( $maybeint ) {
|
||||
return abs( (int) $maybeint );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_url_raw' ) ) {
|
||||
/**
|
||||
* Sanitize raw URL.
|
||||
*
|
||||
* @param string $url URL.
|
||||
* @return string
|
||||
*/
|
||||
function esc_url_raw( $url ) {
|
||||
return filter_var( (string) $url, FILTER_SANITIZE_URL );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_parse_args' ) ) {
|
||||
/**
|
||||
* Parse args against defaults.
|
||||
*
|
||||
* @param array $args Args.
|
||||
* @param array $defaults Defaults.
|
||||
* @return array
|
||||
*/
|
||||
function wp_parse_args( $args, $defaults = array() ) {
|
||||
return array_merge( $defaults, $args );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_strip_all_tags' ) ) {
|
||||
/**
|
||||
* Strip all tags.
|
||||
*
|
||||
* @param string $value Raw text.
|
||||
* @return string
|
||||
*/
|
||||
function wp_strip_all_tags( $value ) {
|
||||
return trim( preg_replace( '/<[^>]*>/', '', (string) $value ) );
|
||||
}
|
||||
}
|
||||
|
||||
require_once dirname( __DIR__, 2 ) . '/tests/php/wp-stubs.php';
|
||||
require_once dirname( __DIR__, 2 ) . '/src/class-settings.php';
|
||||
require_once dirname( __DIR__, 2 ) . '/src/Support/class-logo-sanitizer.php';
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress stubs for static analysis and local tests.
|
||||
*
|
||||
* @package LogoSoup\Tests
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_Error' ) ) {
|
||||
class WP_Error {
|
||||
public function __construct( $code = '', $message = '', $data = array() ) {}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_REST_Request' ) ) {
|
||||
class WP_REST_Request {
|
||||
public function get_method() {
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
public function get_header( $name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_json_params() {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_REST_Response' ) ) {
|
||||
class WP_REST_Response {
|
||||
public function __construct( $data = null, $status = 200 ) {}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_REST_Server' ) ) {
|
||||
class WP_REST_Server {
|
||||
const READABLE = 'GET';
|
||||
const EDITABLE = 'POST';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( '__' ) ) {
|
||||
function __( $text, $domain = 'default' ) {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_html__' ) ) {
|
||||
function esc_html__( $text, $domain = 'default' ) {
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_attr' ) ) {
|
||||
function esc_attr( $text ) {
|
||||
return (string) $text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_html' ) ) {
|
||||
function esc_html( $text ) {
|
||||
return (string) $text;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'esc_url' ) ) {
|
||||
function esc_url( $url ) {
|
||||
return (string) $url;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'selected' ) ) {
|
||||
function selected( $value, $current ) {
|
||||
return $value === $current ? 'selected="selected"' : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'checked' ) ) {
|
||||
function checked( $is_checked ) {
|
||||
return $is_checked ? 'checked="checked"' : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'plugins_url' ) ) {
|
||||
function plugins_url( $path = '', $plugin = '' ) {
|
||||
return (string) $path;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'load_plugin_textdomain' ) ) {
|
||||
function load_plugin_textdomain( $domain = 'default', $deprecated = false, $plugin_rel_path = '' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'register_activation_hook' ) ) {
|
||||
function register_activation_hook( $file, $callback ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'register_deactivation_hook' ) ) {
|
||||
function register_deactivation_hook( $file, $callback ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_action' ) ) {
|
||||
function add_action( $hook, $callback ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'register_setting' ) ) {
|
||||
function register_setting( $group, $name, $args = array() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_options_page' ) ) {
|
||||
function add_options_page( $page_title = '', $menu_title = '', $capability = '', $menu_slug = '', $callback = null ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_settings_section' ) ) {
|
||||
function add_settings_section( $id = '', $title = '', $callback = null, $page = '' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_settings_field' ) ) {
|
||||
function add_settings_field( $id = '', $title = '', $callback = null, $page = '', $section = '' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'current_user_can' ) ) {
|
||||
function current_user_can( $capability = '' ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'settings_fields' ) ) {
|
||||
function settings_fields( $group ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'do_settings_sections' ) ) {
|
||||
function do_settings_sections( $page ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'submit_button' ) ) {
|
||||
function submit_button() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'register_rest_route' ) ) {
|
||||
function register_rest_route( $route_namespace, $route, $args ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_verify_nonce' ) ) {
|
||||
function wp_verify_nonce( $nonce, $action ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'register_block_type' ) ) {
|
||||
function register_block_type( $path, $args = array() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'get_option' ) ) {
|
||||
function get_option( $name, $fallback = false ) {
|
||||
return $fallback;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'add_option' ) ) {
|
||||
function add_option( $name, $value ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'update_option' ) ) {
|
||||
function update_option( $name, $value ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'delete_option' ) ) {
|
||||
function delete_option( $name ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wp_clear_scheduled_hook' ) ) {
|
||||
function wp_clear_scheduled_hook( $hook ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user