From 4f5c6befcd710c29a58b3b397b3a891848b7c4c9 Mon Sep 17 00:00:00 2001 From: Arsalan Ul Haq Sohni Date: Mon, 23 Feb 2026 10:53:06 +0100 Subject: [PATCH 1/3] feat(capabilities): add support capabilities to indicate valid subscription status Signed-off-by: Arsalan Ul Haq Sohni --- lib/AppInfo/Application.php | 2 ++ lib/Capabilities.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/Capabilities.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a8c6535..b00a4d4 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,6 +9,7 @@ namespace OCA\NcwTools\AppInfo; +use OCA\NcwTools\Capabilities; use OCA\NcwTools\Listeners\InstallationCompletedEventListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -25,6 +26,7 @@ public function __construct() { public function register(IRegistrationContext $context): void { $context->registerEventListener(InstallationCompletedEvent::class, InstallationCompletedEventListener::class); + $context->registerCapability(Capabilities::class); } public function boot(IBootContext $context): void { diff --git a/lib/Capabilities.php b/lib/Capabilities.php new file mode 100644 index 0000000..6b42d64 --- /dev/null +++ b/lib/Capabilities.php @@ -0,0 +1,35 @@ + [ + 'hasValidSubscription' => true, + 'desktopEnterpriseChannel' => 'stable', + ], + ]; + } +} From 1be57e006b026ebff56a7ca6c235edb383bf142f Mon Sep 17 00:00:00 2001 From: Arsalan Ul Haq Sohni Date: Mon, 23 Feb 2026 13:38:59 +0100 Subject: [PATCH 2/3] chore(tests): restructure PHPUnit configuration for unit and integration tests Signed-off-by: Arsalan Ul Haq Sohni --- composer.json | 3 ++- tests/phpunit.integration.xml | 22 ++++++++++++++++++++++ tests/phpunit.xml | 5 +++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit.integration.xml diff --git a/composer.json b/composer.json index 31a83f0..8844d25 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "cs:check": "php-cs-fixer fix --dry-run --diff", "cs:fix": "php-cs-fixer fix", "psalm": "psalm --threads=1 --no-cache", - "test:unit": "phpunit tests -c tests/phpunit.xml --colors=always --fail-on-warning --fail-on-risky", + "test:unit": "phpunit -c tests/phpunit.xml --colors=always --fail-on-warning --fail-on-risky", + "test:integration": "phpunit -c tests/phpunit.integration.xml --colors=always", "openapi": "generate-spec", "rector": "rector && composer cs:fix" }, diff --git a/tests/phpunit.integration.xml b/tests/phpunit.integration.xml new file mode 100644 index 0000000..3cba3ce --- /dev/null +++ b/tests/phpunit.integration.xml @@ -0,0 +1,22 @@ + + + + + ./integration + + + + ../appinfo + ../lib + + + diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 28b6835..7cc3223 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,7 +1,8 @@ - - . + + ./unit + ./integration From e5478c2ba7b5fc6976df94511c98adc461cc4b21 Mon Sep 17 00:00:00 2001 From: Arsalan Ul Haq Sohni Date: Mon, 23 Feb 2026 13:40:07 +0100 Subject: [PATCH 3/3] test(capabilities): add integration and unit tests for Capabilities class Signed-off-by: Arsalan Ul Haq Sohni --- .../CapabilitiesIntegrationTest.php | 90 +++++++++++++++++++ tests/unit/CapabilitiesTest.php | 37 ++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/integration/CapabilitiesIntegrationTest.php create mode 100644 tests/unit/CapabilitiesTest.php diff --git a/tests/integration/CapabilitiesIntegrationTest.php b/tests/integration/CapabilitiesIntegrationTest.php new file mode 100644 index 0000000..18b2b97 --- /dev/null +++ b/tests/integration/CapabilitiesIntegrationTest.php @@ -0,0 +1,90 @@ +logger = $this->createMock(LoggerInterface::class); + // Create a fresh CapabilitiesManager for isolation + $this->capabilitiesManager = new CapabilitiesManager($this->logger); + } + + public function testCapabilityIsRegisteredInSystem(): void { + // Register our capability + $this->capabilitiesManager->registerCapability(function () { + return new Capabilities(); + }); + + $capabilities = $this->capabilitiesManager->getCapabilities(); + + // Verify the support capability exists + $this->assertArrayHasKey('support', $capabilities, 'Support capability should be present'); + $this->assertArrayHasKey('hasValidSubscription', $capabilities['support'], 'hasValidSubscription should be present'); + } + + public function testHasValidSubscriptionIsSetToFalse(): void { + // Register our capability + $this->capabilitiesManager->registerCapability(function () { + return new Capabilities(); + }); + + $capabilities = $this->capabilitiesManager->getCapabilities(); + + // Verify the value is true + $this->assertTrue( + $capabilities['support']['hasValidSubscription'], + 'hasValidSubscription should be true as set by ncw_tools' + ); + } + + public function testCapabilityOverridesOtherApps(): void { + // Simulate another app setting hasValidSubscription to true + $this->capabilitiesManager->registerCapability(function () { + return new class implements \OCP\Capabilities\ICapability { + public function getCapabilities() { + return [ + 'support' => [ + 'hasValidSubscription' => true, + ], + ]; + } + }; + }); + + // Now register our capability that should also set it to true + $this->capabilitiesManager->registerCapability(function () { + return new Capabilities(); + }); + + $capabilities = $this->capabilitiesManager->getCapabilities(); + + // Verify it's true + $this->assertTrue( + $capabilities['support']['hasValidSubscription'], + 'ncw_tools should ensure hasValidSubscription is true' + ); + } +} diff --git a/tests/unit/CapabilitiesTest.php b/tests/unit/CapabilitiesTest.php new file mode 100644 index 0000000..fc19757 --- /dev/null +++ b/tests/unit/CapabilitiesTest.php @@ -0,0 +1,37 @@ +capabilities = new Capabilities(); + } + + public function testGetCapabilities(): void { + $expected = [ + 'support' => [ + 'hasValidSubscription' => true, + 'desktopEnterpriseChannel' => 'stable', + ], + ]; + + $this->assertSame($expected, $this->capabilities->getCapabilities()); + } + + public function testImplementsICapabilityInterface(): void { + $this->assertInstanceOf(\OCP\Capabilities\ICapability::class, $this->capabilities); + } +}