188 lines
6.1 KiB
PHP
188 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Deployment;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Tests\TestCase;
|
|
|
|
class LocalStaticAssetsTest extends TestCase
|
|
{
|
|
public function test_local_image_builds_and_checks_required_static_assets(): void
|
|
{
|
|
$dockerfile = file_get_contents(base_path('deploy/Dockerfile.local'));
|
|
$healthcheck = file_get_contents(base_path('deploy/local-healthcheck.sh'));
|
|
|
|
$this->assertIsString($dockerfile);
|
|
$this->assertStringContainsString(
|
|
'com.caiwu.local-build-fingerprint="$LOCAL_BUILD_FINGERPRINT"',
|
|
$dockerfile
|
|
);
|
|
$this->assertStringContainsString(
|
|
'node_modules/apexcharts/dist/apexcharts.min.js',
|
|
$dockerfile
|
|
);
|
|
$this->assertStringContainsString(
|
|
'node_modules/js-cookie/dist/js.cookie.min.js',
|
|
$dockerfile
|
|
);
|
|
|
|
$this->assertIsString($healthcheck);
|
|
foreach ([
|
|
'public/js/manifest.js',
|
|
'public/js/vendor.js',
|
|
'public/css/app.css',
|
|
'public/mix-manifest.json',
|
|
'public/vendor/apexcharts/apexcharts.min.js',
|
|
'public/vendor/js-cookie/js.cookie.js',
|
|
] as $requiredAsset) {
|
|
$this->assertStringContainsString($requiredAsset, $healthcheck);
|
|
}
|
|
$this->assertStringContainsString(
|
|
'runuser -u www-data -- php artisan app:ready --quiet',
|
|
$healthcheck
|
|
);
|
|
$this->assertStringContainsString(
|
|
'http://127.0.0.1:18088/auth/login',
|
|
$healthcheck
|
|
);
|
|
}
|
|
|
|
public function test_local_initializer_rebuilds_stale_or_incomplete_images(): void
|
|
{
|
|
$initializer = file_get_contents(base_path('deploy/local-init.sh'));
|
|
|
|
$this->assertIsString($initializer);
|
|
$this->assertStringContainsString(
|
|
'calculate_local_image_fingerprint',
|
|
$initializer
|
|
);
|
|
$this->assertStringContainsString(
|
|
'image_has_required_assets',
|
|
$initializer
|
|
);
|
|
$this->assertStringContainsString(
|
|
'现有镜像缺少必要静态资源',
|
|
$initializer
|
|
);
|
|
$this->assertStringContainsString(
|
|
'--build-arg "LOCAL_BUILD_FINGERPRINT=$local_image_fingerprint"',
|
|
$initializer
|
|
);
|
|
$this->assertStringContainsString(
|
|
'构建期间检测到源码变化,自动按最新源码再构建一次',
|
|
$initializer
|
|
);
|
|
$this->assertStringContainsString(
|
|
'本地镜像缺少必要静态资源,请查看上方构建日志',
|
|
$initializer
|
|
);
|
|
}
|
|
|
|
public function test_missing_static_files_are_not_routed_through_laravel(): void
|
|
{
|
|
$apache = file_get_contents(base_path('deploy/apache-vhost.conf'));
|
|
|
|
$this->assertIsString($apache);
|
|
$this->assertStringContainsString(
|
|
'RewriteCond %{REQUEST_URI} ^/(public/|vendor/livewire/)',
|
|
$apache
|
|
);
|
|
$this->assertStringContainsString(
|
|
'RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f',
|
|
$apache
|
|
);
|
|
$this->assertStringContainsString(
|
|
'RewriteRule ^ - [R=404,L]',
|
|
$apache
|
|
);
|
|
}
|
|
|
|
public function test_apexcharts_is_loaded_only_by_chart_views(): void
|
|
{
|
|
foreach ([
|
|
'admin',
|
|
'portal',
|
|
'print',
|
|
] as $layout) {
|
|
$scripts = file_get_contents(
|
|
resource_path("views/components/layouts/{$layout}/scripts.blade.php")
|
|
);
|
|
|
|
$this->assertIsString($scripts);
|
|
$this->assertStringContainsString("@stack('chart_libraries')", $scripts);
|
|
$this->assertStringNotContainsString(
|
|
"asset('public/vendor/apexcharts/apexcharts.min.js')",
|
|
$scripts
|
|
);
|
|
}
|
|
|
|
$loader = file_get_contents(
|
|
resource_path('views/components/charts/apexcharts-loader.blade.php')
|
|
);
|
|
|
|
$this->assertIsString($loader);
|
|
$this->assertStringContainsString(
|
|
"asset('public/vendor/apexcharts/apexcharts.min.js')",
|
|
$loader
|
|
);
|
|
|
|
$renderedLoader = Blade::render(<<<'BLADE'
|
|
@include('components.charts.apexcharts-loader')
|
|
@include('components.charts.apexcharts-loader')
|
|
@stack('chart_libraries')
|
|
BLADE);
|
|
|
|
$this->assertSame(
|
|
1,
|
|
substr_count($renderedLoader, 'public/vendor/apexcharts/apexcharts.min.js')
|
|
);
|
|
|
|
foreach ([
|
|
'views/widgets/line_chart.blade.php',
|
|
'views/widgets/donut_chart.blade.php',
|
|
'views/widgets/cash_flow.blade.php',
|
|
'views/widgets/bar_chart.blade.php',
|
|
'views/components/reports/summary/chart.blade.php',
|
|
] as $chartView) {
|
|
$view = file_get_contents(resource_path($chartView));
|
|
|
|
$this->assertIsString($view);
|
|
$this->assertStringContainsString(
|
|
"@include('components.charts.apexcharts-loader')",
|
|
$view
|
|
);
|
|
}
|
|
}
|
|
|
|
public function test_views_and_component_styles_do_not_depend_on_quicksand(): void
|
|
{
|
|
$headFiles = glob(
|
|
resource_path('views/components/layouts/*/head.blade.php')
|
|
);
|
|
|
|
$this->assertIsArray($headFiles);
|
|
$this->assertNotEmpty($headFiles);
|
|
|
|
foreach ($headFiles as $headFile) {
|
|
$head = file_get_contents($headFile);
|
|
|
|
$this->assertIsString($head);
|
|
$this->assertStringNotContainsString(
|
|
'public/vendor/quicksand/css/quicksand.css',
|
|
$head
|
|
);
|
|
}
|
|
|
|
foreach ([
|
|
base_path('config/apexcharts.php'),
|
|
public_path('css/third_party/vue-html-editor_custom.css'),
|
|
] as $componentStyle) {
|
|
$contents = file_get_contents($componentStyle);
|
|
|
|
$this->assertIsString($contents);
|
|
$this->assertStringNotContainsString('Quicksand', $contents);
|
|
$this->assertStringContainsString('JetBrains Mono', $contents);
|
|
}
|
|
}
|
|
}
|