Commit 1169a647 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Report check tests, drop very old TU directory

Fix entities tests

Drop duplicated lines

Wrong comment
parent 4a346968
......@@ -329,4 +329,419 @@ class CommonDBTM extends DbTestCase {
$this->boolean($res)->isTrue();
}
/**
* Check right on Recursive object
*
* @return void
*/
public function testRecursiveObjectChecks() {
$this->login();
$ent0 = getItemByTypeName('Entity', '_test_root_entity', true);
$ent1 = getItemByTypeName('Entity', '_test_child_1', true);
$ent2 = getItemByTypeName('Entity', '_test_child_2', true);
$printer = new \Printer();
$id[0] = (int)$printer->add([
'name' => "Printer 1",
'entities_id' => $ent0,
'is_recursive' => 0
]);
$this->integer($id[0])->isGreaterThan(0);
$id[1] = (int)$printer->add([
'name' => "Printer 2",
'entities_id' => $ent0,
'is_recursive' => 1
]);
$this->integer($id[1])->isGreaterThan(0);
$id[2] = (int)$printer->add([
'name' => "Printer 3",
'entities_id' => $ent1,
'is_recursive' => 1
]);
$this->integer($id[2])->isGreaterThan(0);
$id[3] = (int)$printer->add([
'name' => "Printer 4",
'entities_id' => $ent2
]);
$this->integer($id[3])->isGreaterThan(0);
// Super admin
$this->login('glpi', 'glpi');
$this->variable($_SESSION['glpiactiveprofile']['id'])->isEqualTo(4);
$this->variable($_SESSION['glpiactiveprofile']['printer'])->isEqualTo(255);
// See all
$this->boolean(\Session::changeActiveEntities('all'))->isTrue();
$this->boolean($printer->can($id[0], READ))->isTrue("Fail can read Printer 1");
$this->boolean($printer->can($id[1], READ))->isTrue("Fail can read Printer 2");
$this->boolean($printer->can($id[2], READ))->isTrue("Fail can read Printer 3");
$this->boolean($printer->can($id[3], READ))->isTrue("Fail can read Printer 4");
$this->boolean($printer->canEdit($id[0]))->isTrue("Fail can write Printer 1");
$this->boolean($printer->canEdit($id[1]))->isTrue("Fail can write Printer 2");
$this->boolean($printer->canEdit($id[2]))->isTrue("Fail can write Printer 3");
$this->boolean($printer->canEdit($id[3]))->isTrue("Fail can write Printer 4");
// See only in main entity
$this->boolean(\Session::changeActiveEntities($ent0))->isTrue();
$this->boolean($printer->can($id[0], READ))->isTrue("Fail can read Printer 1");
$this->boolean($printer->can($id[1], READ))->isTrue("Fail can read Printer 2");
$this->boolean($printer->can($id[2], READ))->isFalse("Fail can't read Printer 3");
$this->boolean($printer->can($id[3], READ))->isFalse("Fail can't read Printer 1");
$this->boolean($printer->canEdit($id[0]))->isTrue("Fail can write Printer 1");
$this->boolean($printer->canEdit($id[1]))->isTrue("Fail can write Printer 2");
$this->boolean($printer->canEdit($id[2]))->isFalse("Fail can't write Printer 1");
$this->boolean($printer->canEdit($id[3]))->isFalse("Fail can't write Printer 1");
// See only in child entity 1 + parent if recursive
$this->boolean(\Session::changeActiveEntities($ent1))->isTrue();
$this->boolean($printer->can($id[0], READ))->isFalse("Fail can't read Printer 1");
$this->boolean($printer->can($id[1], READ))->isTrue("Fail can read Printer 2");
$this->boolean($printer->can($id[2], READ))->isTrue("Fail can read Printer 3");
$this->boolean($printer->can($id[3], READ))->isFalse("Fail can't read Printer 4");
$this->boolean($printer->canEdit($id[0]))->isFalse("Fail can't write Printer 1");
$this->boolean($printer->canEdit($id[1]))->isFalse("Fail can't write Printer 2");
$this->boolean($printer->canEdit($id[2]))->isTrue("Fail can write Printer 2");
$this->boolean($printer->canEdit($id[3]))->isFalse("Fail can't write Printer 2");
// See only in child entity 2 + parent if recursive
$this->boolean(\Session::changeActiveEntities($ent2))->isTrue();
$this->boolean($printer->can($id[0], READ))->isFalse("Fail can't read Printer 1");
$this->boolean($printer->can($id[1], READ))->isTrue("Fail can read Printer 2");
$this->boolean($printer->can($id[2], READ))->isFalse("Fail can't read Printer 3");
$this->boolean($printer->can($id[3], READ))->isTrue("Fail can read Printer 4");
$this->boolean($printer->canEdit($id[0]))->isFalse("Fail can't write Printer 1");
$this->boolean($printer->canEdit($id[1]))->isFalse("Fail can't write Printer 2");
$this->boolean($printer->canEdit($id[2]))->isFalse("Fail can't write Printer 3");
$this->boolean($printer->canEdit($id[3]))->isTrue("Fail can write Printer 4");
}
/**
* Check right on CommonDBRelation object
*/
public function testContact_Supplier() {
$ent0 = getItemByTypeName('Entity', '_test_root_entity', true);
$ent1 = getItemByTypeName('Entity', '_test_child_1', true);
$ent2 = getItemByTypeName('Entity', '_test_child_2', true);
// Super admin
$this->login('glpi', 'glpi');
$this->variable($_SESSION['glpiactiveprofile']['id'])->isEqualTo(4);
$this->variable($_SESSION['glpiactiveprofile']['contact_enterprise'])->isEqualTo(255);
// See all
$this->boolean(\Session::changeActiveEntities('all'))->isTrue();
// Create some contacts
$contact = new \Contact();
$idc[0] = (int)$contact->add([
'name' => "Contact 1",
'entities_id' => $ent0,
'is_recursive' => 0
]);
$this->integer($idc[0])->isGreaterThan(0);
$idc[1] = (int)$contact->add([
'name' => "Contact 2",
'entities_id' => $ent0,
'is_recursive' => 1
]);
$this->integer($idc[1])->isGreaterThan(0);
$idc[2] = (int)$contact->add([
'name' => "Contact 3",
'entities_id' => $ent1,
'is_recursive' => 1
]);
$this->integer($idc[2])->isGreaterThan(0);
$idc[3] = (int)$contact->add([
'name' => "Contact 4",
'entities_id' => $ent2]);
$this->integer($idc[3])->isGreaterThan(0);;
// Create some suppliers
$supplier = new \Supplier();
$ids[0] = (int)$supplier->add([
'name' => "Supplier 1",
'entities_id' => $ent0,
'is_recursive' => 0
]);
$this->integer($ids[0])->isGreaterThan(0);
$ids[1] = (int)$supplier->add([
'name' => "Supplier 2",
'entities_id' => $ent0,
'is_recursive' => 1
]);
$this->integer($ids[1])->isGreaterThan(0);
$ids[2] = (int)$supplier->add([
'name' => "Supplier 3",
'entities_id' => $ent1
]);
$this->integer($ids[2])->isGreaterThan(0);
$ids[3] = (int)$supplier->add([
'name' => "Supplier 4",
'entities_id' => $ent2
]);
$this->integer($ids[3])->isGreaterThan(0);
// Relation
$rel = new \Contact_Supplier();
$input = [
'contacts_id' => $idc[0], // root
'suppliers_id' => $ids[0] //root
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[0] = (int)$rel->add($input);
$this->integer($idr[0])->isGreaterThan(0);
$this->boolean($rel->can($idr[0], READ))->isTrue();
$this->boolean($rel->canEdit($idr[0]))->isTrue();
$input = [
'contacts_id' => $idc[0], // root
'suppliers_id' => $ids[1] // root + rec
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[1] = (int)$rel->add($input);
$this->integer($idr[1])->isGreaterThan(0);
$this->boolean($rel->can($idr[1], READ))->isTrue();
$this->boolean($rel->canEdit($idr[1]))->isTrue();
$input = [
'contacts_id' => $idc[0], // root
'suppliers_id' => $ids[2] // child 1
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[0], // root
'suppliers_id' => $ids[3] // child 2
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[1], // root + rec
'suppliers_id' => $ids[0] // root
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[2] = (int)$rel->add($input);
$this->integer($idr[2])->isGreaterThan(0);
$this->boolean($rel->can($idr[2], READ))->isTrue();
$this->boolean($rel->canEdit($idr[2]))->isTrue();
$input = [
'contacts_id' => $idc[1], // root + rec
'suppliers_id' => $ids[1] // root + rec
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[3] = (int)$rel->add($input);
$this->integer($idr[3])->isGreaterThan(0);
$this->boolean($rel->can($idr[3], READ))->isTrue();
$this->boolean($rel->canEdit($idr[3]))->isTrue();
$input = [
'contacts_id' => $idc[1], // root + rec
'suppliers_id' => $ids[2] // child 1
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[4] = (int)$rel->add($input);
$this->integer($idr[4])->isGreaterThan(0);
$this->boolean($rel->can($idr[4], READ))->isTrue();
$this->boolean($rel->canEdit($idr[4]))->isTrue();
$input = [
'contacts_id' => $idc[1], // root + rec
'suppliers_id' => $ids[3] // child 2
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[5] = (int)$rel->add($input);
$this->integer($idr[5])->isGreaterThan(0);
$this->boolean($rel->can($idr[5], READ))->isTrue();
$this->boolean($rel->canEdit($idr[5]))->isTrue();
$input = [
'contacts_id' => $idc[2], // Child 1
'suppliers_id' => $ids[0] // root
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[2], // Child 1
'suppliers_id' => $ids[1] // root + rec
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[6] = (int)$rel->add($input);
$this->integer($idr[6])->isGreaterThan(0);
$this->boolean($rel->can($idr[6], READ))->isTrue();
$this->boolean($rel->canEdit($idr[6]))->isTrue();
$input = [
'contacts_id' => $idc[2], // Child 1
'suppliers_id' => $ids[2] // Child 1
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[7] = (int)$rel->add($input);
$this->integer($idr[7])->isGreaterThan(0);
$this->boolean($rel->can($idr[7], READ))->isTrue();
$this->boolean($rel->canEdit($idr[7]))->isTrue();
$input = [
'contacts_id' => $idc[2], // Child 1
'suppliers_id' => $ids[3] // Child 2
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
// See only in child entity 2 + parent if recursive
$this->boolean(\Session::changeActiveEntities($ent2))->isTrue();
$this->boolean($rel->can($idr[0], READ))->isFalse(); // root / root
//$this->boolean($rel->canEdit($idr[0]))->isFalse();
$this->boolean($rel->can($idr[1], READ))->isFalse(); // root / root rec
//$this->boolean($rel->canEdit($idr[1]))->isFalse();
$this->boolean($rel->can($idr[2], READ))->isFalse(); // root rec / root
//$this->boolean($rel->canEdit($idr[2]))->isFalse();
$this->boolean($rel->can($idr[3], READ))->isTrue(); // root rec / root rec
//$this->boolean($rel->canEdit($idr[3]))->isFalse();
$this->boolean($rel->can($idr[4], READ))->isFalse(); // root rec / child 1
//$this->boolean($rel->canEdit($idr[4]))->isFalse();
$this->boolean($rel->can($idr[5], READ))->isTrue(); // root rec / child 2
$this->boolean($rel->canEdit($idr[5]))->isTrue();
$this->boolean($rel->can($idr[6], READ))->isFalse(); // child 1 / root rec
//$this->boolean($rel->canEdit($idr[6]))->isFalse();
$this->boolean($rel->can($idr[7], READ))->isFalse(); // child 1 / child 1
//$this->boolean($rel->canEdit($idr[7]))->isFalse();
$input = [
'contacts_id' => $idc[0], // root
'suppliers_id' => $ids[0] // root
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[0],// root
'suppliers_id' => $ids[1] // root + rec
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[1],// root + rec
'suppliers_id' => $ids[0] // root
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[3], // Child 2
'suppliers_id' => $ids[0] // root
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[3],// Child 2
'suppliers_id' => $ids[1] // root + rec
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[7] = (int)$rel->add($input);
$this->integer($idr[7])->isGreaterThan(0);
$this->boolean($rel->can($idr[7], READ))->isTrue();
$this->boolean($rel->canEdit($idr[7]))->isTrue();
$input = [
'contacts_id' => $idc[3], // Child 2
'suppliers_id' => $ids[2] // Child 1
];
$this->boolean($rel->can(-1, CREATE, $input))->isFalse();
$input = [
'contacts_id' => $idc[3], // Child 2
'suppliers_id' => $ids[3] // Child 2
];
$this->boolean($rel->can(-1, CREATE, $input))->isTrue();
$idr[8] = (int)$rel->add($input);
$this->integer($idr[8])->isGreaterThan(0);
$this->boolean($rel->can($idr[8], READ))->isTrue();
$this->boolean($rel->canEdit($idr[8]))->isTrue();
}
/**
* Entity right check
*/
public function testEntity() {
$this->login();
$ent0 = getItemByTypeName('Entity', '_test_root_entity', true);
$ent1 = getItemByTypeName('Entity', '_test_child_1', true);
$ent2 = getItemByTypeName('Entity', '_test_child_2', true);
$entity = new \Entity();
$ent3 = (int)$entity->add([
'name' => '_test_child_2_subchild_1',
'entities_id' => $ent2
]);
$this->integer($ent3)->isGreaterThan(0);
$ent4 = (int)$entity->add([
'name' => '_test_child_2_subchild_2',
'entities_id' => $ent2
]);
$this->integer($ent4)->isGreaterThan(0);
$this->boolean(\Session::changeActiveEntities('all'))->isTrue();
$this->boolean($entity->can(0, READ))->isTrue("Fail: can't read root entity");
$this->boolean($entity->can($ent0, READ))->isTrue("Fail: can't read entity 0");
$this->boolean($entity->can($ent1, READ))->isTrue("Fail: can't read entity 1");
$this->boolean($entity->can($ent2, READ))->isTrue("Fail: can't read entity 2");
$this->boolean($entity->can($ent3, READ))->isTrue("Fail: can't read entity 2.1");
$this->boolean($entity->can($ent4, READ))->isTrue("Fail: can't read entity 2.2");
$this->boolean($entity->can(99999, READ))->isFalse("Fail: can read not existing entity");
$this->boolean($entity->canEdit(0))->isTrue("Fail: can't write root entity");
$this->boolean($entity->canEdit($ent0))->isTrue("Fail: can't write entity 0");
$this->boolean($entity->canEdit($ent1))->isTrue("Fail: can't write entity 1");
$this->boolean($entity->canEdit($ent2))->isTrue("Fail: can't write entity 2");
$this->boolean($entity->canEdit($ent3))->isTrue("Fail: can't write entity 2.1");
$this->boolean($entity->canEdit($ent4))->isTrue("Fail: can't write entity 2.2");
$this->boolean($entity->canEdit(99999))->isFalse("Fail: can write not existing entity");
$input=['entities_id' => $ent1];
$this->boolean($entity->can(-1, CREATE, $input))->isTrue("Fail: can create entity in root");
$input=['entities_id' => $ent2];
$this->boolean($entity->can(-1, CREATE, $input))->isTrue("Fail: can't create entity in 2");
$input=['entities_id' => $ent3];
$this->boolean($entity->can(-1, CREATE, $input))->isTrue("Fail: can't create entity in 2.1");
$input=['entities_id' => 99999];
$this->boolean($entity->can(-1, CREATE, $input))->isFalse("Fail: can create entity in not existing entity");
$input=['entities_id' => -1];
$this->boolean($entity->can(-1, CREATE, $input))->isFalse("Fail: can create entity in not existing entity");
$this->boolean(\Session::changeActiveEntities($ent2, false))->isTrue();
$input=['entities_id' => $ent1];
$this->boolean($entity->can(-1, CREATE, $input))->isFalse("Fail: can create entity in root");
$input=['entities_id' => $ent2];
// next should be false (or not).... but check is done on glpiactiveprofile
// will require to save current state in session - this is probably acceptable
// this allow creation when no child defined yet (no way to select tree in this case)
$this->boolean($entity->can(-1, CREATE, $input))->isTrue("Fail: can't create entity in 2");
$input=['entities_id' => $ent3];
$this->boolean($entity->can(-1, CREATE, $input))->isFalse("Fail: can create entity in 2.1");
}
}
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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 2 of the License, or
* (at your option) any later version.
*
* GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', realpath('../..'));
}
include_once (GLPI_ROOT . "/inc/autoload.function.php");
include_once (GLPI_ROOT . "/inc/db.function.php");
include_once (GLPI_CONFIG_DIR . "/config_db.php");
Config::detectRootDoc();
include_once (GLPI_ROOT . "/inc/config.php");
if (is_writable(GLPI_SESSION_DIR)) {
Session::setPath();
} else {
die("Can't write in ".GLPI_SESSION_DIR."\n");
}
Session::start();
// Init debug variable
Toolbox::setDebugMode(Session::DEBUG_MODE, 0, 0, 1);
$_SESSION['glpilanguage'] = 'en_GB';
Session::loadLanguage();
$DB = new DB();
if (!$DB->connected) {
die("No DB connection\n");
}
require_once 'System/AllTests.php';
require_once 'Install/AllTests.php';
require_once 'Framework/AllTests.php';
class AllTests {
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('GLPI');
$suite->addTest(System_AllTests::suite());
$suite->addTest(Install_AllTests::suite());
// $suite->addTest(Framework_AllTests::suite());
return $suite;
}
}
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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 2 of the License, or
* (at your option) any later version.
*
* GLPI 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 GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
include_once ('Version.php');
include_once ('CommonDBTM/AllTests.php');
include_once ('Dropdown/AllTests.php');
class Framework_GLPI extends PHPUnit_Framework_TestSuite {
public $tables = [];
public $sharedFixture = [];
public static function suite() {
$suite = new Framework_GLPI('Framework_Version');
$suite->addTest(Framework_CommonDBTM_AllTests::suite());
// $suite->addTest(Framework_Dropdown_AllTests::suite());
return $suite;
}
protected function setUp() {
global $DB;
$DB->connect();
// Store Max(id) for each glpi tables
$result = $DB->list_tables();
while ($data=$DB->fetch_row($result)) {
$query = "SELECT MAX(`id`) AS MAXID
FROM `".$data[0]."`";
foreach ($DB->request($query) as $row) {
$this->tables[$data[0]] = (empty($row['MAXID']) ? 0 : $row['MAXID']);
}
}
$DB->free_result($result);
$tab = [];
$auth = new Auth();
// First session
$auth->login('glpi', 'glpi');
// Create entity tree
$entity = new Entity();
$tab['entity'][0] = $entity->add(['name' => 'PHP Unit root',
'entities_id' => 0]);
if (!$tab['entity'][0] // Crash detection
|| !FieldExists('glpi_profiles', 'notification') // Schema detection
|| countElementsInTable('glpi_rules')!=6) { // Old rules
if (!$tab['entity'][0]) {
echo "Couldn't run test (previous run not cleaned)\n";
} else {
echo "Schema need to be updated\n";
}
echo "Loading a fresh empty database:";
$DB->runFile(GLPI_ROOT ."/install/mysql/glpi-0.84-empty.sql");
die(" done\nTry again\n");
}
$tab['entity'][1] = $entity->add(['name' => 'PHP Unit Child 1',
'entities_id' => $tab['entity'][0]]);
$tab['entity'][2] = $entity->add(['name' => 'PHP Unit Child 2',
'entities_id' => $tab['entity'][0]]);
$tab['entity'][3] = $entity->add(['name' => 'PHP Unit Child 2.1',
'entities_id' => $tab['entity'][2]]);
$tab['entity'][4] = $entity->add(['name' => 'PHP Unit Child 2.2',
'entities_id' => $tab['entity'][2]]);
// New session with all the entities
$auth->login('glpi', 'glpi') or die("Login glpi/glpi invalid !\n");
// Shared this with all tests
$this->sharedFixture = $tab;
}
//
//
// protected function tearDown() {
// global $DB;
//
// $DB->connect();
//