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
2 changes: 1 addition & 1 deletion .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: "BLEEDING_EDGE"
php: "8.4"
pg-postgis: "17-3"
qgis-server: "3.42"
qgis-server: "3.44"
update-projects: "TRUE"
env:
CYPRESS_CI: TRUE
Expand Down
18 changes: 18 additions & 0 deletions lizmap/modules/lizmap/lib/Project/Qgis/LayerTreeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* @property bool $mutuallyExclusive
* @property array $customproperties
* @property array<LayerTreeGroup|LayerTreeLayer> $items
* @property null|string $shortname
* @property null|string $title
* @property null|string $abstract
*/
class LayerTreeGroup extends BaseQgisXmlObject
{
Expand All @@ -29,6 +32,9 @@ class LayerTreeGroup extends BaseQgisXmlObject
'mutuallyExclusive',
'customproperties',
'items',
'shortname',
'title',
'abstract',
);

/** @var array The default values for properties */
Expand All @@ -40,6 +46,13 @@ class LayerTreeGroup extends BaseQgisXmlObject
/** @var string The XML element local name */
protected static $qgisLocalName = 'layer-tree-group';

/** @var array<string> The XML element parsed children */
protected static $children = array(
'shortname',
'title',
'abstract',
);

protected static $childParsers = array();

/** @var array<string, string> The XML element tagname associated with a collector property name */
Expand Down Expand Up @@ -76,6 +89,11 @@ public function getGroupShortNames()
continue;
}
$data += $item->getGroupShortNames();
if (isset($item->shortname) && $item->shortname != null) {
$data[$item->name] = $item->shortname;

continue;
}
if (!array_key_exists('wmsShortName', $item->customproperties)) {
continue;
}
Expand Down
115 changes: 0 additions & 115 deletions tests/end2end/cypress/integration/requests-service-ghaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,121 +232,6 @@ describe('Request service', function () {
})
})

it('WMTS GetCapabilities', function () {
cy.request('/index.php/lizmap/service/?repository=testsrepository&project=cache&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities')
.then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.headers['content-type']).to.eq('text/xml; charset=utf-8')
expect(resp.headers['cache-control']).to.eq('no-cache')
expect(resp.headers['etag']).to.not.eq(undefined)

expect(resp.body).to.contain('version="1.0.0"')
expect(resp.body).to.contain('<ows:Identifier>Quartiers</ows:Identifier>')
expect(resp.body).to.contain('<TileMatrixSet>EPSG:3857</TileMatrixSet>')

const etag = resp.headers['etag']
cy.request({
url: '/index.php/lizmap/service/?repository=testsrepository&project=cache&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities',
headers: {
'If-None-Match': etag,
},
failOnStatusCode: false,
}).then((resp) => {
expect(resp.status).to.eq(304)
expect(resp.body).to.have.length(0)
})
})
})

it('WMTS GetTile', function () {
// Get full transparent tile TILEMATRIX=13&TILEROW=2989&TILECOL=4185
cy.request({
method: 'GET',
url: '/index.php/lizmap/service/?repository=testsrepository&project=cache',
qs: {
'SERVICE': 'WMTS',
'VERSION': '1.0.0',
'REQUEST': 'GetTile',
'LAYER': 'Quartiers',
'STYLE': 'default',
'TILEMATRIXSET': 'EPSG:3857',
'TILEMATRIX': '13',
'TILEROW': '2989',
'TILECOL': '4185',
'FORMAT': 'image/png',
},
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.headers['content-type']).to.contain('image/png')
expect(resp.headers).to.have.property('content-length', '355') // Transparent
expect(resp.headers).to.have.property('date')
const tileDate = new Date(resp.headers['date'])
expect(resp.headers).to.have.property('expires')
const tileExpires = new Date(resp.headers['expires'])
expect(tileExpires).to.be.greaterThan(tileDate)
/*expect(resp.body).to.contain('version="1.0.0"')*/
})

// Get not full transparent tile TILEMATRIX=13&TILEROW=2991&TILECOL=4184
cy.request({
method: 'GET',
url: '/index.php/lizmap/service/?repository=testsrepository&project=cache',
qs: {
'SERVICE': 'WMTS',
'VERSION': '1.0.0',
'REQUEST': 'GetTile',
'LAYER': 'Quartiers',
'STYLE': 'default',
'TILEMATRIXSET': 'EPSG:3857',
'TILEMATRIX': '13',
'TILEROW': '2991',
'TILECOL': '4184',
'FORMAT': 'image/png',
},
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.headers['content-type']).to.contain('image/png')
expect(resp.headers).to.have.property('content-length')
expect(parseInt(resp.headers['content-length'])).to.be.greaterThan(355) // Not transparent
expect(parseInt(resp.headers['content-length'])).to.be.within(11020, 11030 ) // Monochrome
expect(resp.headers).to.have.property('date')
const tileDate = new Date(resp.headers['date'])
expect(resp.headers).to.have.property('expires')
const tileExpires = new Date(resp.headers['expires'])
expect(tileExpires).to.be.greaterThan(tileDate)
/*expect(resp.body).to.contain('version="1.0.0"')*/
})

// Get monochrome tile TILEMATRIX=15&TILEROW=11964&TILECOL=16736
cy.request({
method: 'GET',
url: '/index.php/lizmap/service/?repository=testsrepository&project=cache',
qs: {
'SERVICE': 'WMTS',
'VERSION': '1.0.0',
'REQUEST': 'GetTile',
'LAYER': 'Quartiers',
'STYLE': 'default',
'TILEMATRIXSET': 'EPSG:3857',
'TILEMATRIX': '15',
'TILEROW': '11964',
'TILECOL': '16736',
'FORMAT': 'image/png',
},
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.headers['content-type']).to.contain('image/png')
expect(resp.headers).to.have.property('content-length')
expect(parseInt(resp.headers['content-length'])).to.be.greaterThan(355) // Not transparent
expect(resp.headers).to.have.property('date')
const tileDate = new Date(resp.headers['date'])
expect(resp.headers).to.have.property('expires')
const tileExpires = new Date(resp.headers['expires'])
expect(tileExpires).to.be.greaterThan(tileDate)
/*expect(resp.body).to.contain('version="1.0.0"')*/
})
})

it('Project parameter is mandatory', function () {
cy.request({
url: '/index.php/lizmap/service/?repository=testsrepository&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities',
Expand Down
143 changes: 143 additions & 0 deletions tests/end2end/playwright/requests-wmts.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// @ts-check
import { test, expect } from '@playwright/test';

test.describe('WMTS Requests @requests @readonly', () => {
test('WMTS Getcapabilities', async({ request }) => {
let params = new URLSearchParams({
repository: 'testsrepository',
project: 'cache',
SERVICE: 'WMTS',
VERSION: '1.0.0',
REQUEST: 'GetCapabilities',
});
let url = `/index.php/lizmap/service?${params}`;
let response = await request.get(url, {});
// check response
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
// check content-type header
expect(response.headers()['content-type']).toBe('text/xml; charset=utf-8');
// check headers
expect(response.headers()).toHaveProperty('cache-control');
expect(response.headers()['cache-control']).toBe('no-cache');
expect(response.headers()).toHaveProperty('etag');
const etag = response.headers()['etag'];
expect(etag).not.toBe('');
expect(etag).toHaveLength(43);

// check body
let body = await response.text();
expect(body).toContain('Capabilities');
expect(body).toContain('version="1.0.0"');
expect(body).toContain('xmlns="http://www.opengis.net/wmts/1.0"');
expect(body).toContain('<ows:Identifier>Quartiers</ows:Identifier>');
expect(body).toContain('<TileMatrixSet>EPSG:3857</TileMatrixSet>');

// GET request with the etag
response = await request.get(url, {
headers: {
'If-None-Match': etag
}
});
await expect(response).not.toBeOK();
expect(response.status()).toBe(304);
})

test('WMTS GetTile', async({ request }) => {
let params = new URLSearchParams({
repository: 'testsrepository',
project: 'cache',
SERVICE: 'WMTS',
VERSION: '1.0.0',
REQUEST: 'GetTile',
LAYER: 'Quartiers',
STYLE: 'default',
TILEMATRIXSET: 'EPSG:3857',
TILEMATRIX: '13',
TILEROW: '2989',
TILECOL: '4185',
FORMAT: 'image/png',
});
let url = `/index.php/lizmap/service?${params}`;
let response = await request.get(url, {});
// check response
await expect(response).toBeOK();
expect(response.status()).toBe(200);
// check content-type header
expect(response.headers()['content-type']).toBe('image/png');
// check headers
expect(response.headers()).toHaveProperty('content-length');
expect(response.headers()['content-length']).toBe('355'); // Transparent
expect(response.headers()).toHaveProperty('date');
expect(response.headers()).toHaveProperty('expires');
let tileDate = new Date(response.headers()['date'])
let tileExpires = new Date(response.headers()['expires'])
expect(tileExpires > tileDate).toBeTruthy();

params = new URLSearchParams({
repository: 'testsrepository',
project: 'cache',
SERVICE: 'WMTS',
VERSION: '1.0.0',
REQUEST: 'GetTile',
LAYER: 'Quartiers',
STYLE: 'default',
TILEMATRIXSET: 'EPSG:3857',
TILEMATRIX: '13',
TILEROW: '2991',
TILECOL: '4184',
FORMAT: 'image/png',
});
url = `/index.php/lizmap/service?${params}`;
response = await request.get(url, {});
// check response
await expect(response).toBeOK();
expect(response.status()).toBe(200);
// check content-type header
expect(response.headers()['content-type']).toBe('image/png');
// check headers
expect(response.headers()).toHaveProperty('content-length');
let contentLength = Number(response.headers()['content-length']);
expect(contentLength).toBeGreaterThan(355); // Not transparent
expect(contentLength).toBeGreaterThan(11000); // 11019
expect(contentLength).toBeLessThan(11100); // 11019
expect(response.headers()).toHaveProperty('date');
expect(response.headers()).toHaveProperty('expires');
tileDate = new Date(response.headers()['date'])
tileExpires = new Date(response.headers()['expires'])
expect(tileExpires > tileDate).toBeTruthy();

params = new URLSearchParams({
repository: 'testsrepository',
project: 'cache',
SERVICE: 'WMTS',
VERSION: '1.0.0',
REQUEST: 'GetTile',
LAYER: 'Quartiers',
STYLE: 'default',
TILEMATRIXSET: 'EPSG:3857',
TILEMATRIX: '15',
TILEROW: '11964',
TILECOL: '16736',
FORMAT: 'image/png',
});
url = `/index.php/lizmap/service?${params}`;
response = await request.get(url, {});
// check response
await expect(response).toBeOK();
expect(response.status()).toBe(200);
// check content-type header
expect(response.headers()['content-type']).toBe('image/png');
// check headers
expect(response.headers()).toHaveProperty('content-length');
contentLength = Number(response.headers()['content-length']);
expect(contentLength).toBeGreaterThan(355); // Not transparent
expect(contentLength).toBeGreaterThan(650); // 687
expect(contentLength).toBeLessThan(700); // 687
expect(response.headers()).toHaveProperty('date');
expect(response.headers()).toHaveProperty('expires');
tileDate = new Date(response.headers()['date'])
tileExpires = new Date(response.headers()['expires'])
expect(tileExpires > tileDate).toBeTruthy();
})
})
40 changes: 40 additions & 0 deletions tests/units/classes/Project/Qgis/LayerTreeGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,46 @@ public function testConstruct(): void
$this->assertEquals('publicbuildings_tramstop', $treeGroup->items[1]->name);
}

public function testShortName(): void
{

$xmlStr = '
<layer-tree-group checked="Qt::Unchecked" expanded="1" name="overview">
<customproperties>
<Option type="Map">
<Option name="wmsShortName" type="QString" value="Overview"></Option>
</Option>
</customproperties>
<layer-tree-layer expanded="1" patch_size="-1,-1" providerKey="" legend_split_behavior="0" id="quartiers_c6fea644_09fc_4f73_b4e8_201a2cc9f131" name="quartiers_overview" checked="Qt::Unchecked" source="service=\'lizmapdb\' sslmode=prefer key=\'quartier\' estimatedmetadata=true srid=4326 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table=&quot;tests_projects&quot;.&quot;quartiers&quot; (geom)" legend_exp="">
<customproperties>
<Option></Option>
</customproperties>
</layer-tree-layer>
</layer-tree-group>
';
$oXml = App\XmlTools::xmlReaderFromString($xmlStr);
$treeGroup = Qgis\LayerTreeGroup::fromXmlReader($oXml);
$this->assertEquals(null, $treeGroup->shortname);
$this->assertEquals('Overview', $treeGroup->customproperties['wmsShortName']);

$xmlStr = '
<layer-tree-group expanded="1" name="overview" checked="Qt::Unchecked" groupLayer="">
<customproperties>
<Option/>
</customproperties>
<shortname>Overview</shortname>
<layer-tree-layer expanded="1" patch_size="-1,-1" providerKey="" legend_split_behavior="0" id="quartiers_c6fea644_09fc_4f73_b4e8_201a2cc9f131" name="quartiers_overview" checked="Qt::Unchecked" source="service=\'lizmapdb\' sslmode=prefer key=\'quartier\' estimatedmetadata=true srid=4326 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table=&quot;tests_projects&quot;.&quot;quartiers&quot; (geom)" legend_exp="">
<customproperties>
<Option/>
</customproperties>
</layer-tree-layer>
</layer-tree-group>
';
$oXml = App\XmlTools::xmlReaderFromString($xmlStr);
$treeGroup = Qgis\LayerTreeGroup::fromXmlReader($oXml);
$this->assertEquals('Overview', $treeGroup->shortname);
}

public function testEmpty(): void
{
$xmlStr = '
Expand Down
Loading