Skip to content

Commit 109f485

Browse files
authored
Merge pull request #5686 from Gustry/print-3-40
Fix tests in print when the project has been updated
2 parents 7d9c301 + de22843 commit 109f485

File tree

6 files changed

+98
-67
lines changed

6 files changed

+98
-67
lines changed

lizmap/modules/admin_api/controllers/project_rest.classic.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @license https://www.mozilla.org/MPL/ Mozilla Public Licence
1010
*/
1111

12+
use Lizmap\App\VersionTools;
1213
use LizmapApi\Credentials;
1314
use LizmapApi\Error;
1415
use LizmapApi\RestApiCtrl;
@@ -106,6 +107,7 @@ protected function getProjDetail($rep, $repo)
106107
'wmsGetCapabilitiesUrl' => $proj->getWMSGetCapabilitiesUrl(),
107108
'wmtsGetCapabilitiesUrl' => $proj->getWMTSGetCapabilitiesUrl(),
108109
'version' => $projInfos['version'],
110+
'versionInt' => VersionTools::qgisVersionWithNameToInt($projInfos['version']),
109111
'saveDateTime' => $projInfos['saveDateTime'],
110112
'saveUser' => $projInfos['saveUser'],
111113
'saveUserFull' => $projInfos['saveUserFull'],

lizmap/modules/lizmap/lib/App/VersionTools.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,19 @@ public static function intVersionToSortableString(string $intVersion): string
7575

7676
return $majorVersion.'.'.$minorVersion.'.'.$patchVersion;
7777
}
78+
79+
/**
80+
* Transform a QGIS version with its name to a sortable int version.
81+
*
82+
* Transform "3.34.12-Prizren" into "33412"
83+
*
84+
* @param string $versionString Name of the version
85+
*/
86+
public static function qgisVersionWithNameToInt(string $versionString): int
87+
{
88+
$version = VersionTools::dropBuildId($versionString);
89+
$version = explode('.', $version);
90+
91+
return intval(intval($version[0]) * 10000 + intval($version[1]) * 100 + intval($version[2]));
92+
}
7893
}

tests/api/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ components:
157157
type: string
158158
description: Project key
159159
example: montpellier
160-
projectname:
160+
projectName:
161161
type: string
162162
description: Project name
163163
example: Montpellier-Transports

tests/end2end/playwright/globals.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path';
1010
*/
1111

1212
/**
13-
* Playwright Page
13+
* Playwright APIResponse
1414
* @typedef {import('@playwright/test').APIResponse} APIResponse
1515
*/
1616

@@ -243,6 +243,32 @@ export async function expectToHaveLengthCompare(title, parameters, expectedLengt
243243
).toHaveLength(expectedLength);
244244
}
245245

246+
/**
247+
* Get the JSON for the given project using the API
248+
* @param {import("playwright-core/types/types.js").APIRequestContext} request Request to use
249+
* @param {string} project The project name
250+
* @param {string} repository The repository name, default to "testsrepository".
251+
* @returns {Promise<any>} The JSON response
252+
*/
253+
export async function jsonFromProjectApi(request, project, repository = 'testsrepository') {
254+
return await requestWithAdminBasicAuth(
255+
request,
256+
`/api.php/admin/repositories/${repository}/projects/${project}`
257+
);
258+
}
259+
260+
/**
261+
* Get the version of QGIS written in the project
262+
* @param {import("playwright-core/types/types.js").APIRequestContext} request Request to use
263+
* @param {string} project The project name
264+
* @returns {int} The QGIS version, written as "34004" for QGIS 3.40.4, to be easily sortable.
265+
*/
266+
export async function qgisVersionFromProjectApi(request, project) {
267+
const response = await jsonFromProjectApi(request, project);
268+
const json = await checkJson(response);
269+
return json.versionInt;
270+
}
271+
246272
/**
247273
* Check for a JSON response
248274
* @param {APIResponse} response The response object

tests/end2end/playwright/print.spec.js

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ import * as fs from 'fs/promises'
44
import { existsSync } from 'node:fs';
55
import { test, expect } from '@playwright/test';
66
import {PrintPage} from "./pages/printpage";
7-
import { gotoMap, expectParametersToContain, getAuthStorageStatePath, expectToHaveLengthCompare, playwrightTestFile } from './globals';
7+
import {
8+
gotoMap,
9+
expectParametersToContain,
10+
getAuthStorageStatePath,
11+
expectToHaveLengthCompare,
12+
playwrightTestFile,
13+
qgisVersionFromProjectApi,
14+
} from './globals';
815

916
// To update OSM and GeoPF tiles in the mock directory
1017
// IMPORTANT, this must not be set to `true` while committing, on GitHub. Set to `false`.
1118
const UPDATE_MOCK_FILES = false;
1219

20+
1321
test.describe('Print', () => {
1422

1523
test.beforeEach(async ({ page }) => {
@@ -51,7 +59,7 @@ test.describe('Print', () => {
5159
expect(await page.locator('.btn-print-dpis').inputValue()).toBe('200');
5260
});
5361

54-
test('Print requests', async ({ page }) => {
62+
test('Print requests', async ({ request, page }) => {
5563
// Required GetPrint parameters
5664
const expectedParameters = {
5765
'SERVICE': 'WMS',
@@ -72,10 +80,6 @@ test.describe('Print', () => {
7280

7381
// Launch print
7482
await page.locator('#print-launch').click();
75-
// check message
76-
await expect(page.locator('div.alert')).toHaveCount(1)
77-
// Close message
78-
await page.locator('div.alert button.btn-close').click();
7983

8084
// check request
8185
let getPrintRequest = await getPrintPromise;
@@ -90,13 +94,14 @@ test.describe('Print', () => {
9094
// Disabled because of the migration when project is saved with QGIS >= 3.32
9195
// 'multiline_label': 'Multiline label',
9296
})
97+
let expectedLength = 15;
98+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
99+
expectedLength = 14;
100+
}
93101
let name = "Print requests";
94102
let getPrintParams = await expectParametersToContain(
95103
name, getPrintRequest.postData() ?? '', expectedParameters1);
96-
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), 15, Object.keys(expectedParameters1));
97-
98-
// Close message
99-
await page.locator('.btn-close').click();
104+
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), expectedLength, Object.keys(expectedParameters1));
100105

101106
// Test `print_map` template
102107
await page.locator('#print-template').selectOption('1');
@@ -137,10 +142,6 @@ test.describe('Print', () => {
137142

138143
// Launch print
139144
await page.locator('#print-launch').click();
140-
// check message
141-
await expect(page.locator('div.alert')).toHaveCount(1)
142-
// Close message
143-
await page.locator('div.alert button.btn-close').click();
144145

145146
// check request
146147
getPrintRequest = await getPrintPromise;
@@ -191,10 +192,6 @@ test.describe('Print', () => {
191192

192193
// Launch print
193194
await page.locator('#print-launch').click();
194-
// check message
195-
await expect(page.locator('div.alert')).toHaveCount(1)
196-
// Close message
197-
await page.locator('div.alert button.btn-close').click();
198195

199196
// check request
200197
getPrintRequest = await getPrintPromise;
@@ -235,6 +232,10 @@ test.describe('Print', () => {
235232
// 'multiline_label': 'Multiline label',
236233
})
237234
/* eslint-enable no-useless-escape, @stylistic/js/max-len */
235+
expectedLength = 17
236+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
237+
expectedLength = 16;
238+
}
238239
name = 'Print requests 4';
239240
getPrintParams = await expectParametersToContain(
240241
name,
@@ -243,12 +244,12 @@ test.describe('Print', () => {
243244
await expectToHaveLengthCompare(
244245
name,
245246
Array.from(getPrintParams.keys()),
246-
17,
247+
expectedLength,
247248
Object.keys(expectedParameters4)
248249
);
249250
});
250251

251-
test('Print requests with selection', async ({ page }) => {
252+
test('Print requests with selection', async ({ request, page }) => {
252253
// Select a feature
253254
await page.locator('#button-attributeLayers').click();
254255
await page.getByRole('button', { name: 'Detail' }).click();
@@ -264,10 +265,6 @@ test.describe('Print', () => {
264265

265266
// Launch print
266267
await page.locator('#print-launch').click();
267-
// check message
268-
await expect(page.locator('div.alert')).toHaveCount(1)
269-
// Close message
270-
await page.locator('div.alert button.btn-close').click();
271268

272269
// check request
273270
const getPrintRequest = await getPrintPromise;
@@ -290,11 +287,15 @@ test.describe('Print', () => {
290287
}
291288
const name = "Print requests with selection";
292289
const getPrintParams = await expectParametersToContain(name, getPrintRequest.postData() ?? '', expectedParameters);
293-
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), 16, Object.keys(expectedParameters));
290+
let expectedLength = 16;
291+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
292+
expectedLength = 15;
293+
}
294+
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), expectedLength, Object.keys(expectedParameters));
294295

295296
});
296297

297-
test('Print requests with filter', async ({ page }) => {
298+
test('Print requests with filter', async ({ request, page }) => {
298299
// Select a feature
299300
await page.locator('#button-attributeLayers').click();
300301
await page.getByRole('button', { name: 'Detail' }).click();
@@ -315,10 +316,6 @@ test.describe('Print', () => {
315316

316317
// Launch print
317318
await page.locator('#print-launch').click();
318-
// check message
319-
await expect(page.locator('div.alert')).toHaveCount(1)
320-
// Close message
321-
await page.locator('div.alert button.btn-close').click();
322319

323320
// check request
324321
const getPrintRequest = await getPrintPromise;
@@ -339,9 +336,13 @@ test.describe('Print', () => {
339336
'simple_label': 'simple label',
340337
'FILTERTOKEN': /[a-z\d]+/,
341338
}
339+
let expectedLength = 16;
340+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
341+
expectedLength = 15;
342+
}
342343
const name = 'Print requests with filter';
343344
const getPrintParams = await expectParametersToContain(name, getPrintRequest.postData() ?? '', expectedParameters);
344-
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), 16, Object.keys(expectedParameters));
345+
await expectToHaveLengthCompare(name, Array.from(getPrintParams.keys()), expectedLength, Object.keys(expectedParameters));
345346
});
346347
});
347348

@@ -691,7 +692,7 @@ test.describe('Print 3857', () => {
691692
expect(await page.locator('.btn-print-dpis').inputValue()).toBe('200');
692693
});
693694

694-
test('Print requests', async ({ page }) => {
695+
test('Print requests', async ({ request, page }) => {
695696
// Required GetPrint parameters
696697
const expectedParameters = {
697698
'SERVICE': 'WMS',
@@ -708,10 +709,6 @@ test.describe('Print 3857', () => {
708709

709710
// Launch print
710711
await page.locator('#print-launch').click();
711-
// check message
712-
await expect(page.locator('div.alert')).toHaveCount(1)
713-
// Close message
714-
await page.locator('div.alert button.btn-close').click();
715712

716713
// check request
717714
let getPrintRequest = await getPrintPromise;
@@ -732,10 +729,14 @@ test.describe('Print 3857', () => {
732729
getPrintRequest.postData() ?? '',
733730
expectedParameters1
734731
);
732+
let expectedLength = 15;
733+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
734+
expectedLength = 14;
735+
}
735736
await expectToHaveLengthCompare(
736737
name,
737738
Array.from(getPrintParams.keys()),
738-
15,
739+
expectedLength,
739740
Object.keys(expectedParameters1)
740741
);
741742

@@ -749,10 +750,6 @@ test.describe('Print 3857', () => {
749750

750751
// Launch print
751752
await page.locator('#print-launch').click();
752-
// check message
753-
await expect(page.locator('div.alert')).toHaveCount(1)
754-
// Close message
755-
await page.locator('div.alert button.btn-close').click();
756753

757754
// check request
758755
getPrintRequest = await getPrintPromise;
@@ -776,9 +773,6 @@ test.describe('Print 3857', () => {
776773
Object.keys(expectedParameters2)
777774
);
778775

779-
// Close message
780-
await page.locator('.btn-close').click();
781-
782776
// Redlining with circle
783777
await page.locator('#button-draw').click();
784778
await page.getByRole('button', { name: 'Toggle Dropdown' }).click();
@@ -807,10 +801,6 @@ test.describe('Print 3857', () => {
807801

808802
// Launch print
809803
await page.locator('#print-launch').click();
810-
// check message
811-
await expect(page.locator('div.alert')).toHaveCount(1)
812-
// Close message
813-
await page.locator('div.alert button.btn-close').click();
814804

815805
// check request
816806
getPrintRequest = await getPrintPromise;
@@ -856,10 +846,14 @@ test.describe('Print 3857', () => {
856846
getPrintRequest.postData() ?? ''
857847
, expectedParameters3
858848
);
849+
expectedLength = 17;
850+
if (await qgisVersionFromProjectApi(request, 'print') > 33200) {
851+
expectedLength = 16;
852+
}
859853
await expectToHaveLengthCompare(
860854
name,
861855
Array.from(getPrintParams.keys()),
862-
17,
856+
expectedLength,
863857
Object.keys(expectedParameters3)
864858
);
865859
});
@@ -930,10 +924,6 @@ test.describe('Print base layers', () => {
930924

931925
// Launch print
932926
await page.locator('#print-launch').click();
933-
// check message
934-
await expect(page.locator('div.alert')).toHaveCount(1)
935-
// Close message
936-
await page.locator('div.alert button.btn-close').click();
937927

938928
// check request
939929
let getPrintRequest = await getPrintRequestPromise;
@@ -974,10 +964,6 @@ test.describe('Print base layers', () => {
974964

975965
// Launch print
976966
await page.locator('#print-launch').click();
977-
// check message
978-
await expect(page.locator('div.alert')).toHaveCount(1)
979-
// Close message
980-
await page.locator('div.alert button.btn-close').click();
981967

982968
// check request
983969
getPrintRequest = await getPrintRequestPromise;
@@ -1054,10 +1040,6 @@ test.describe('Print base layers', () => {
10541040

10551041
// Launch print
10561042
await page.locator('#print-launch').click();
1057-
// check message
1058-
await expect(page.locator('div.alert')).toHaveCount(1)
1059-
// Close message
1060-
await page.locator('div.alert button.btn-close').click();
10611043

10621044
// check request
10631045
getPrintRequest = await getPrintRequestPromise;
@@ -1097,10 +1079,6 @@ test.describe('Print base layers', () => {
10971079

10981080
// Launch print
10991081
await page.locator('#print-launch').click();
1100-
// check message
1101-
await expect(page.locator('div.alert')).toHaveCount(1)
1102-
// Close message
1103-
await page.locator('div.alert button.btn-close').click();
11041082

11051083
// check request
11061084
getPrintRequest = await getPrintRequestPromise;

tests/units/classes/App/VersionToolsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public function testQgisMajMinHumanVersion(): void
2424
$this->assertEquals('1.40', VersionTools::qgisMajMinHumanVersion('1040')); // Fixme when QGIS 10 is released :)
2525
}
2626

27+
public function testQgisVersionWithNameToInt(): void
28+
{
29+
$this->assertEquals(33410, VersionTools::qgisVersionWithNameToInt('3.34.10-Bratislava'));
30+
$this->assertEquals(34006, VersionTools::qgisVersionWithNameToInt('3.40.6-Bratislava'));
31+
$this->assertEquals(34010, VersionTools::qgisVersionWithNameToInt('3.40.10-Prizren'));
32+
$this->assertEquals(40000, VersionTools::qgisVersionWithNameToInt('4.0.0-Prizren'));
33+
$this->assertEquals(40400, VersionTools::qgisVersionWithNameToInt('4.4.0-Prizren'));
34+
$this->assertEquals(33412, VersionTools::qgisVersionWithNameToInt('03.34.12'));
35+
}
36+
2737
public function testIntVersionToSortableString(): void
2838
{
2939
$this->assertEquals('01.01.02', VersionTools::intVersionToSortableString('01.01.02'));

0 commit comments

Comments
 (0)