Skip to content
Merged
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: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ parameters:
- tests
level: 5
ignoreErrors:
-
message: '#^Cannot unset property App\\Test\\.* because it might have hooks in a subclass\.$#'
path: tests/*
-
message: '#^Call to static method PHPUnit\\Framework\\Assert::assertIsArray\(\) with .* will always evaluate to true\.$#'
path: tests/*
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/Component/ModulesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function (&$data, $key) use ($metaModules): void {
unset($this->modules['tags']);
}
$types = array_keys($this->modules);
if (isset($this->modules['translations']) && !$this->translationsEnabled($types)) {
// Filter out non-object-type modules (like 'tags') before checking translations
$objectTypes = array_diff($types, array_keys($this->otherModules));
if (isset($this->modules['translations']) && !$this->translationsEnabled($objectTypes)) {
unset($this->modules['translations']);
}

Expand Down
71 changes: 71 additions & 0 deletions tests/TestCase/Controller/Component/ModulesComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2075,4 +2075,75 @@ public function testSaveRelatedObjectsChildrenFoldersAddRelatedRemoveRelatedOnly
$actual = $this->Modules->saveRelatedObjects('123456789', 'folders', $data);
static::assertSame([], $actual);
}

/**
* Test that `getModules()` does not pass 'tags' to `translationsEnabled()`.
* Tags is a non-object-type module and calling getSchema('tags') would cause an API error.
*
* @return void
*/
public function testGetModulesDoesNotPassNonObjectTypeModulesToTranslationsEnabled(): void
{
Cache::clear(SchemaComponent::CACHE_CONFIG);
Configure::write('Modules', ['documents' => []]);

// Setup mock API client
$apiClient = $this->getMockBuilder(BEditaClient::class)
->setConstructorArgs(['https://api.example.org'])
->getMock();
$schemaCallCount = 0;
$schemaCallTypes = [];

// Mock schema method - should only be called for object types, never for 'tags'
$apiClient->method('schema')
->willReturnCallback(
function ($type) use (&$schemaCallCount, &$schemaCallTypes) {
$schemaCallCount++;
$schemaCallTypes[] = $type;
static::assertNotSame('tags', $type, 'getSchema should not be called for tags');
if ($type === 'documents') {
return ['translatable' => ['title']];
}

return [];
},
);

// Mock get method for /home endpoint (modulesFromMeta)
$apiClient->method('get')
->willReturnCallback(
function ($endpoint) {
if ($endpoint === '/home') {
return [
'meta' => [
'resources' => [
[
'name' => 'documents',
'hints' => ['object_type' => true],
],
],
],
];
}

return [];
},
);

ApiClientProvider::setApiClient($apiClient);

// Mock Authentication component
$appController = $this->Modules->getController();
$request = $appController->getRequest()->withAttribute('authentication', $this->getAuthenticationServiceMock());
$appController->setRequest($request);
$this->Modules->Authentication->setIdentity(new Identity(['id' => 1, 'roles' => ['guest']]));

// Call getModules - should not throw an error about /model/schema/tags
$modules = $this->Modules->getModules();

// Verify that modules were returned
static::assertIsArray($modules);
// Verify that schema was called but only for object types
static::assertNotContains('tags', $schemaCallTypes, 'schema should not be called with tags');
}
}
Loading