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
This diff is collapsed.
<?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();
//
// $tot = 0;
// // Cleanup the object created by the suite
// foreach ($this->tables as $table => $maxid) {
// $query = "DELETE
// FROM `$table`
// WHERE `id` > ".$maxid;
// $res = $DB->query($query);
// $tot += $DB->affected_rows();
// }
// echo "\nCleanup of $tot records\n";
// }
}
class Framework_AllTests {
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('Framework');
$suite->addTest(Framework_GLPI::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/>.
* ---------------------------------------------------------------------
*/
require_once 'CanCheck.php';
require_once 'DeleteRestore.php';
class Framework_CommonDBTM_AllTests {
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('Framework_CommonDBTM_CanCheck');
// $suite->addTestSuite('Framework_CommonDBTM_DeleteRestore');
return $suite;
}
}
This diff is collapsed.
<?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/>.
* ---------------------------------------------------------------------
*/
class Framework_CommonDBTM_DeleteRestore extends PHPUnit_Framework_TestCase {
/**
* Check delete / purge on a pinter
*/
public function testPrinter() {
$printer = new Printer();
// Create
$id[0] = $printer->add(['name' => "Printer",
'entities_id' => 0,
'is_template' => 0]);
$this->assertGreaterThan(0, $id[0], "Fail to create Printer 1");
$this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Printer");
// Verify DB Schema have not change
$this->assertArrayHasKey('is_deleted', $printer->fields, "Fail: no is_deleted field");
$this->assertArrayHasKey('is_template', $printer->fields, "Fail: no is_template field");
$this->assertEquals(0, $printer->fields['is_deleted'], "Fail: is_deleted set");
$this->assertEquals(0, $printer->fields['is_template'], "Fail: is_template set");
// Delete
$this->assertTrue($printer->delete(['id'=>$id[0]]), "Fail: can't delete Printer");
$this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Printer");
$this->assertEquals(1, $printer->fields['is_deleted'], "Fail: is_deleted not set");
// Restore
$this->assertTrue($printer->restore(['id'=>$id[0]]), "Fail: can't restore Printer");
$this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Printer");
$this->assertEquals(0, $printer->fields['is_deleted'], "Fail: is_deleted set");
// Delete again
$this->assertTrue($printer->delete(['id'=>$id[0]]), "Fail: can't delete Printer");
$this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Printer");
$this->assertEquals(1, $printer->fields['is_deleted'], "Fail: is_deleted not set");
// Purge
$this->assertTrue($printer->delete(['id'=>$id[0]], 1), "Fail: to purge Printer");
$this->assertFalse($printer->getFromDB($id[0]), "Fail: can read Printer (purged)");
}
/**
* Check delete / purge on a template of printer
*/
public function testPrinterTemplate() {
$printer = new Printer();
// Create
$id[0] = $printer->add(['name' => "Printer 1",
'entities_id' => 0,
'is_template' => 1]);
$this->assertGreaterThan(0, $id[0], "Fail to create Printer Template");
$this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Template");
$this->assertEquals(0, $printer->fields['is_deleted'], "Fail: is_deleted set");
$this->assertEquals(1, $printer->fields['is_template'], "Fail: is_template not set");
// Delete (= purge)
$this->assertTrue($printer->delete(['id'=>$id[0]], 0), "Fail: can't delete Template");
$this->assertFalse($printer->getFromDB($id[0]), "Fail: can read Template (deleted)");
}
/**
* Check delete / purge on a Reminder (no is_template, no is_deleted)
*/
public function testReminder() {
$reminder = new Reminder();
// Create
$id[0] = $reminder->add(['name' => "Reminder",
'entities_id' => 0,
'users_id' => $_SESSION['glpiID']]);
$this->assertGreaterThan(0, $id[0], "Fail to create Reminder");
$this->assertTrue($reminder->getFromDB($id[0]), "Fail: can't read Reminder");
// Verify DB Schema have not change
$this->assertArrayNotHasKey('is_deleted', $reminder->fields, "Fail: is_deleted field");
$this->assertArrayNotHasKey('is_template', $reminder->fields, "Fail: is_template field");
// Delete (= purge)
$this->assertTrue($reminder->delete(['id'=>$id[0]]), "Fail: can't delete Reminder");
$this->assertFalse($reminder->getFromDB($id[0]), "Fail: can read Reminder (deleted)");
}
}
<?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/>.
* ---------------------------------------------------------------------
*/
require_once 'Import.php';
require_once 'TreeCache.php';
class Framework_Dropdown_AllTests {
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('Framework_Dropdown_Import');
$suite->addTestSuite('Framework_Dropdown_TreeCache');
return $suite;
}
}
This diff is collapsed.
<?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/>.
* ---------------------------------------------------------------------
*/
class Framework_Dropdown_TreeCache extends PHPUnit_Framework_TestCase {
/**
* sons / ancestors for Entity
*/
public function testEntity() {
$ent0 = $this->sharedFixture['entity'][0];
$ent1 = $this->sharedFixture['entity'][1];
$ent2 = $this->sharedFixture['entity'][2];
$ent3 = $this->sharedFixture['entity'][3];
$ent4 = $this->sharedFixture['entity'][4];
$parent = getAncestorsOf('glpi_entities', $ent0);
$this->assertEquals(1, count($parent));
$this->assertArrayHasKey(0, $parent);
$sons = getSonsOf('glpi_entities', $ent0);
$this->assertEquals(5, count($sons));
$this->assertArrayHasKey($ent0, $sons);
$this->assertArrayHasKey($ent1, $sons);
$this->assertArrayHasKey($ent2, $sons);
$this->assertArrayHasKey($ent3, $sons);
$this->assertArrayHasKey($ent4, $sons);
$parent = getAncestorsOf('glpi_entities', $ent1);
$this->assertEquals(2, count($parent));
$this->assertArrayHasKey(0, $parent);
$this->assertArrayHasKey($ent0, $parent);
$sons = getSonsOf('glpi_entities', $ent1);
$this->assertEquals(1, count($sons));
$this->assertArrayHasKey($ent1, $sons);
$sons = getSonsOf('glpi_entities', $ent2);
$this->assertEquals(3, count($sons));
$this->assertArrayHasKey($ent2, $sons);
$this->assertArrayHasKey($ent3, $sons);
$this->assertArrayHasKey($ent4, $sons);
$parent = getAncestorsOf('glpi_entities', $ent4);
$this->assertEquals(3, count($parent));
$this->assertArrayHasKey(0, $parent);
$this->assertArrayHasKey($ent0, $parent);
$this->assertArrayHasKey($ent2, $parent);
}
/**
* sons / ancestors for CommonTreeDropdown
*/
public function testTree() {
$entity = $this->sharedFixture['entity'][0];
$loc = new Location();
// A
$id[0] = $loc->add(['entities_id' => $entity,
'locations_id' => 0,
'name' => 'A']);
$this->assertGreaterThan(0, $id[0]);
// A > AA
$id[1] = $loc->add(['entities_id' => $entity,
'locations_id' => $id[0],
'name' => 'AA']);
$this->assertGreaterThan(0, $id[1]);
$this->assertTrue($loc->getFromDB($id[1]));
$this->assertEquals('A > AA', $loc->fields['completename']);
// A > BB
$id[2] = $loc->add(['entities_id' => $entity,
'locations_id' => $id[0],
'name' => 'BB']);
$this->assertGreaterThan(0, $id[2]);
$this->assertTrue($loc->getFromDB($id[2]));
$this->assertEquals('A > BB', $loc->fields['completename']);
// Sons of A (A, AA, BB)
$sons = getSonsOf('glpi_locations', $id[0]);
$this->assertEquals(3, count($sons));
$this->assertArrayHasKey($id[0], $sons);
$this->assertArrayHasKey($id[1], $sons);
$this->assertArrayHasKey($id[2], $sons);
// Ancestors of A (none)
$parent = getAncestorsOf('glpi_locations', $id[0]);
$this->assertEquals(0, count($parent));
// Ancestors of AA (A)
$parent = getAncestorsOf('glpi_locations', $id[1]);
$this->assertEquals(1, count($parent));
$this->assertArrayHasKey($id[0], $parent);
// Ancestors of BB (none)
$parent = getAncestorsOf('glpi_locations', $id[2]);
$this->assertEquals(1, count($parent));
$this->assertArrayHasKey($id[0], $parent);
// B
$id[3] = $loc->add(['entities_id' => $entity,
'locations_id' => 0,
'name' => 'B']);
$this->assertGreaterThan(0, $id[3]);
// B > CC
$id[4] = $loc->add(['entities_id' => $entity,
'locations_id' => $id[3],
'name' => 'CC']);
$this->assertGreaterThan(0, $id[4]);
$this->assertTrue($loc->getFromDB($id[4]));
$this->assertEquals('B > CC', $loc->fields['completename']);
$sons = getSonsOf('glpi_locations', $id[3]);
$this->assertEquals(2, count($sons));
$this->assertArrayHasKey($id[4], $sons);
// B > CC > XXX
$id[5] = $loc->add(['entities_id' => $entity,
'locations_id' => $id[4],
'name' => 'XXX']);
$this->assertGreaterThan(0, $id[5]);
$this->assertTrue($loc->getFromDB($id[5]));
$this->assertEquals('B > CC > XXX', $loc->fields['completename']);
// B > CC => A > CC
$res = $loc->update(['id' => $id[4],
'locations_id' => $id[0]]);
$this->assertTrue($res);
$this->assertTrue($loc->getFromDB($id[4]));
$this->assertEquals('A > CC', $loc->fields['completename']);
// B > CC > XXX => A > CC > XXX
$this->assertTrue($loc->getFromDB($id[5]));
$this->assertEquals('A > CC > XXX', $loc->fields['completename']);
// New parent of CC (A)
$parent = getAncestorsOf('glpi_locations', $id[4]);
$this->assertEquals(1, count($parent));
$this->assertArrayHasKey($id[0], $parent);
// New sons of B (only B)
$sons = getSonsOf('glpi_locations', $id[3]);
$this->assertEquals(1, count($sons));
$this->assertArrayHasKey($id[3], $sons);
// New sons of A (A, AA, BB, CC)
$sons = getSonsOf('glpi_locations', $id[0]);
$this->assertEquals(5, count($sons));
$this->assertArrayHasKey($id[4], $sons);
$this->assertArrayHasKey($id[5], $sons);
// Rename A => C
$res = $loc->update(['id' => $id[0],
'name' => 'C']);
$this->assertTrue($res);
// Check complete name of sons
$this->assertTrue($loc->getFromDB($id[4]));
$this->assertEquals('C > CC', $loc->fields['completename']);
$this->assertTrue($loc->getFromDB($id[5]));
$this->assertEquals('C > CC > XXX', $loc->fields['completename']);
$this->assertEquals(3, $loc->fields['level']);
// Delete CC and move child under B
$res = $loc->delete(['id' => $id[4],
'_replace_by' => $id[3]]);
$this->assertTrue($res);
// Sons of B (B and XXX)
$sons = getSonsOf('glpi_locations', $id[3]);
$this->assertEquals(2, count($sons));
$this->assertArrayHasKey($id[5], $sons);
$this->assertTrue($loc->getFromDB($id[5]));
$this->assertEquals('B > XXX', $loc->fields['completename']);
$this->assertEquals(2, $loc->fields['level']);
}
}
<?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/>.
* ---------------------------------------------------------------------
*/
class Framework_Version extends PHPUnit_Framework_TestCase {
public function testVersion() {
global $CFG_GLPI;
$this->assertEquals('0.84', GLPI_VERSION, "Bad version in source page");
$this->assertEquals(GLPI_VERSION, $CFG_GLPI["version"], "Bad version in config");
}
// public function testLogin() {
// global $DB;
//
// $DB->connect();
//
// $auth = new Auth();
// $res = $auth->login('stupid_login_which_doesnt_exists', 'stupid_password');
// $this->assertFalse($res, "Bad login accepted");
//
// $res = $auth->login('glpi', 'glpi');
// $this->assertTrue($res, "Good login refused");
// }
}
<?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/>.
* ---------------------------------------------------------------------