Skip to content

Commit

Permalink
Fix domain relation deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Dec 29, 2023
1 parent c04505d commit 45981f9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DomainRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function ($e) {

public function pre_deleteItem()
{
if (in_array([self::BELONGS, self::MANAGE], $this->fields['id'])) {
if (in_array($this->fields['id'], [self::BELONGS, self::MANAGE])) {
//keep defaults
return false;
}
Expand Down
58 changes: 58 additions & 0 deletions tests/functional/DomainRelation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2023 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

namespace tests\units;

use DbTestCase;

class DomainRelation extends DbTestCase
{
public function testDeleteProtectedRelations()
{
$this->login();

$relation = new \DomainRelation();
$this->integer($unprotected_id = $relation->add([
'name' => __FUNCTION__
]))->isGreaterThan(0);

// Should not be able to delete the domain relations added to GLPI by default
$this->boolean($relation->delete(['id' => \DomainRelation::BELONGS]))->isFalse();
$this->boolean($relation->delete(['id' => \DomainRelation::MANAGE]))->isFalse();

// Should be able to delete the domain relation added by the test
$this->boolean($relation->delete(['id' => $unprotected_id]))->isTrue();
}
}

0 comments on commit 45981f9

Please sign in to comment.