Ejemplo n.º 1
0
    public function test_rename()
    {
        global $table_prefix;
        // uses auth, so we set up the mock/stub
        // to allow reading first forum
        $this->auth->expects($this->once())->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true)));
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $tag_id = 1;
        $new_name_clean = "newtagname";
        $assigned_count = $this->tags_manager->rename($tag_id, $new_name_clean);
        $this->assertEquals(1, $assigned_count);
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
    }
 /**
  * @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);
     }
 }