/** * Setup the $cp PHP global */ function cp_setup_cp_global() { global $cp, $wpdb; $cp = new StdClass(); // Set custom table names $cp->tables = new stdClass(); $cp->tables->project_users = $wpdb->prefix . 'cp_project_users'; // If we're not on a CollabPress page, bail. if (!is_collabpress_page()) { return; } // Set up the default keys $defaults = array('project' => false, 'task' => false, 'cp_page' => false, 'view' => false); // Parse query string variables and set CollabPress global appropriately foreach ($defaults as $key => $value) { if (!empty($_REQUEST[$key])) { switch ($key) { case 'project': $cp->project = get_post($_REQUEST[$key]); break; case 'task': $cp->task = get_post($_REQUEST[$key]); $cp->project = get_post(cp_get_task_project_id($cp->task->ID)); break; default: $cp->{$key} = $_REQUEST[$key]; break; } } } // Set the view if it's not declared in the query string. // We'll use it later for choosing the template to be loaded. if (empty($cp->view)) { if (!empty($cp->task)) { $cp->view = 'task'; } else { if (!empty($cp->project)) { $cp->view = 'project'; } else { $cp->view = 'dashboard'; } } } do_action('cp_global_setup'); }
function test_cp_get_task_project_id() { $tasklist_id = $this->factory->tasklist->create(array('project_id' => 4)); $task_id = $this->factory->task->create(array('task_list_id' => $tasklist_id)); $this->assertEquals(cp_get_task_project_id($task_id), 4); }