Files
wp-multi-city/tests/ZipArchiveBuildTest.php
T
2026-05-17 12:23:01 +05:00

83 lines
2.6 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));
exec('unzip -l ' . escapeshellarg($zipPath), $listing);
$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}"
);
}
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']
);
}
}