function testProjectModel() { $this->startCodeCoverage(); $project = new Project(); $this->assertTrue($project->GetNumberOfErrorConfigures(0, 0) === false, "GetNumberOfErrorConfigures!=false"); $this->assertTrue($project->GetNumberOfWarningConfigures(0, 0) === false, "GetNumberOfWarningConfigures!=false"); $this->assertTrue($project->GetNumberOfPassingConfigures(0, 0) === false, "GetNumberOfPassingConfigures!=false"); $this->assertTrue($project->GetNumberOfPassingTests(0, 0) === false, "GetNumberOfPassingTests!=false"); $this->assertTrue($project->GetNumberOfFailingTests(0, 0) === false, "GetNumberOfFailingTests!=false"); $this->assertTrue($project->GetNumberOfNotRunTests(0, 0) === false, "GetNumberOfNotRunTests!=false"); $this->assertTrue($project->SendEmailToAdmin(0, 0) === false, "SendEmailToAdmin!=false"); if (!($project->Delete() === false)) { $this->fail("Project::Delete didn't return false for no id"); return 1; } $project->Id = "27123"; if (!($project->Exists() === false)) { $this->fail("Project::Exists didn't return false for bogus id"); return 1; } //Cover empty contents case $project->AddLogo('', ''); $project->Id = "2"; $contents1 = file_get_contents('data/smile.gif', true); $contents2 = file_get_contents('data/smile2.gif', true); //Cover all execution paths $project->AddLogo($contents1, 'gif'); $project->AddLogo($contents2, 'gif'); $project->AddLogo($contents1, 'gif'); @$project->SendEmailToAdmin('foo', 'hello world'); $this->stopCodeCoverage(); return 0; }
public function deleteProject($projectid) { // Login as admin. $client = new GuzzleHttp\Client(['cookies' => true]); global $CDASH_BASE_URL; try { $response = $client->request('POST', $CDASH_BASE_URL . '/user.php', ['form_params' => ['login' => 'simpletest@localhost', 'passwd' => 'simpletest', 'sent' => 'Login >>']]); } catch (GuzzleHttp\Exception\ClientException $e) { $this->fail($e->getMessage()); return false; } // Delete project. $project_array = array('Id' => $projectid); try { $response = $client->delete($CDASH_BASE_URL . '/api/v1/project.php', ['json' => ['project' => $project_array]]); } catch (GuzzleHttp\Exception\ClientException $e) { $this->fail($e->getMessage()); return false; } // Make sure the project doesn't exist anymore. $project = new Project(); $project->Id = $projectid; if ($project->Exists()) { $this->fail("Project {$projectid} still exists after it should have been deleted"); } }
function get_project(&$response) { // Make sure we have a projectid. if (!isset($_REQUEST['project'])) { $response['error'] = 'No projectid specified'; http_response_code(400); return false; } if (!is_array($_REQUEST['project'])) { $_REQUEST['project'] = json_decode($_REQUEST['project'], true); } if (!isset($_REQUEST['project']['Id'])) { $response['error'] = 'No projectid specified'; http_response_code(400); return false; } $projectid = $_REQUEST['project']['Id']; if (!is_numeric($projectid) || $projectid < 1) { $response['error'] = 'No projectid specified'; http_response_code(400); return false; } // Make sure the project exists. $Project = new Project(); $Project->Id = $projectid; if (!$Project->Exists()) { $response['error'] = 'This project does not exist.'; http_response_code(400); return false; } // Make sure we have an authenticated user that has access to this project. if (!valid_user($reponse, $projectid)) { return false; } return $Project; }
$edit = isset($_GET['edit']) && !empty($_GET['edit']); $projectid = null; if (isset($_GET['projectid']) && !empty($_GET['projectid'])) { $projectid = pdo_real_escape_numeric($_GET['projectid']); } $Project = new Project(); // If the projectid is not set and there is only one project we go directly to the page if ($edit && is_null($projectid)) { $projectids = $Project->GetIds(); if (count($projectids) == 1) { $projectid = $projectids[0]; } } // If the projectid is set, make sure that it's valid $Project->Id = $projectid; if (!is_null($projectid) && $projectid > 0 && !$Project->Exists()) { $response['error'] = 'This project does not exist.'; echo json_encode($response); return; } $User = new User(); $User->Id = $userid; $role = $Project->GetUserRole($userid); // If we are editing a project make sure we have the right to do so if (!is_null($projectid) && !(isset($_SESSION['cdash']['user_can_create_project']) && $_SESSION['cdash']['user_can_create_project'] == 1) && !$User->IsAdmin()) { $response['error'] = 'You do not have permission to access this page.'; echo json_encode($response); return; } elseif (!is_null($projectid) && (!$User->IsAdmin() && $role <= 1)) { $response['error'] = 'You do not have permission to access this page.'; echo json_encode($response);
@($edit = $_GET["edit"]); @($projectid = $_GET["projectid"]); if ($projectid != NULL) { $projectid = pdo_real_escape_numeric($projectid); } $Project = new Project(); // If the projectid is not set and there is only one project we go directly to the page if (isset($edit) && !isset($projectid)) { $projectids = $Project->GetIds(); if (count($projectids) == 1) { $projectid = $projectids[0]; } } // If the projectid is set, make sure that it's valid $Project->Id = $projectid; if (isset($projectid) && $projectid > 0 && !$Project->Exists()) { echo "This project doesn't exists."; return; } $User = new User(); $User->Id = $userid; $role = $Project->GetUserRole($userid); // If we are editing a project make sure we have the right to do so if (!isset($projectid) && !(isset($_SESSION['cdash']['user_can_create_project']) && $_SESSION['cdash']['user_can_create_project'] == 1) && !$User->IsAdmin()) { echo "You don't have the permissions to access this page"; return; } else { if (isset($projectid) && (!$User->IsAdmin() && $role <= 1)) { echo "You don't have the permissions to access this page"; return; }
include 'public/login.php'; $start = microtime_float(); $response = array(); // Make sure a project was requested. if (!isset($_GET['project'])) { $response['error'] = 'Project not specified.'; echo json_encode($response); http_response_code(400); return; } // Make sure the project exists. $projectname = $_GET['project']; $projectid = get_project_id($projectname); $Project = new Project(); $Project->Id = $projectid; if (!$Project->Exists()) { $response['error'] = 'Project does not exist.'; echo json_encode($response); http_response_code(400); return; } // Load project data. $Project->Fill(); $has_subprojects = $Project->GetNumberOfSubProjects() > 0; // Make sure the user has access to this project. $logged_in = false; if (isset($_SESSION['cdash']) && isset($_SESSION['cdash']['loginid'])) { $logged_in = true; } if (!checkUserPolicy(@$_SESSION['cdash']['loginid'], $projectid, 1)) { if ($logged_in) {