Ejemplo n.º 1
0
 public function testCRUD()
 {
     $post = new BlogPost();
     $post->userId = 2;
     $post->title = "Hello World!";
     $post->message = "This is a blog post!";
     $this->assertEqual($post->isNewRecord(), true);
     $this->assertEqual($post->createdAt, null);
     $this->assertEqual($post->save(), true);
     $this->assertEqual($post->isNewRecord(), false);
     $this->assertNotEqual($post->createdAt, null);
     // post got an id after save
     $id = $post->id;
     // Load and update post but to another variable
     $post2 = BlogPost::load($id);
     $this->assertEqual($post2->isNewRecord(), false);
     $this->assertNotEqual($post2, null);
     $this->assertEqual($post2->message, "This is a blog post!");
     $post2->message = "This is a new text";
     $post2->createdAt = 1;
     $this->assertEqual($post2->save(), true);
     // Reload first post and check that message was updated
     $post->reload();
     $this->assertEqual($post->message, "This is a new text");
     $this->assertEqual($post->createdAt, 1);
     // Delete post
     $post->delete();
     $this->assertEqual($post->isDeletedRecord, true);
     try {
         $post->save();
     } catch (Exception $e) {
     }
     $this->assertNotEqual($e, null);
     $this->assertEqual(get_class($e), 'TipyModelException');
     $this->assertEqual($e->getMessage(), "Unable to save deleted model");
     try {
         $post->reload();
     } catch (Exception $e) {
     }
     $this->assertNotEqual($e, null);
     $this->assertEqual(get_class($e), 'TipyModelException');
     $this->assertEqual($e->getMessage(), "Unable to reload deleted model");
 }
Ejemplo n.º 2
0
//instantiate the object representing this blog
$blog = new Blog($course_id, $user_id);

//delete post
if ($action == "delPost") {
    $post = new BlogPost();
    if ($post->loadFromDB($pId)) {
        //different criteria regarding editing posts for different blog types
        if ($blog_type == 'course_blog') {
            $allow_to_edit = $post->permEdit($is_editor, $stud_allow_create, $uid);
        } elseif ($blog_type == 'perso_blog') {
            $allow_to_edit = $is_blog_editor;
        }
        if ($allow_to_edit) {
            if($post->delete()) {
                Session::Messages($langBlogPostDelSucc, 'alert-success');
            } else {
                Session::Messages($langBlogPostDelFail);
            }
        } else {
            Session::Messages($langBlogPostNotAllowedDel);
        }
    } else {
        Session::Messages($langBlogPostNotFound);      
    }
    redirect_to_home_page("modules/blog/index.php?$url_params");
}

//create blog post form
if ($action == "createPost") {