function testRenderAsEdit_newNotebook() { global $USER; $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB); $n = Notebook::createNewNotebookForUser($USER->user_id, $this->DB); // $this->fail(); // $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="'.$n->created_at.'" data-updated_at="'.$n->updated_at.'" data-user_id="101" data-name="'.htmlentities($n->name).'" data-notes="'.htmlentities(util_lang('new_notebook_notes')).'" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> //<form action="'.APP_ROOT_PATH.'/app_code/notebook.php"> // <input type="hidden" name="action" value="update"/> // <input type="hidden" name="notebook_id" value="NEW"/> // <h3 class="notebook_title">'.ucfirst(util_lang('notebook')).': <input id="notebook-name" type="text" name="name" value="'.htmlentities($n->name).'"/></h3> // <span class="created_at">'.util_lang('created_at').' '.util_datetimeFormatted($n->created_at).'</span>, <span class="updated_at">'.util_lang('updated_at').' '.util_datetimeFormatted($n->updated_at).'</span><br/> // <span class="owner">'.util_lang('owned_by').' <a href="'.APP_ROOT_PATH.'/app_code/user.php?action=view&user_id=101">'.$USER->screen_name.'</a></span><br/> // <div class="notebook-notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">'.htmlentities(util_lang('new_notebook_notes')).'</textarea></div> // <input id="edit-submit-control" class="btn" type="submit" name="edit-submit-control" value="'.util_lang('save','properize').'"/> // <a id="edit-cancel-control" class="btn" href="/digitalfieldnotebooks/app_code/notebook.php?action=list">'.util_lang('cancel','properize').'</a> //</form> // <h4>'.ucfirst(util_lang('pages')).'</h4> // '.util_lang('new_notebook_must_be_saved').' //</div>'; $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="' . $n->created_at . '" data-updated_at="' . $n->updated_at . '" data-user_id="101" data-name="' . htmlentities($n->name) . '" data-notes="' . htmlentities(util_lang('new_notebook_notes')) . '" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> <form action="' . APP_ROOT_PATH . '/app_code/notebook.php"> <div id="actions"> <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('save', 'properize') . '</button> <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=list"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a> </div> <input type="hidden" name="action" value="update"/> <input type="hidden" name="notebook_id" value="NEW"/> <h3 class="notebook_title">' . ucfirst(util_lang('notebook')) . ': <input id="notebook-name" type="text" name="name" value="' . htmlentities($n->name) . '"/></h3> <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($n->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($n->updated_at) . '</span></div> <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . $USER->screen_name . '</a></div> <div class="control-workflows"></div> <div class="notebook_notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">' . htmlentities(util_lang('new_notebook_notes')) . '</textarea></div> </form> <h4>' . ucfirst(util_lang('pages')) . '</h4> ' . util_lang('new_notebook_must_be_saved') . ' </div>'; $rendered = $n->renderAsEdit(); // echo "<pre>\n".htmlentities($canonical)."\n-----------------\n".htmlentities($rendered)."\n</pre>"; $this->assertEqual($canonical, $rendered); $this->assertNoPattern('/IMPLEMENTED/', $rendered); }
// exit; if (count($all_accessible_notebooks) < 1) { $notebook = new Notebook(['DB' => $DB]); if (!$USER->canActOnTarget($ACTIONS['create'], $notebook)) { util_redirectToAppHome('failure', util_lang('no_notebooks_found')); } } else { $notebook = $all_accessible_notebooks[0]; } } else { // if ((! isset($_REQUEST['notebook_id'])) || (! is_numeric($_REQUEST['notebook_id']))) { //// util_redirectToAppHome('failure',util_lang('no_notebook_specified')); // util_redirectToAppPage('app_code/notebook.php?action=list','failure',util_lang('no_notebook_specified')); // } if ($_REQUEST['notebook_id'] == 'NEW') { $notebook = Notebook::createNewNotebookForUser($USER->user_id, $DB); } else { $notebook = Notebook::getOneFromDb(['notebook_id' => $_REQUEST['notebook_id']], $DB); if (!$notebook->matchesDb) { // util_redirectToAppHome('failure',util_lang('no_notebook_found')); util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_found')); } } } # 3. confirm that the user is allowed to take that action on that object (if not, redirect them to the home page with an appropriate warning) if (!$USER->canActOnTarget($ACTIONS[$action], $notebook)) { // util_redirectToAppHome('failure',util_lang('no_permission')); if ($action == 'edit') { util_redirectToAppPage('app_code/notebook.php?action=view¬ebook_id=' . $notebook->notebook_id, 'failure', util_lang('no_permission')); } util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_permission'));