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
69 changes: 33 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ jobs:
cs-fix:
name: Run code style check
runs-on: "ubuntu-24.04"
steps:
- uses: actions/checkout@v4

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
extensions: 'pdo_sqlite, gd'
tools: cs2pr
strategy:
fail-fast: false
matrix:
php:
- '7.4'
- '8.1'

steps:
- uses: actions/checkout@v4

- uses: ramsey/composer-install@v3
with:
dependency-versions: highest
- uses: ibexa/gh-workflows/actions/composer-install@main
with:
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
satis-network-token: ${{ secrets.SATIS_NETWORK_TOKEN }}

- name: Run code style check
run: composer run-script check-cs -- --format=checkstyle | cs2pr
- name: Run code style check
run: composer run-script check-cs -- --format=checkstyle | cs2pr

tests:
name: Unit & integration tests
Expand All @@ -39,34 +42,28 @@ jobs:
matrix:
php:
- '7.4'
- '8.0'
- '8.2'
- '8.1'

steps:
- uses: actions/checkout@v4

- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: pdo_sqlite, gd
tools: cs2pr
- uses: actions/checkout@v4

- uses: ramsey/composer-install@v3
with:
dependency-versions: highest
- uses: ibexa/gh-workflows/actions/composer-install@main
with:
gh-client-id: ${{ secrets.AUTOMATION_CLIENT_ID }}
gh-client-secret: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
satis-network-key: ${{ secrets.SATIS_NETWORK_KEY }}
satis-network-token: ${{ secrets.SATIS_NETWORK_TOKEN }}

- name: Run PHPStan analysis
run: composer run-script phpstan
- name: Run PHPStan analysis
run: composer run-script phpstan

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run unit test suite
run: composer test
- name: Run integration test suite
run: composer test-integration
- name: Run unit test suite
run: composer test
- name: Run integration test suite
run: composer test-integration

functional-tests:
name: "REST functional tests"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-xmlwriter": "*",
"ibexa/core": "~4.6.0@dev",
"ibexa/core": "~4.6.x-dev",
"symfony/http-kernel": "^5.3",
"symfony/dependency-injection": "^5.3",
"symfony/routing": "^5.3",
Expand Down
11 changes: 11 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recipesEndpoint": "",
"packages": [
{
"requirement": "dev-ct-group-is-system as 4.6.x-dev",
"repositoryUrl": "https://github.com/ibexa/core",
"package": "ibexa/core",
"shouldBeAddedAsVCS": false
}
]
}
4 changes: 3 additions & 1 deletion src/lib/Server/Controller/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ public function loadContentTypeGroupList(Request $request)
);
}

$includeSystem = $request->query->getBoolean('includeSystem', false);

return new Values\ContentTypeGroupList(
$this->contentTypeService->loadContentTypeGroups(Language::ALL)
$this->contentTypeService->loadContentTypeGroups(Language::ALL, $includeSystem)
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/Server/Input/Parser/ContentTypeGroupInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher)
$contentTypeGroupCreateStruct->creationDate = new DateTime($data['modificationDate']);
}

if (array_key_exists('isSystem', $data)) {
$contentTypeGroupCreateStruct->isSystem = $this->parserTools->parseBooleanValue($data['isSystem']);
}

// @todo mainLanguageCode, names, descriptions?

if (array_key_exists('User', $data) && is_array($data['User'])) {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/Server/Input/Parser/Criterion/LogicalNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LogicalNot extends CriterionParser
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('NOT', $data) && !is_array($data['NOT'])) {
if (!array_key_exists('NOT', $data) || !is_array($data['NOT'])) {
throw new Exceptions\Parser('Invalid <NOT> format');
}

Expand All @@ -37,6 +37,11 @@ public function parse(array $data, ParsingDispatcher $parsingDispatcher)
}
$criterionName = key($data['NOT']);
$criterionData = current($data['NOT']);

if (!is_string($criterionName)) {
throw new Exceptions\Parser('Invalid <NOT> format');
}

$criteria = $this->dispatchCriterion($criterionName, $criterionData, $parsingDispatcher);

return new LogicalNotCriterion($criteria);
Expand Down
113 changes: 113 additions & 0 deletions tests/bundle/Functional/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Ibexa\Tests\Bundle\Rest\Functional;

use Ibexa\Tests\Bundle\Rest\Functional\TestCase as RESTFunctionalTestCase;
use Psr\Http\Message\ResponseInterface;

class ContentTypeTest extends RESTFunctionalTestCase
{
Expand All @@ -23,9 +24,9 @@
XML;
$request = $this->createHttpRequest(
'POST',
'/api/ibexa/v2/content/typegroups',

Check failure on line 27 in tests/bundle/Functional/ContentTypeTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "/api/ibexa/v2/content/typegroups" 4 times.

See more on https://sonarcloud.io/project/issues?id=ibexa_rest&issues=AZrZdtpLofB72QVNFBK7&open=AZrZdtpLofB72QVNFBK7&pullRequest=208
'ContentTypeGroupInput+xml',

Check failure on line 28 in tests/bundle/Functional/ContentTypeTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "ContentTypeGroupInput+xml" 3 times.

See more on https://sonarcloud.io/project/issues?id=ibexa_rest&issues=AZranIyexLqXHRN-oe0J&open=AZranIyexLqXHRN-oe0J&pullRequest=208
'ContentTypeGroup+json',

Check failure on line 29 in tests/bundle/Functional/ContentTypeTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "ContentTypeGroup+json" 3 times.

See more on https://sonarcloud.io/project/issues?id=ibexa_rest&issues=AZranIyexLqXHRN-oe0K&open=AZranIyexLqXHRN-oe0K&pullRequest=208
$body
);
$response = $this->sendHttpRequest($request);
Expand Down Expand Up @@ -159,6 +160,50 @@
// @todo test data
}

/**
* Covers GET /content/typegroups without includeSystem param (defaults to false).
*/
public function testLoadContentTypeGroupListExcludesSystemByDefault(): void
{
$systemIdentifier = $this->createSystemContentTypeGroup();

$response = $this->sendHttpRequest(
$this->createHttpRequest(
'GET',
'/api/ibexa/v2/content/typegroups',
'',
'ContentTypeGroupList+json'

Check failure on line 175 in tests/bundle/Functional/ContentTypeTest.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "ContentTypeGroupList+json" 3 times.

See more on https://sonarcloud.io/project/issues?id=ibexa_rest&issues=AZranIyexLqXHRN-oe0L&open=AZranIyexLqXHRN-oe0L&pullRequest=208
)
);
self::assertHttpResponseCodeEquals($response, 200);

$identifiers = $this->getContentTypeGroupIdentifiers($response);

self::assertNotContains($systemIdentifier, $identifiers);
}

/**
* Covers GET /content/typegroups?includeSystem=true.
*/
public function testLoadContentTypeGroupListIncludesSystemGroups(): void
{
$systemIdentifier = $this->createSystemContentTypeGroup();

$response = $this->sendHttpRequest(
$this->createHttpRequest(
'GET',
'/api/ibexa/v2/content/typegroups?includeSystem=true',
'',
'ContentTypeGroupList+json'
)
);
self::assertHttpResponseCodeEquals($response, 200);

$identifiers = $this->getContentTypeGroupIdentifiers($response);

self::assertContains($systemIdentifier, $identifiers);
}

/**
* @depends testUpdateContentTypeGroup
* Covers GET /content/typegroups?identifier=<contentTypeGroupIdentifier>
Expand All @@ -172,6 +217,25 @@
self::assertHttpResponseCodeEquals($response, 307);
}

public function testCreateSystemContentTypeGroup(): void
{
$identifier = $this->createSystemContentTypeGroup();

$response = $this->sendHttpRequest(
$this->createHttpRequest(
'GET',
'/api/ibexa/v2/content/typegroups?includeSystem=true',
'',
'ContentTypeGroupList+json'
)
);
self::assertHttpResponseCodeEquals($response, 200);

$identifiers = $this->getContentTypeGroupIdentifiers($response);

self::assertContains($identifier, $identifiers);
}

/**
* @depends testUpdateContentTypeGroup
* Covers GET /content/typegroups/<contentTypeGroupId>
Expand Down Expand Up @@ -672,6 +736,55 @@
self::assertArrayHasKey('ContentTypeList', $responseData);
self::assertSame('image', $responseData['ContentTypeList']['ContentType'][0]['identifier']);
}

/**
* @return string[]
*/
private function getContentTypeGroupIdentifiers(ResponseInterface $response): array
{
$responseData = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
self::assertArrayHasKey('ContentTypeGroupList', $responseData);

$groupList = $responseData['ContentTypeGroupList']['ContentTypeGroup'] ?? [];
if (isset($groupList['_href'])) {
$groupList = [$groupList];
}

return array_map(
static function (array $group): string {
return strtolower($group['identifier'] ?? '');
},
$groupList
);
}

private function createSystemContentTypeGroup(): string
{
$identifier = $this->addTestSuffix('system_group_' . uniqid());
$body = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
<ContentTypeGroupInput>
<identifier>{$identifier}</identifier>
<isSystem>true</isSystem>
</ContentTypeGroupInput>
XML;

$request = $this->createHttpRequest(
'POST',
'/api/ibexa/v2/content/typegroups',
'ContentTypeGroupInput+xml',
'ContentTypeGroup+json',
$body
);

$response = $this->sendHttpRequest($request);
self::assertHttpResponseCodeEquals($response, 201);
self::assertHttpResponseHasHeader($response, 'Location');

$this->addCreatedElement($response->getHeader('Location')[0]);

return $identifier;
}
}

class_alias(ContentTypeTest::class, 'EzSystems\EzPlatformRestBundle\Tests\Functional\ContentTypeTest');
6 changes: 6 additions & 0 deletions tests/lib/Server/Input/Parser/ContentTypeGroupInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function testParse()
'_href' => '/user/users/14',
],
'modificationDate' => '2012-12-31T12:00:00',
'isSystem' => true,
];

$contentTypeGroupInput = $this->getParser();
Expand Down Expand Up @@ -52,6 +53,11 @@ public function testParse()
$result->creationDate,
'ContentTypeGroupCreateStruct creationDate property not created correctly.'
);

$this->assertTrue(
$result->isSystem,
'ContentTypeGroupCreateStruct isSystem property not created correctly.'
);
}

/**
Expand Down
Loading