Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests on the landingpage with XPath and opacity #5080

Draft
wants to merge 2 commits into
base: release_3_8
Choose a base branch
from
Draft
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
28 changes: 8 additions & 20 deletions lizmap/modules/lizmap/lib/Project/QgisProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,29 +377,17 @@ protected function setShortNames(ProjectConfig $cfg)
*/
protected function setLayerOpacity(ProjectConfig $cfg)
{
$layers = $this->layers;
// loop through project layers to get embedded ones as well
foreach ($layers as $layer) {
$xpath = "//maplayer[id='{$layer['id']}']/layerOpacity[.!=1]/parent::* | //maplayer[id='{$layer['id']}']/pipe/rasterrenderer/@opacity[.!=1]/ancestor::maplayer";
$layerWithOpacity = null;

// check if layer is embedded or not
$qgisProject = $this->getEmbeddedQgisProject($layer['id']);

if ($qgisProject) {
$layerWithOpacity = $qgisProject->xpathQuery($xpath);
} else {
$layerWithOpacity = $this->xpathQuery($xpath);
}
if ($layerWithOpacity && count($layerWithOpacity) == 1) {
$name = (string) $layerWithOpacity[0]->layername;
$layerWithOpacities = $this->xpathQuery('//maplayer/layerOpacity[.!=1]/parent::* | //maplayer/pipe/rasterrenderer/@opacity[.!=1]/ancestor::maplayer');
if ($layerWithOpacities) {
foreach ($layerWithOpacities as $layerWithOpacity) {
$name = (string) $layerWithOpacity->layername;
$layerCfg = $cfg->getLayer($name);
$opacity = 1;
if ($layerCfg) {
if (isset($layerWithOpacity[0]->layerOpacity)) {
$opacity = (float) $layerWithOpacity[0]->layerOpacity;
} elseif (isset($layerWithOpacity[0]->pipe->rasterrenderer['opacity'])) {
$opacity = (float) $layerWithOpacity[0]->pipe->rasterrenderer['opacity'];
if (isset($layerWithOpacity->layerOpacity)) {
$opacity = (float) $layerWithOpacity->layerOpacity;
} elseif (isset($layerWithOpacity->pipe->rasterrenderer['opacity'])) {
$opacity = (float) $layerWithOpacity->pipe->rasterrenderer['opacity'];
}
$layerCfg->opacity = $opacity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Projects homepage', function () {
cy.get('.liz-repository-project-item:visible').its('length').as('totalProjects')
// Insert value in search input
cy.get('#search-project').type('nature')
// CHeck the number of title projects that contains the serach value
// Check the number of title projects that contains the search value
cy.get('.liz-repository-project-item:visible').should('length', 2)
// Clear the search input
cy.get('#search-project').clear()
Expand Down
43 changes: 0 additions & 43 deletions tests/units/classes/Project/QgisProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,51 +397,8 @@ public function testSetLayerOpacity()
$cfg = new Project\ProjectConfig((object) array('layers' => $json->layers));
$testProj = new qgisProjectForTests();
$testProj->setXml(simplexml_load_file(__DIR__.'/Ressources/opacity.qgs'));
$layers = array(
array (
'id' => 'events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101',
'name' => 'montpellier_events',
),
array (
'id' => 'raster_78572dfa_41b3_42da_a9c6_933ead8bad8f',
'name' => 'local_raster_layer',
),
);
$testProj->setLayers($layers);
$testProj->setLayerOpacityForTest($cfg);
$this->assertEquals($expectedLayer, $cfg->getLayers());

// embedded layers
$file = __DIR__.'/Ressources/opacity_embed.qgs';
$data = array(
'WMSInformation' => array(),
'layers' => array(),
);
$file = __DIR__.'/Ressources/opacity_embed.qgs';
$testProjE = new ProjectForTests();

$testQgis = new QgisProjectForTests($data);
$rep = new Project\Repository('key', array(), null, null, null);
$testQgis->setPath($file);
$testQgis->readXMLProjectTest($file);

$cfg = json_decode(file_get_contents($file.'.cfg'));
$config = new Project\ProjectConfig($cfg);

$testProjE->setCfg($config);
$testProjE->setQgis($testQgis);
$testProjE->setRepo($rep);
$testProjE->setKey('test');

$testQgis->setLayerOpacityForTest($config);

$emLayer = $testQgis->getLayer('_a5a62408_edf3_4c07_a266_0e8ae6642517', $testProjE);
$this->assertNotNull($emLayer);
$this->assertEquals($emLayer->getName(), 'Fabbricati');

$eLayerName = $emLayer->getName();
$this->assertNotNull($config->getLayer($eLayerName));
$this->assertEquals(0.4,$config->getLayer($eLayerName)->opacity);
}

public static function getLayerData()
Expand Down
1 change: 0 additions & 1 deletion tests/units/classes/Project/Ressources/opacity.qgs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<customproperties/>
<blendMode>0</blendMode>
<layername>montpellier_events</layername>
<id>events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101</id>
<featureBlendMode>0</featureBlendMode>
<layerOpacity>0.85</layerOpacity>
<geometryOptions geometryPrecision="0" removeDuplicateNodes="0">
Expand Down
768 changes: 0 additions & 768 deletions tests/units/classes/Project/Ressources/opacity_embed.qgs

This file was deleted.

219 changes: 0 additions & 219 deletions tests/units/classes/Project/Ressources/opacity_embed.qgs.cfg

This file was deleted.

Loading
Loading