Files
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

144 lines
4.4 KiB
PHP

<?php
use Jio\Core\DomainModel;
use Jio\Core\FrontSubmitPay;
use PHPUnit\Framework\TestCase;
require_once dirname(__DIR__, 2) . '/src/Core/DomainModel.php';
require_once dirname(__DIR__, 2) . '/src/Core/FrontSubmitPay.php';
if (!function_exists('update_post_meta')) {
function update_post_meta(int $post_id, string $key, $value): void {
$GLOBALS['jio_test_post_meta'][$post_id][$key] = $value;
}
}
final class FrontSubmitPayHarness {
use FrontSubmitPay;
public function user_can_cap(string $cap, int $user_id = 0, ?int $context = null): bool {
return true;
}
public function save(int $post_id, array $data, array $settings): array {
return $this->save_pay_meta($post_id, $data, 7, $settings);
}
}
final class FrontSubmitPayTest extends TestCase {
private FrontSubmitPayHarness $submit;
protected function setUp(): void {
$GLOBALS['jio_test_post_meta'] = [];
$this->submit = new FrontSubmitPayHarness();
}
public function test_manual_cash_price_only_requires_enabled_vip_level(): void {
$result = $this->submit->save(101, [
'pay_enabled' => '1',
'jio_pay' => [
'price' => '10.00',
'vip1_price' => '8.00',
],
], $this->settings(true, false));
self::assertTrue($result['success']);
$meta = $GLOBALS['jio_test_post_meta'][101][DomainModel::PAY_META_KEY];
self::assertSame('8.00', $meta['vip1_price']);
self::assertSame('0.00', $meta['vip2_price']);
}
public function test_manual_points_price_only_requires_enabled_vip_level(): void {
$result = $this->submit->save(102, [
'pay_enabled' => '1',
'jio_pay' => [
'pay_modo' => 'points',
'points_price' => '100',
'vip2_points' => '50',
],
], $this->settings(false, true));
self::assertTrue($result['success']);
$meta = $GLOBALS['jio_test_post_meta'][102][DomainModel::PAY_META_KEY];
self::assertSame(0, $meta['vip1_points']);
self::assertSame(50, $meta['vip2_points']);
}
public function test_manual_price_rejects_missing_enabled_vip_level(): void {
$result = $this->submit->save(103, [
'pay_enabled' => '1',
'jio_pay' => ['price' => '10.00'],
], $this->settings(true, false));
self::assertFalse($result['success']);
self::assertSame('请设置正确的会员价格', $result['message']);
}
public function test_manual_price_does_not_require_disabled_vip_levels(): void {
$result = $this->submit->save(104, [
'pay_enabled' => '1',
'jio_pay' => ['price' => '10.00'],
], $this->settings(false, false));
self::assertTrue($result['success']);
$meta = $GLOBALS['jio_test_post_meta'][104][DomainModel::PAY_META_KEY];
self::assertSame('0.00', $meta['vip1_price']);
self::assertSame('0.00', $meta['vip2_price']);
}
public function test_download_resource_modal_fields_are_sanitized_as_one_payload(): void {
$downloads = DomainModel::sanitize_downloads([
[
'url' => 'https://example.com/file.zip',
'label' => '<b>镜像下载</b>',
'extract_code' => ' 提取码:1234 ',
'copy_key' => '<i>提取码</i>',
'copy_val' => ' 1234 ',
'class' => 'jb-blue',
],
]);
self::assertCount(1, $downloads);
self::assertSame('镜像下载', $downloads[0]['label']);
self::assertSame('提取码:1234', $downloads[0]['extract_code']);
self::assertSame('提取码', $downloads[0]['copy_key']);
self::assertSame('1234', $downloads[0]['copy_val']);
self::assertSame('jb-blue', $downloads[0]['class']);
}
public function test_submit_saves_download_url_without_attachment_ownership_filter(): void {
$url = 'https://localhost/wp-content/uploads/2026/08/resource.zip';
$result = $this->submit->save(105, [
'pay_enabled' => '1',
'jio_pay' => [
'price' => '10.00',
'downloads' => [
[
'url' => $url,
'label' => '本地资源',
],
],
],
], $this->settings(false, false));
self::assertTrue($result['success']);
$meta = $GLOBALS['jio_test_post_meta'][105][DomainModel::PAY_META_KEY];
self::assertSame(DomainModel::PAY_TYPE_DOWNLOAD, $meta['pay_type']);
self::assertCount(1, $meta['downloads']);
self::assertSame($url, $meta['downloads'][0]['url']);
}
private function settings(bool $vip1_enabled, bool $vip2_enabled): array {
return [
'pay_free_s' => true,
'pay_price_min' => '0.00',
'pay_price_max' => '100.00',
'pay_vip_price_s' => true,
'pay_vip_1_enabled' => $vip1_enabled,
'pay_vip_2_enabled' => $vip2_enabled,
'pay_vip_1_discount' => 80,
'pay_vip_2_discount' => 50,
];
}
}