Skip to content

Commit

Permalink
fix null xml QgisProject property
Browse files Browse the repository at this point in the history
  • Loading branch information
mind84 committed Dec 5, 2024
1 parent 3cfc638 commit 49cd0cd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
18 changes: 9 additions & 9 deletions lizmap/modules/lizmap/lib/Project/QgisProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public function findLayersByKeyword($key, $proj)
*/
public function xpathQuery($query)
{
$ret = $this->xml->xpath($query);
$ret = $this->getXml()->xpath($query);
if ($ret && is_array($ret)) {
return $ret;
}
Expand Down Expand Up @@ -702,7 +702,7 @@ public function getXmlLayer($layerId)
*/
protected function getXml()
{
if ($this->xml) {
if ($this->xml != null) {
return $this->xml;
}
$qgs_path = $this->path;
Expand Down Expand Up @@ -768,7 +768,7 @@ public function getPrintTemplates()
{
// get restricted composers
$rComposers = array();
$restrictedComposers = $this->xml->xpath('//properties/WMSRestrictedComposers/value');
$restrictedComposers = $this->getXml()->xpath('//properties/WMSRestrictedComposers/value');
if ($restrictedComposers && is_array($restrictedComposers)) {
foreach ($restrictedComposers as $restrictedComposer) {
$rComposers[] = (string) $restrictedComposer;
Expand All @@ -777,7 +777,7 @@ public function getPrintTemplates()

$printTemplates = array();
// get layout qgs project version >= 3
$layouts = $this->xml->xpath('//Layout');
$layouts = $this->getXml()->xpath('//Layout');
if ($layouts && is_array($layouts)) {
foreach ($layouts as $layout) {
// test restriction
Expand Down Expand Up @@ -893,7 +893,7 @@ public function readLocateByLayer($locateByLayer)
}
// update locateByLayer with alias and filter information
foreach ($locateByLayer as $k => $v) {
$xmlLayer = $this->getXmlLayer2($this->xml, $v->layerId);
$xmlLayer = $this->getXmlLayer2($this->getXml(), $v->layerId);
if (is_null($xmlLayer)) {
continue;
}
Expand Down Expand Up @@ -953,7 +953,7 @@ public function readEditionLayers($editionLayers)
if ($qgisProject) {
$xml = $qgisProject->getXml();
} else {
$xml = $this->xml;
$xml = $this->getXml();
}

// Read layer property from QGIS project XML
Expand Down Expand Up @@ -982,7 +982,7 @@ public function readEditionForms($editionLayers, $proj)
if ($qgisProject) {
$xml = $qgisProject->getXml();
} else {
$xml = $this->xml;
$xml = $this->getXml();
}

$layerXml = $this->getXmlLayer2($xml, $obj->layerId);
Expand Down Expand Up @@ -1118,7 +1118,7 @@ public function readAttributeLayers($attributeLayers)
}

// Read layer property from QGIS project XML
$layerXml = $this->getXmlLayer2($this->xml, $obj->layerId);
$layerXml = $this->getXmlLayer2($this->getXml(), $obj->layerId);
if (is_null($layerXml)) {
continue;
}
Expand All @@ -1145,7 +1145,7 @@ public function readLayersOrder($xml, $layers)
{
$layersOrder = array();
if ($this->qgisProjectVersion >= 30000) { // For QGIS >=3.0, custom-order is in layer-tree-group
$customOrder = $this->xml->xpath('layer-tree-group/custom-order');
$customOrder = $this->getXml()->xpath('layer-tree-group/custom-order');
if (count($customOrder) == 0) {
return $layersOrder;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/units/classes/Project/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function testReadProject()
'layers' => array(),
);
$qgis_default = new QgisProjectForTests($data);
$qgis_default->setXml(new SimpleXMLElement('<root></root>'));
$qgis_default->setXmlForTest(new SimpleXMLElement('<root></root>'));
$this->assertNotNull($qgis_default->getXmlForTest());
$rep = new Project\Repository('key', array(), null, null, null);
$proj = new ProjectForTests();
$cfg = json_decode(file_get_contents(__DIR__.'/Ressources/readProject.qgs.cfg'));
Expand Down
8 changes: 4 additions & 4 deletions tests/units/classes/Project/QgisProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function testSetLayerOpacity()
$expectedLayer->local_raster_layer->opacity = (float) 0.6835;
$cfg = new Project\ProjectConfig((object) array('layers' => $json->layers));
$testProj = new qgisProjectForTests();
$testProj->setXml(simplexml_load_file(__DIR__.'/Ressources/opacity.qgs'));
$testProj->setXmlForTest(simplexml_load_file(__DIR__.'/Ressources/opacity.qgs'));
$layers = array(
array (
'id' => 'events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101',
Expand Down Expand Up @@ -521,7 +521,7 @@ public function testReadEditionLayers($fileName, $expectedELayer)
$file = __DIR__.'/Ressources/'.$fileName.'.qgs';
$eLayers = json_decode(file_get_contents($file.'.cfg'))->editionLayers;
$testProj = new qgisProjectForTests();
$testProj->setXml(simplexml_load_file($file));
$testProj->setXmlForTest(simplexml_load_file($file));
$testProj->readEditionLayersForTest($eLayers);
$this->assertEquals($expectedELayer, $eLayers);
}
Expand Down Expand Up @@ -734,7 +734,7 @@ public function testReadAttributeLayer()
$aLayer = json_decode(file_get_contents($file.'.cfg'))->attributeLayers;
$xml = simplexml_load_string($table);
$testProj = new qgisProjectForTests();
$testProj->setXml(simplexml_load_file($file));
$testProj->setXmlForTest(simplexml_load_file($file));
$testProj->readAttributeLayersForTest($aLayer);
$xml = json_decode(str_replace('@', '', json_encode($xml)));
$this->assertEquals($xml, $aLayer->montpellier_events->attributetableconfig);
Expand Down Expand Up @@ -768,7 +768,7 @@ public function testSetShortNames($file, $lname, $sname)
),
);
$testProj = new qgisProjectForTests();
$testProj->setXml(simplexml_load_file($file));
$testProj->setXmlForTest(simplexml_load_file($file));
$cfg = new Project\ProjectConfig((object) array('layers' => (object) $layers));
$testProj->setShortNamesForTest($cfg);
$layer = $cfg->getLayers();
Expand Down
7 changes: 6 additions & 1 deletion tests/units/testslib/QgisProjectForTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ public function setLayerOpacityForTest($cfg)
return $this->setLayerOpacity($cfg);
}

public function setXml($xml)
public function getXmlForTest()
{
return $this->getXml();
}

public function setXmlForTest($xml)
{
$this->xml = $xml;
}
Expand Down

0 comments on commit 49cd0cd

Please sign in to comment.