|
| 1 | +// @ts-check |
| 2 | +import { test, expect } from '@playwright/test'; |
| 3 | + |
| 4 | +test.describe('WMTS Requests @requests @readonly', () => { |
| 5 | + test('WMTS Getcapabilities', async({ request }) => { |
| 6 | + let params = new URLSearchParams({ |
| 7 | + repository: 'testsrepository', |
| 8 | + project: 'cache', |
| 9 | + SERVICE: 'WMTS', |
| 10 | + VERSION: '1.0.0', |
| 11 | + REQUEST: 'GetCapabilities', |
| 12 | + }); |
| 13 | + let url = `/index.php/lizmap/service?${params}`; |
| 14 | + let response = await request.get(url, {}); |
| 15 | + // check response |
| 16 | + expect(response.ok()).toBeTruthy(); |
| 17 | + expect(response.status()).toBe(200); |
| 18 | + // check content-type header |
| 19 | + expect(response.headers()['content-type']).toBe('text/xml; charset=utf-8'); |
| 20 | + // check headers |
| 21 | + expect(response.headers()).toHaveProperty('cache-control'); |
| 22 | + expect(response.headers()['cache-control']).toBe('no-cache'); |
| 23 | + expect(response.headers()).toHaveProperty('etag'); |
| 24 | + const etag = response.headers()['etag']; |
| 25 | + expect(etag).not.toBe(''); |
| 26 | + expect(etag).toHaveLength(43); |
| 27 | + |
| 28 | + // check body |
| 29 | + let body = await response.text(); |
| 30 | + expect(body).toContain('Capabilities'); |
| 31 | + expect(body).toContain('version="1.0.0"'); |
| 32 | + expect(body).toContain('xmlns="http://www.opengis.net/wmts/1.0"'); |
| 33 | + expect(body).toContain('<ows:Identifier>Quartiers</ows:Identifier>'); |
| 34 | + expect(body).toContain('<TileMatrixSet>EPSG:3857</TileMatrixSet>'); |
| 35 | + |
| 36 | + // GET request with the etag |
| 37 | + response = await request.get(url, { |
| 38 | + headers: { |
| 39 | + 'If-None-Match': etag |
| 40 | + } |
| 41 | + }); |
| 42 | + await expect(response).not.toBeOK(); |
| 43 | + expect(response.status()).toBe(304); |
| 44 | + }) |
| 45 | + |
| 46 | + test('WMTS GetTile', async({ request }) => { |
| 47 | + let params = new URLSearchParams({ |
| 48 | + repository: 'testsrepository', |
| 49 | + project: 'cache', |
| 50 | + SERVICE: 'WMTS', |
| 51 | + VERSION: '1.0.0', |
| 52 | + REQUEST: 'GetTile', |
| 53 | + LAYER: 'Quartiers', |
| 54 | + STYLE: 'default', |
| 55 | + TILEMATRIXSET: 'EPSG:3857', |
| 56 | + TILEMATRIX: '13', |
| 57 | + TILEROW: '2989', |
| 58 | + TILECOL: '4185', |
| 59 | + FORMAT: 'image/png', |
| 60 | + }); |
| 61 | + let url = `/index.php/lizmap/service?${params}`; |
| 62 | + let response = await request.get(url, {}); |
| 63 | + // check response |
| 64 | + await expect(response).toBeOK(); |
| 65 | + expect(response.status()).toBe(200); |
| 66 | + // check content-type header |
| 67 | + expect(response.headers()['content-type']).toBe('image/png'); |
| 68 | + // check headers |
| 69 | + expect(response.headers()).toHaveProperty('content-length'); |
| 70 | + expect(response.headers()['content-length']).toBe('355'); // Transparent |
| 71 | + expect(response.headers()).toHaveProperty('date'); |
| 72 | + expect(response.headers()).toHaveProperty('expires'); |
| 73 | + let tileDate = new Date(response.headers()['date']) |
| 74 | + let tileExpires = new Date(response.headers()['expires']) |
| 75 | + expect(tileExpires > tileDate).toBeTruthy(); |
| 76 | + |
| 77 | + params = new URLSearchParams({ |
| 78 | + repository: 'testsrepository', |
| 79 | + project: 'cache', |
| 80 | + SERVICE: 'WMTS', |
| 81 | + VERSION: '1.0.0', |
| 82 | + REQUEST: 'GetTile', |
| 83 | + LAYER: 'Quartiers', |
| 84 | + STYLE: 'default', |
| 85 | + TILEMATRIXSET: 'EPSG:3857', |
| 86 | + TILEMATRIX: '13', |
| 87 | + TILEROW: '2991', |
| 88 | + TILECOL: '4184', |
| 89 | + FORMAT: 'image/png', |
| 90 | + }); |
| 91 | + url = `/index.php/lizmap/service?${params}`; |
| 92 | + response = await request.get(url, {}); |
| 93 | + // check response |
| 94 | + await expect(response).toBeOK(); |
| 95 | + expect(response.status()).toBe(200); |
| 96 | + // check content-type header |
| 97 | + expect(response.headers()['content-type']).toBe('image/png'); |
| 98 | + // check headers |
| 99 | + expect(response.headers()).toHaveProperty('content-length'); |
| 100 | + let contentLength = Number(response.headers()['content-length']); |
| 101 | + expect(contentLength).toBeGreaterThan(355); // Not transparent |
| 102 | + expect(contentLength).toBeGreaterThan(11000); // 11019 |
| 103 | + expect(contentLength).toBeLessThan(11100); // 11019 |
| 104 | + expect(response.headers()).toHaveProperty('date'); |
| 105 | + expect(response.headers()).toHaveProperty('expires'); |
| 106 | + tileDate = new Date(response.headers()['date']) |
| 107 | + tileExpires = new Date(response.headers()['expires']) |
| 108 | + expect(tileExpires > tileDate).toBeTruthy(); |
| 109 | + |
| 110 | + params = new URLSearchParams({ |
| 111 | + repository: 'testsrepository', |
| 112 | + project: 'cache', |
| 113 | + SERVICE: 'WMTS', |
| 114 | + VERSION: '1.0.0', |
| 115 | + REQUEST: 'GetTile', |
| 116 | + LAYER: 'Quartiers', |
| 117 | + STYLE: 'default', |
| 118 | + TILEMATRIXSET: 'EPSG:3857', |
| 119 | + TILEMATRIX: '15', |
| 120 | + TILEROW: '11964', |
| 121 | + TILECOL: '16736', |
| 122 | + FORMAT: 'image/png', |
| 123 | + }); |
| 124 | + url = `/index.php/lizmap/service?${params}`; |
| 125 | + response = await request.get(url, {}); |
| 126 | + // check response |
| 127 | + await expect(response).toBeOK(); |
| 128 | + expect(response.status()).toBe(200); |
| 129 | + // check content-type header |
| 130 | + expect(response.headers()['content-type']).toBe('image/png'); |
| 131 | + // check headers |
| 132 | + expect(response.headers()).toHaveProperty('content-length'); |
| 133 | + contentLength = Number(response.headers()['content-length']); |
| 134 | + expect(contentLength).toBeGreaterThan(355); // Not transparent |
| 135 | + expect(contentLength).toBeGreaterThan(650); // 687 |
| 136 | + expect(contentLength).toBeLessThan(700); // 687 |
| 137 | + expect(response.headers()).toHaveProperty('date'); |
| 138 | + expect(response.headers()).toHaveProperty('expires'); |
| 139 | + tileDate = new Date(response.headers()['date']) |
| 140 | + tileExpires = new Date(response.headers()['expires']) |
| 141 | + expect(tileExpires > tileDate).toBeTruthy(); |
| 142 | + }) |
| 143 | +}) |
0 commit comments