43815dea2d
tests / phpunit (push) Has been cancelled
- PluginBootS7Test idempotency: assertTrue(class_exists) instead of assertTrue(true) - ZipArchiveBuildTest: try/finally cleanup + unzip exit-code check - bootstrap.php: drop unused PUC shims (wp_remote_post, transient*) - CHANGELOG.md: header references Keep a Changelog (was: mirrors readme.txt) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase;
|
|
|
|
final class ZipArchiveBuildTest extends BaseTestCase
|
|
{
|
|
private const PLUGIN_ROOT = __DIR__ . '/..';
|
|
private const ARCHIVE_PREFIX = 'wp-multi-city/';
|
|
|
|
public function test_git_archive_includes_runtime_files_excludes_dev_files(): void
|
|
{
|
|
$tmp = tempnam(sys_get_temp_dir(), 'wpmc-zip-');
|
|
unlink($tmp);
|
|
$zipPath = $tmp . '.zip';
|
|
|
|
$cmd = sprintf(
|
|
'cd %s && git archive HEAD --worktree-attributes --format=zip --prefix=%s -o %s 2>&1',
|
|
escapeshellarg(self::PLUGIN_ROOT),
|
|
escapeshellarg(self::ARCHIVE_PREFIX),
|
|
escapeshellarg($zipPath)
|
|
);
|
|
exec($cmd, $out, $rc);
|
|
self::assertSame(0, $rc, 'git archive failed: ' . implode("\n", $out));
|
|
|
|
try {
|
|
$listing = [];
|
|
$unzipRc = 0;
|
|
exec('unzip -l ' . escapeshellarg($zipPath), $listing, $unzipRc);
|
|
self::assertSame(0, $unzipRc, 'unzip -l failed (is unzip installed?)');
|
|
$joined = implode("\n", $listing);
|
|
|
|
$required = [
|
|
'wp-multi-city/wp-multi-city.php',
|
|
'wp-multi-city/includes/lib/plugin-update-checker/plugin-update-checker.php',
|
|
'wp-multi-city/wp-plugin-info.json',
|
|
'wp-multi-city/readme.txt',
|
|
'wp-multi-city/README.md',
|
|
];
|
|
foreach ($required as $path) {
|
|
self::assertStringContainsString($path, $joined, "missing in archive: {$path}");
|
|
}
|
|
|
|
$forbidden = [
|
|
'tests/',
|
|
'docs/',
|
|
'composer.json',
|
|
'phpunit.xml.dist',
|
|
'patchwork.json',
|
|
'release.sh',
|
|
'CLAUDE.md',
|
|
'.gitattributes',
|
|
'.gitea/',
|
|
];
|
|
foreach ($forbidden as $path) {
|
|
self::assertStringNotContainsString(
|
|
'wp-multi-city/' . $path,
|
|
$joined,
|
|
"dev file leaked into archive: {$path}"
|
|
);
|
|
}
|
|
} finally {
|
|
if (file_exists($zipPath)) {
|
|
unlink($zipPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_wp_plugin_info_json_is_valid(): void
|
|
{
|
|
$path = self::PLUGIN_ROOT . '/wp-plugin-info.json';
|
|
self::assertFileExists($path);
|
|
|
|
$json = file_get_contents($path);
|
|
self::assertIsString($json);
|
|
|
|
$data = json_decode($json, true);
|
|
self::assertIsArray($data, 'wp-plugin-info.json must be valid JSON');
|
|
self::assertSame('wp-multi-city', $data['slug']);
|
|
self::assertArrayHasKey('version', $data);
|
|
self::assertArrayHasKey('download_url', $data);
|
|
self::assertStringContainsString(
|
|
'git.netranking.ru/bryzgalov/wp-multi-city',
|
|
$data['download_url']
|
|
);
|
|
}
|
|
}
|