From 4a451077c75496cae4cfefd58198e823e88d7716 Mon Sep 17 00:00:00 2001 From: Tim Goudriaan Date: Tue, 31 Dec 2024 11:49:46 +0100 Subject: [PATCH] Add test for dashboard package statistics page --- .../packages/package_statistics.html.twig | 6 ++--- .../DashboardPackagesControllerTest.php | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/templates/dashboard/packages/package_statistics.html.twig b/templates/dashboard/packages/package_statistics.html.twig index 7e8fd94..0174250 100644 --- a/templates/dashboard/packages/package_statistics.html.twig +++ b/templates/dashboard/packages/package_statistics.html.twig @@ -9,7 +9,7 @@

{{ 'Installations'|trans }}

-
+
{{ 'Total'|trans }}:
{{ installationsTotal|number_format(thousandSep: ' ') }}
@@ -17,7 +17,7 @@
-
+
{{ 'Last 30 days'|trans }}:
{{ installationsLast30Days|number_format(thousandSep: ' ') }}
@@ -25,7 +25,7 @@
-
+
{{ 'Today'|trans }}:
{{ installationsToday|number_format(thousandSep: ' ') }}
diff --git a/tests/FunctionalTests/DashboardPackagesControllerTest.php b/tests/FunctionalTests/DashboardPackagesControllerTest.php index b765245..73fbeb0 100644 --- a/tests/FunctionalTests/DashboardPackagesControllerTest.php +++ b/tests/FunctionalTests/DashboardPackagesControllerTest.php @@ -9,6 +9,29 @@ class DashboardPackagesControllerTest extends WebTestCase { + public function testStatistics(): void + { + $client = static::createClient(); + + /** @var UserRepository $userRepository */ + $userRepository = $client->getContainer()->get(UserRepository::class); + + /** @var User $user */ + $user = $userRepository->findOneByUsername('user'); + $client->loginUser($user); + + $client->request('GET', '/?routeName=dashboard_packages_statistics&routeParams[packageName]=psr/log'); + + $this->assertResponseStatusCodeSame(200); + + /** @var PackageRepository $packageRepository */ + $packageRepository = $client->getContainer()->get(PackageRepository::class); + + $package = $packageRepository->findOneByName('psr/log'); + + $this->assertAnySelectorTextSame('#total_all .display-6', number_format($package->getInstallations()->getTotal(), thousands_separator: ' ')); + } + public function testAddVcsRepository(): void { $client = static::createClient();