public function test_delete_content_type() { Post::add_new_type('test_type'); $params = array('title' => 'A post title', 'content' => 'Some great content. Really.', 'user_id' => $this->user->id, 'status' => Post::status('published'), 'content_type' => Post::type('test_type'), 'pubdate' => DateTime::date_create(time())); $post = Post::create($params); $this->assert_true('test_type' == $post->typename, "Post content type should be 'test_type'."); $this->assert_false(Post::delete_post_type('test_type'), "Post still exists with the content type 'test_type'"); $post->delete(); $this->assert_true(Post::delete_post_type('test_type'), "No posts exist with the content type 'test_type'"); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function module_setup() { $user = User::get_by_name('posts_test'); if (!$user) { $user = User::create(array('username' => 'posts_test', 'email' => '*****@*****.**', 'password' => md5('q' . rand(0, 65535)))); } $this->user = $user; $post = Post::create(array('title' => 'Test Post', 'content' => 'These tests expect there to be at least one post.', 'user_id' => $user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry'))); $this->post_id = $post->id; $this->paramarray = array('id' => 'foofoo', 'post_id' => $this->post_id, 'name' => 'test', 'email' => '*****@*****.**', 'url' => 'http://example.org', 'ip' => ip2long('127.0.0.1'), 'content' => 'test content', 'status' => Comment::status('unapproved'), 'date' => DateTime::date_create(), 'type' => Comment::type('comment')); $this->comment = Comment::create($this->paramarray); }
<?php namespace Habari; $habari_addon = Posts::get(array('content_type' => 'addon', 'slug' => 'habari')); if (count($habari_addon) == 0) { $habari = Post::create(array('content_type' => Post::type('addon'), 'title' => 'Habari', 'content' => file_get_contents(dirname(__FILE__) . '/addon.habari.txt'), 'status' => Post::status('published'), 'tags' => array('habari'), 'pubdate' => DateTime::date_create(), 'user_id' => User::identify()->id, 'slug' => 'habari')); $habari->info->guid = '7a0313be-d8e3-11db-8314-0800200c9a66'; $habari->info->url = 'http://habariproject.org'; $habari->info->description = 'Habari is next-generation blogging.'; $habari->info->authors = array(array('name' => 'The Habari Community', 'url' => 'http://habariproject.org')); $habari->info->licenses = array(array('name' => 'Apache License, Version 2.0', 'url' => 'http://www.apache.org/licenses/LICENSE-2.0')); $habari->info->type = 'core'; $habari->info->commit(); $versions = array('0.9' => array('version' => '0.9', 'description' => 'Habari release 0.9', 'info_url' => 'http://wiki.habariproject.org/en/Release_0.9', 'url' => 'http://habariproject.org/dist/habari-0.9.zip', 'habari_version' => '0.9', 'severity' => 'feature', 'requires' => '', 'provides' => '', 'recommends' => '', 'release' => DateTime::date_create('2012-11-20')->sql)); $this->save_versions($habari, $versions); $wazi = Post::create(array('content_type' => Post::type('addon'), 'title' => 'Wazi', 'content' => file_get_contents(Site::$config_path . '/system/themes/wazi/README'), 'status' => Post::status('published'), 'tags' => array('habari', 'theme'), 'pubdate' => DateTime::date_create(), 'user_id' => User::identify()->id, 'slug' => 'wazi')); $wazi->info->guid = ''; $wazi->info->url = 'http://habariproject.org'; $wazi->info->description = 'Responsive theme included with Habari.'; $wazi->info->authors = array(array('name' => 'The Habari Community', 'url' => 'http://habariproject.org')); $wazi->info->licenses = array(array('name' => 'Apache License, Version 2.0', 'url' => 'http://www.apache.org/licenses/LICENSE-2.0')); $wazi->info->type = 'theme'; $wazi->info->commit(); $versions = array('0.9' => array('version' => '0.9', 'description' => 'Wazi', 'info_url' => 'http://wiki.habariproject.org/en/Release_0.9', 'url' => 'http://habariproject.org/dist/habari-0.9.zip', 'habari_version' => '0.9', 'severity' => 'feature', 'requires' => '', 'provides' => '', 'recommends' => '', 'release' => DateTime::date_create('2012-11-20')->sql)); $this->save_versions($wazi, $versions); }
public static function handle_addon($info = array(), $versions = array()) { // Allow plugins to modify a new addon before it is created. Plugins::act('handle_addon_before', $info, $versions); $main_fields = array('user_id' => 'user_id', 'name' => 'title', 'description' => 'content', 'tags' => 'tags'); $post_fields = array('content_type' => Post::type('addon'), 'status' => Post::status('published'), 'pubdate' => DateTime::create()); $post = self::get_addon(strtoupper($info['guid'])); // strtoupper might not be necessary if (!$post) { /* There is no addon already with the guid. Create a new one. */ foreach ($main_fields as $k => $v) { $post_fields[$v] = $info[$k]; } unset($post); $post = Post::create($post_fields); $post->info->hoster = $info['hoster']; $post->update(); EventLog::log(_t('Created post #%s - %s', array($post->id, $post->title)), 'info'); } else { /* Update the existing addon. */ $post->modify(array('title' => $info['name'], 'content' => $info['description'], 'slug' => Utils::slugify($info['name']), 'pubdate' => DateTime::date_create())); $post->update(); EventLog::log(_t('Edited post #%s - %s', array($post->id, $post->title)), 'info'); $info = array_diff_key($info, array('original_repo' => 'should be removed for updates')); } // remove the fields that should not become postinfo. $info_fields = array_diff_key($info, $main_fields); foreach ($info_fields as $k => $v) { switch ($k) { case 'guid': $post->info->{$k} = strtoupper($v); break; default: $post->info->{$k} = $v; break; } } $post->info->commit(); self::save_versions($post, $versions); // Allow plugins to act after a new addon has been created. Plugins::act('handle_addon_after', $info, $versions); }
/** * Limit the number of posts returned * - limit => the maximum number of posts to return, implicitly set for many queries * - nolimit => do not implicitly set limit */ public function test_get_posts_with_limit() { for ($i = 1; $i <= 5; $i++) { $post = Post::create(array('title' => "Test Post {$i}", 'content' => 'If this were really a post...', 'user_id' => $this->user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry'), 'pubdate' => DateTime::date_create(time()))); $post->info->testing_limit = 1; $post->info->i = $i; $post->info->commit(); } $count_posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'count' => 1, 'limit' => 2)); $this->assert_equal($count_posts, 5, "LIMIT with a COUNT is pointless - COUNTing anything should return a single value."); $posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'limit' => 2)); $this->assert_equal(count($posts), 2); $count_posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'count' => 1, 'nolimit' => 1)); $this->assert_true($count_posts > 2); $posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'nolimit' => 1)); $this->assert_true(count($posts) > 2); // OFFSET based on page number (and limit) $posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'limit' => 2, 'page' => 2)); $this->assert_equal(count($posts), 2); $posts = Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'limit' => 2, 'page' => 3)); $this->assert_equal(count($posts), 1); Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_limit', 'nolimit' => 1))->delete(); }
private function make_comment($post, $time) { $comment = Comment::create(array('post_id' => $post->id, 'name' => $this->get_comment_name(), 'url' => 'http://example.com', 'content' => $this->get_comment_content(), 'status' => $this->get_comment_status(), 'type' => Comment::type('comment'), 'date' => DateTime::date_create($time))); $comment->info->lipsum = true; $comment->info->commit(); }
public function test_object_terms() { $post = Post::create(array('title' => 'Unit Test Post', 'content' => 'This is a unit test post to test setting and getting terms.', 'user_id' => 1, 'status' => Post::status('draft'), 'content_type' => Post::type('entry'), 'pubdate' => DateTime::date_create())); $v = Vocabulary::get('tags'); // Test setting terms with strings $new_terms = array('habari', 'unit test'); $v->set_object_terms('post', $post->id, $new_terms); $terms = $v->get_object_terms('post', $post->id); $t = array(); foreach ($terms as $term) { $t[] = (string) $term; } $this->assert_equal(2, count($terms)); $this->assert_equal(0, count(array_diff($new_terms, $t))); // Test get_all_object_terms $nv = Vocabulary::create(array('name' => 'animals', 'description' => 'Types of animals.', 'features' => array('hierarchical'))); $root = $nv->add_term('Animal Kingdom'); $nv->set_object_terms('post', $post->id, array($root)); $terms = Vocabulary::get_all_object_terms('post', $post->id); $new_terms[] = 'Animal Kingdom'; $t = array(); foreach ($terms as $term) { $t[] = (string) $term; } $this->assert_equal(3, count($terms)); $this->assert_equal(0, count(array_diff($new_terms, $t))); $v->delete_term('unit test'); $post->delete(); $nv->delete(); }