public function test_get_tag_by_id() { $tag = $this->tags_manager->get_tag_by_id(1); $this->assertEquals('tag1', $tag); $tag = $this->tags_manager->get_tag_by_id(2); $this->assertEquals('tag2', $tag); }
/** * @param $is_ajax whether the edit is called by ajax or not * @param string $u_action phpbb acp-u_action */ private function handle_edit($u_action, $is_ajax = true) { if (!$is_ajax) { $new_tag_name = $this->request->variable('new_tag_name', ''); if (empty($new_tag_name)) { $tag_id = $this->request->variable('tag_id', 0); $old_tag_name = $this->tags_manager->get_tag_by_id($tag_id); $this->template->assign_vars(array('U_ACTION' => $this->get_tag_link($u_action, $tag_id) . '&action=edit_non_ajax', 'S_EDIT_TAG_NON_AJAX' => true, 'OLD_TAG_NAME' => $old_tag_name)); return; } // now new_tag_name and old_tag_name are set and the normal procedure can take place. } $old_tag_name = $this->request->variable('old_tag_name', ''); $new_tag_name = $this->request->variable('new_tag_name', ''); if (empty($old_tag_name) || empty($new_tag_name)) { $error_msg = $this->user->lang('TOPICTAGS_MISSING_TAG_NAMES'); $this->simple_response($u_action, $error_msg, false); } else { if ($is_ajax) { $old_tag_name = rawurldecode(base64_decode($old_tag_name)); $new_tag_name = rawurldecode(base64_decode($new_tag_name)); } if ($old_tag_name == $new_tag_name) { $error_msg = $this->user->lang('TOPICTAGS_NO_MODIFICATION', $old_tag_name); $this->simple_response($u_action, $error_msg, false); } $old_ids = $this->tags_manager->get_existing_tags(array($old_tag_name), true); if (empty($old_ids)) { $error_msg = $this->user->lang('TOPICTAGS_TAG_DOES_NOT_EXIST', $old_tag_name); $this->simple_response($u_action, $error_msg, false); } // if we reach here, we know that we got a single valid old tag $old_id = $old_ids[0]; $new_tag_name_clean = $this->tags_manager->clean_tag($new_tag_name); $is_valid = $this->tags_manager->is_valid_tag($new_tag_name_clean, true); if (!$is_valid) { $error_msg = $this->user->lang('TOPICTAGS_TAG_INVALID', $new_tag_name); $this->simple_response($u_action, $error_msg, false); } // old tag exist and new tag is valid $new_ids = $this->tags_manager->get_existing_tags(array($new_tag_name), true); if (!empty($new_ids)) { // new tag exist -> merge $new_id = $new_ids[0]; $new_tag_count = $this->tags_manager->merge($old_id, $new_tag_name, $new_id); $msg = $this->user->lang('TOPICTAGS_TAG_MERGED', $new_tag_name_clean); $this->simple_response($u_action, $msg, true, array('success' => true, 'merged' => true, 'new_tag_count' => $new_tag_count, 'msg' => base64_encode(rawurlencode($msg)))); } // old tag exist and new tag is valid and does not exist -> rename it $this->tags_manager->rename($old_id, $new_tag_name_clean); $msg = $this->user->lang('TOPICTAGS_TAG_CHANGED'); $this->simple_response($u_action, $msg); } }