Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 STRATO GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace OCA\NcwTools;

use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {
/**
* Override support capabilities to always show valid subscription
* This ensures the support capability is present even if the support app
* returns an empty array when subscription check fails.
*
* @return array{
* support: array{
* hasValidSubscription: bool,
* desktopEnterpriseChannel?: string,
* }
* }
*/
public function getCapabilities(): array {
return [
'support' => [
'hasValidSubscription' => true,
'desktopEnterpriseChannel' => 'stable',
],
];
}
}
90 changes: 90 additions & 0 deletions tests/integration/CapabilitiesIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 STRATO GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace OCA\NcwTools\Tests\Integration;

use OC\CapabilitiesManager;
use OCA\NcwTools\Capabilities;
use Psr\Log\LoggerInterface;
use Test\TestCase;

/**
* Integration test to verify that the ncw_tools Capabilities class
* properly overrides the support.hasValidSubscription value in the
* actual Nextcloud capabilities system.
*
* @group DB
*/
class CapabilitiesIntegrationTest extends TestCase {
private CapabilitiesManager $capabilitiesManager;
private LoggerInterface $logger;

protected function setUp(): void {
parent::setUp();
$this->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'
);
}
}
22 changes: 22 additions & 0 deletions tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- SPDX-FileCopyrightText: 2026 STRATO GmbH
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="bootstrap.php"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
timeoutForLargeTests="900"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
cacheDirectory=".phpunit.cache">
<testsuite name="NCW Tools Integration Tests">
<directory suffix="Test.php">./integration</directory>
</testsuite>
<source>
<include>
<directory suffix=".php">../appinfo</directory>
<directory suffix=".php">../lib</directory>
</include>
</source>
</phpunit>
5 changes: 3 additions & 2 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="bootstrap.php" timeoutForSmallTests="900" timeoutForMediumTests="900" timeoutForLargeTests="900" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuite name="NCW Tools Tests">
<directory suffix="Test.php">.</directory>
<testsuite name="NCW Tools Unit Tests">
<directory suffix="Test.php">./unit</directory>
<exclude>./integration</exclude>
</testsuite>
<source>
<include>
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 STRATO GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);

namespace OCA\NcwTools\Tests\Unit;

use OCA\NcwTools\Capabilities;
use Test\TestCase;

class CapabilitiesTest extends TestCase {
private Capabilities $capabilities;

protected function setUp(): void {
parent::setUp();
$this->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);
}
}