From 1e1d4b411abda527e6e00e0e13f992fd57f7a8ad Mon Sep 17 00:00:00 2001 From: Keita Jamadam Sugama Date: Tue, 30 Apr 2024 09:44:26 +0900 Subject: [PATCH] backport phpunit tests --- php/tests/AdodbTest.php | 3 - php/tests/ArchiveLibTest.php | 2 +- php/tests/BaseObjectTest.php | 138 +++++++++----------- php/tests/ClassTest.php | 133 +++++++++++++++++++ php/tests/InitTestDB.php | 3 + php/tests/MTSerializeTest.php | 2 +- php/tests/MemcachedTest.php | 16 +-- php/tests/Mockdata.php | 235 ++++++++++++++++++++++++++++++++++ php/tests/UnitTest.php | 208 +++++++++++++++++++++++++++--- 9 files changed, 633 insertions(+), 107 deletions(-) create mode 100644 php/tests/ClassTest.php create mode 100644 php/tests/Mockdata.php diff --git a/php/tests/AdodbTest.php b/php/tests/AdodbTest.php index 1c9703aaa6..70c306b66c 100644 --- a/php/tests/AdodbTest.php +++ b/php/tests/AdodbTest.php @@ -1,8 +1,5 @@ context(); - - // Test some objects inheriting ObjectBase class. - - require_once( "php/lib/class.mt_config.php" ); - $config = new Config; - $config->Load(); - $this->assertTrue( isset( $config->id ) ); - - require_once( "php/lib/class.mt_author.php" ); - $author = new Author; - $author->Load(); - $this->assertTrue( isset( $author->id ) ); - - require_once( "php/lib/class.mt_entry.php" ); - $entry = new Entry; - $entry->id = 1; - $this->assertTrue( isset( $entry->id ) ); - $this->assertEquals( 'entry_', $entry->_prefix ); - - // protected variable call (bugid:113105, MTC-9543) - $this->assertNull( $entry->_has_meta ); - $this->assertFalse( isset( $entry->_has_meta ) ); - - // ignore E_DEPRECATED for some tests - error_reporting(error_reporting() & ~E_DEPRECATED); - - // dynamic properties still works (__set/__get/__isset magic methods) - $entry->unknown = 'val'; - $this->assertTrue( isset( $entry->unknown ) ); - $this->assertEquals( 'val', $entry->unknown ); - - // meta field in the form of order_by MT tag attributes work - $meta_field1 = 'field:my_field1'; - $meta_field2 = 'field:my_field2'; - $entry->$meta_field1 = 'my_field1_val'; - $this->assertTrue( isset( $entry->$meta_field1 ) ); - $this->assertEquals( 'my_field1_val', $entry->$meta_field1 ); - $this->assertFalse( isset( $entry->$meta_field2 ) ); - $this->assertNull( $entry->$meta_field2 ); - - error_reporting(error_reporting() | E_DEPRECATED); - - // fixed Dynamic publishing error occurred with memcached environment. bugid: 113546 - $mt->config('MemcachedServers', '127.0.0.1:11211'); - $obj_names = array( - 'asset' => 'Asset', - 'author' => 'Author', - 'blog' => 'Blog', - 'category' => 'Category', - 'comment' => 'Comment', - 'entry' => 'Entry', - 'folder' => 'Folder', - 'page' => 'Page', - 'tbping' => 'TBPing', - 'template' => 'Template', - 'website' => 'Website'); - foreach ($obj_names as $table => $name) { - require_once("php/lib/class.mt_$table.php"); - $obj = new $name; - $obj->Load(); - - $this->cache("$table:".$obj->id, $obj); - $obj_cache = $this->load_cache("$table:".$obj->id); - $this->assertInstanceOf("$name", $obj_cache); - } + public function testIssetWithOverloading() { + + // Test some objects inheriting ObjectBase class. + + require_once( "php/lib/class.mt_config.php" ); + $config = new Config; + $config->Load(); + $this->assertTrue( isset( $config->id ) ); + + require_once( "php/lib/class.mt_author.php" ); + $author = new Author; + $author->Load(); + $this->assertTrue( isset( $author->id ) ); + + require_once( "php/lib/class.mt_entry.php" ); + $entry = new Entry; + $entry->id = 1; + $this->assertTrue( isset( $entry->id ) ); + $this->assertEquals( 'entry_', $entry->_prefix ); + + // protected variable call (bugid:113105, MTC-9543) + $this->assertNull( $entry->_has_meta ); + $this->assertFalse( isset( $entry->_has_meta ) ); + + // dynamic properties still works (__set/__get/__isset magic methods) + $entry->unknown = 'val'; + $this->assertTrue( isset( $entry->unknown ) ); + $this->assertEquals( 'val', $entry->unknown ); + + // meta field in the form of order_by MT tag attributes work + $meta_field1 = 'field:my_field1'; + $meta_field2 = 'field:my_field2'; + $entry->$meta_field1 = 'my_field1_val'; + $this->assertTrue( isset( $entry->$meta_field1 ) ); + $this->assertEquals( 'my_field1_val', $entry->$meta_field1 ); + $this->assertFalse( isset( $entry->$meta_field2 ) ); + $this->assertNull( $entry->$meta_field2 ); + + // fixed Dynamic publishing error occurred with memcached environment. bugid: 113546 + MT::get_instance()->config('MemcachedServers', '127.0.0.1:11211'); + $obj_names = array( + 'asset' => 'Asset', + 'author' => 'Author', + 'blog' => 'Blog', + 'category' => 'Category', + 'comment' => 'Comment', + 'entry' => 'Entry', + 'folder' => 'Folder', + 'page' => 'Page', + 'tbping' => 'TBPing', + 'template' => 'Template', + 'website' => 'Website'); + foreach ($obj_names as $table => $name) { + require_once("class.mt_$table.php"); + $obj = new $name; + $obj->Load(); + + $this->cache("$table:".$obj->id, $obj); + $obj_cache = $this->load_cache("$table:".$obj->id); + $this->assertInstanceOf("$name", $obj_cache); + } - } + } // Objcet cache private function cache($key, $obj) { @@ -99,7 +87,7 @@ private function load_cache($key) { private function cache_driver() { if (empty(self::$_cache_driver)) { - require_once("class.basecache.php"); + require_once('class.basecache.php'); try { self::$_cache_driver = CacheProviderFactory::get_provider('memcached'); } catch (Exception $e) { diff --git a/php/tests/ClassTest.php b/php/tests/ClassTest.php new file mode 100644 index 0000000000..6c04a08492 --- /dev/null +++ b/php/tests/ClassTest.php @@ -0,0 +1,133 @@ +Load($entry->id); + $this->assertEquals('Entry', get_class($entry2)); + $this->assertEquals($entry->id, $entry2->id); + + $template = $entry2->template(); + $this->assertEquals('Template', get_class($template)); + $this->assertEquals('1', $template->id); + + $comment = Mockdata::makeComment(); + $comments = $entry->comments(); + $this->assertEquals('Comment', get_class($comments[0])); + $this->assertEquals($comment->id, $comments[0]->id); + + $trackback = MockData::makeTrackback(); + + $trackback2 = $entry->trackback(); + $this->assertEquals('Trackback', get_class($trackback2)); + $this->assertEquals($trackback->id, $trackback2->id); + + $ping = MockData::makeTbping(['entry_id' => $entry->id, 'trackback_id' => $trackback->id]); + $pings = $entry->pings(); + $this->assertEquals('TBPing', get_class($pings[0])); + $this->assertEquals($ping->id, $pings[0]->id); + + $trackback2 = $ping->trackback(); + $this->assertEquals('Trackback', get_class($trackback2)); + $this->assertEquals($trackback2->id, $trackback->id); + + $category2 = $trackback2->category(); + $this->assertEquals('Category', get_class($category2)); + $this->assertEquals($category->id, $category2->id); + } + + public function testObjectAsset() { + + $entry = MockData::makeEntry(); + $asset = MockData::makeAsset(); + $oasset = MockData::makeObjectAsset(['object_ds' => 'entry']); + + $oasset2 = new ObjectAsset(); + $oasset2->Load($oasset->id); + $this->assertEquals('ObjectAsset', get_class($oasset2)); + $this->assertEquals($oasset->id, $oasset2->id); + + $asset2 = $oasset2->asset(); + $this->assertEquals('Asset', get_class($asset2)); + $this->assertEquals($asset->id, $asset2->id); + + $entry2 = $oasset2->related_object(); + $this->assertEquals('Entry', get_class($entry2)); + $this->assertEquals($entry->id, $entry2->id); + } + + public function testObjectScore() { + + $entry = MockData::makeEntry(); + $oscore = MockData::makeObjectScore(['object_ds' => 'entry']); + $oscore2 = new ObjectScore(); + $oscore2->Load($oscore->id); + $this->assertEquals('ObjectScore', get_class($oscore2)); + $this->assertEquals($oscore->id, $oscore2->id); + + $entry2 = $oscore2->related_object(); + $this->assertEquals('Entry', get_class($entry2)); + $this->assertEquals($entry->id, $entry2->id); + } + + public function testObjectTag() { + + $entry = Mockdata::makeEntry(['status' => 2]); + $otag = MockData::makeObjectTag(['object_datasource' => 'entry', 'tag_id' => 1]); + + $otag2 = new ObjectTag(); + $otag2->Load($otag->id); + $this->assertEquals('ObjectTag', get_class($otag2)); + $this->assertEquals($otag->id, $otag2->id); + + $entry2 = $otag2->related_object(); + $this->assertEquals('Entry', get_class($entry2)); + $this->assertEquals($entry->id, $entry2->id); + + $tag = $otag2->tag(); + $this->assertEquals('Tag', get_class($tag)); + } + + public function testPage() { + + $page = MockData::makePage(); + + require_once('class.mt_folder.php'); + $folder = new Folder(); + $folder->blog_id = 1; + $folder->class = 'folder'; + $folder->category_category_set_id = 0; + $folder->label = ''; + $folder->save(); + + require_once('class.mt_placement.php'); + $placement = new Placement(); + $placement->blog_id = 1; + $placement->entry_id = $page->id; + $placement->is_primary = 1; + $placement->category_id = $folder->id; + $placement->save(); + + $folder2 = $page->folder(); + $this->assertEquals('Folder', get_class($folder2)); + $this->assertEquals($folder2->id, $folder->id); + } + + public function testTemplate() { + + $template = MockData::makeTemplate(['type' => 'index', 'name' => 'mytemplate']); + + $blog = $template->blog(); + $this->assertEquals('Website', get_class($blog)); + $this->assertEquals(1, $blog->id); + } +} diff --git a/php/tests/InitTestDB.php b/php/tests/InitTestDB.php index f6f3577ab1..61bdaf1a18 100644 --- a/php/tests/InitTestDB.php +++ b/php/tests/InitTestDB.php @@ -2,3 +2,6 @@ system('MT_CONFIG=mysql-test.cfg perl -It/lib -Ilib -Iextlib -MMT::Test=:db -E "say \"Initialized test DB.\""'); +set_include_path(realpath(__DIR__). '/../'); +require_once('mt.php'); +MT::get_instance(1, realpath( "t/mysql-test.cfg" )); diff --git a/php/tests/MTSerializeTest.php b/php/tests/MTSerializeTest.php index f27b53ff4d..0fe73afd83 100644 --- a/php/tests/MTSerializeTest.php +++ b/php/tests/MTSerializeTest.php @@ -4,7 +4,7 @@ class MTSerializeTest extends TestCase { public function testGetInstace() { - include_once('php/lib/MTSerialize.php'); + require_once('MTSerialize.php'); $serializer1 = MTSerialize::get_instance(); $this->assertInstanceOf('MTSerialize', $serializer1); diff --git a/php/tests/MemcachedTest.php b/php/tests/MemcachedTest.php index ade7db294f..7c85e7575c 100644 --- a/php/tests/MemcachedTest.php +++ b/php/tests/MemcachedTest.php @@ -2,14 +2,14 @@ use PHPUnit\Framework\TestCase; -include_once("php/lib/mtcache_base.php"); -include_once("php/lib/class.basecache.php"); -include_once("php/mt.php"); +require_once('mtcache_base.php'); +require_once('class.basecache.php'); +require_once('mt.php'); class MemcachedTest extends TestCase { public function testMain() { - $mt = MT::get_instance(1, realpath( "t/mysql-test.cfg" )); + $mt = MT::get_instance(); $this->_testCacheLib($mt); $this->_testMTCacheSession($mt); $this->_testCacheSession($mt); @@ -25,26 +25,26 @@ public function _testCacheLib($mt) { } public function _testMTCacheSession($mt) { - include_once("php/lib/mtcache_session.php"); + require_once('mtcache_session.php'); $a = new MTCache_session(); $this->assertCache($a, true); } public function _testCacheSession($mt) { - include_once("php/lib/class.cachesession.php"); + require_once('class.cachesession.php'); $a = new CacheSession(); $this->assertCache($a, true); } public function _testCacheMemcache($mt) { - include_once("php/lib/class.cachememcached.php"); + require_once('class.cachememcached.php'); $mt->config('MemcachedServers', '127.0.0.1:11211'); $a = new CacheMemcached(); $this->assertCache($a); } public function _testMTCacheMemcached($mt) { - include_once("php/lib/mtcache_memcached.php"); + require_once('mtcache_memcached.php'); $a = new MTCache_memcached(); $a->connect('127.0.0.1:11211'); $this->assertCache($a); diff --git a/php/tests/Mockdata.php b/php/tests/Mockdata.php new file mode 100644 index 0000000000..bdd1c13910 --- /dev/null +++ b/php/tests/Mockdata.php @@ -0,0 +1,235 @@ +name = $args['name']; + $blog->save(); + self::$last_blog_id = $blog->id; + return $blog; + } + + public static function makeEntry($args=[]) { + + require_once('class.mt_entry.php'); + $entry = new Entry(); + $entry->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $entry->category_category_set_id = 1; + $entry->author_id = 1; + $entry->current_revision = 1; + $entry->status = $args['status'] ?? 1; + $entry->template_id = '1'; + $entry->save(); + self::$last_entry_id = $entry->id; + return $entry; + } + + public static function makePage($args=[]) { + + require_once('class.mt_page.php'); + $page = new Page(); + $page->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $page->category_category_set_id = 1; + $page->author_id = 1; + $page->current_revision = 1; + $page->status = '3'; + $page->template_id = '1'; + $page->save(); + return $page; + } + + public static function makeAsset($args=[]) { + + require_once('class.mt_asset.php'); + $asset = new Asset(); + $asset->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $asset->class = 'image'; + $asset->save(); + + self::$last_asset_id = $asset->id; + + return $asset; + } + + public static function makeCategory($args=[]) { + + require_once('class.mt_category.php'); + $category = new Category(); + $category->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $category->class = 'category'; + $category->category_category_set_id = 0; + $category->label = ''; + $category->save(); + + self::$last_category_id = $category->id; + + return $category; + } + + public static function makeTrackback($args=[]) { + + require_once('class.mt_trackback.php'); + $trackback = new Trackback(); + $trackback->entry_id = $args['entry_id'] ?? self::$last_entry_id; + $trackback->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $trackback->last_moved_on = '2000-01-01 00:00:00'; + $trackback->category_id = $args['category_id'] ?? self::$last_category_id; + $trackback->save(); + + self::$last_trackback_id = $trackback->id; + + return $trackback; + } + + + public static function makeTbping($args=[]) { + + $entry_id = $args['entry_id'] ?? self::$last_entry_id; + require_once('class.mt_tbping.php'); + $ping = new TBPing(); + $ping->entry_id = $entry_id; + $ping->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $ping->last_moved_on = '2000-01-01 00:00:00'; + $ping->ip = '127.0.0.1'; + $ping->junk_status = 1; + $ping->tb_id = $args['trackback_id'] ?? self::$last_trackback_id; + $ping->visible = 1; + $ping->save(); + + $entry = new Entry(); + $entry->Load($entry_id); + $entry->ping_count++; + $entry->save(); + + return $ping; + } + + public static function makeObjectScore($args=[]) { + + require_once('class.mt_objectscore.php'); + $oscore = new ObjectScore(); + $oscore->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $oscore->object_ds = $args['object_ds']; + $oscore->object_id = $args['object_id']; + if (!isset($oscore->object_id)) { + if ($args['object_ds'] === 'entry') { + $oscore->object_id = self::$last_entry_id; + } else if ($args['object_ds'] === 'content_data') { + $oscore->object_id = self::$last_content_data; + } + } + $oscore->namespace = 'foo'; + $oscore->save(); + return $oscore; + } + + public static function makeTemplate($args=[]) { + + require_once('class.mt_template.php'); + $template = new Template(); + $template->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $template->name = $args['name']; + $template->type = $args['type']; + $template->current_revision = 1; + $template->save(); + return $template; + } + + public static function makeTag($args=[]) { + + require_once('class.mt_tag.php'); + $tag = new Tag(); + $tag->tag_name = $args['name']; + $tag->save(); + return $tag; + } + + public static function makeComment($args=[]) { + + $entry_id = $args['entry_id'] ?? self::$last_entry_id; + require_once('class.mt_comment.php'); + $comment = new Comment(); + $comment->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $comment->entry_id = $entry_id; + $comment->last_moved_on = '2000-01-01 00:00:00'; + $comment->save(); + + $entry = new Entry(); + $entry->Load($entry_id); + $entry->comment_count++; + $entry->save(); + + return $comment; + } + + public static function makeObjectAsset($args=[]) { + + require_once('class.mt_objectasset.php'); + $oasset = new ObjectAsset(); + $oasset->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $oasset->asset_id = $asset_id ?? self::$last_asset_id ?? 1; + $oasset->cf_id = 0; + $oasset->object_ds = $args['object_ds']; + $oasset->object_id = $args['object_id']; + if (!isset($oasset->object_id)) { + if ($args['object_ds'] === 'entry') { + $oasset->object_id = self::$last_entry_id; + } else if ($args['object_ds'] === 'content_data') { + $oasset->object_id = self::$last_content_data; + } + } + $oasset->save(); + return $oasset; + } + + public static function makeObjectTag($args=[]) { + + require_once('class.mt_objecttag.php'); + $otag = new ObjectTag(); + $otag->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $otag->object_datasource = $args['object_datasource']; + $otag->object_id = $args['object_id']; + if (!isset($otag->object_id)) { + if ($args['object_datasource'] === 'entry') { + $otag->object_id = self::$last_entry_id; + } else if ($args['object_datasource'] === 'content_data') { + $otag->object_id = self::$last_content_data; + } + } + $otag->cf_id = 0; + $otag->tag_id = $args['tag_id']; + $otag->save(); + return $otag; + } + + public static function makeTouch($args=[]) { + + require_once('class.mt_touch.php'); + $touch = new Touch(); + $touch->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + $touch->object_type = $args['object_type']; + $touch->modified_on = $args['modified_on'] ?? '20240101122459'; + $touch->save(); + return $touch; + } + + public static function makeRebuildTrigger($args=[]) { + + require_once('class.mt_rebuild_trigger.php'); + $trigger = new RebuildTrigger(); + $trigger->blog_id = $args['blog_id'] ?? self::$last_blog_id ?? 1; + // $trigger->object_type = $type; + $trigger->save(); + return $trigger; + } +} diff --git a/php/tests/UnitTest.php b/php/tests/UnitTest.php index 7ec3ba8108..fe9ae63b46 100644 --- a/php/tests/UnitTest.php +++ b/php/tests/UnitTest.php @@ -2,15 +2,13 @@ use PHPUnit\Framework\TestCase; -include_once("php/lib/captcha_lib.php"); +require_once('captcha_lib.php'); +require_once('Mockdata.php'); class UnitTest extends TestCase { - private $mt; - private $ctx; - public function testWdayFromTs() { - include_once("php/lib/MTUtil.php"); + require_once('MTUtil.php'); // leap year $this->assertEquals(6, wday_from_ts(2000,1,1), 'right wday'); $this->assertEquals(4, wday_from_ts(2000,1,6), 'right wday'); @@ -23,21 +21,163 @@ public function testWdayFromTs() { $this->assertEquals(4, wday_from_ts(2001,3,1), 'right wday'); } + public function testFetchWebsites() { + + $mt = MT::get_instance(); + $sites = $mt->db()->fetch_websites([]); + $this->assertEquals('Blog', get_class($sites[0])); // XXX Consider to fix this to be Website instead + $this->assertEquals(1, $sites[0]->id); + } + + public function testFetchWebsite() { + + $mt = MT::get_instance(); + $site = $mt->db()->fetch_website(1); + $this->assertEquals('Blog', get_class($site)); // XXX Consider to fix this to be Website instead + $this->assertEquals(1, $site->id); + } + + public function testFetch_plugin_data() { + + $mt = MT::get_instance(); + + require_once('class.mt_plugindata.php'); + $plugindata = new PluginData(); + $plugindata->data = $mt->db()->serialize(['foo' => 'fooval', 'bar' => 'barval']); + $plugindata->key = 'configuration:blog:3'; + $plugindata->plugin = 'MyPlugin'; + $plugindata->save(); + + $config = $mt->db()->fetch_plugin_data('MyPlugin', 'configuration:blog:3'); + $this->assertEquals('fooval', $config['foo']); + $this->assertEquals('barval', $config['bar']); + + $config1 = $mt->db()->fetch_plugin_config('MyPlugin', 'blog:3'); + $this->assertEquals('fooval', $config['foo']); + $this->assertEquals('barval', $config['bar']); + } + + public function testFetch_tag() { + + $tag = MockData::makeTag(['name' => 'foo']); + + $mt = MT::get_instance(); + $tag2 = $mt->db()->fetch_tag($tag->id); + $this->assertEquals('Tag', get_class($tag2)); + $this->assertEquals($tag->id, $tag2->id); + + $tag3 = $mt->db()->fetch_tag_by_name($tag->tag_name); + $this->assertEquals('Tag', get_class($tag3)); + $this->assertEquals($tag->id, $tag3->id); + } + + public function testFetch_avg_scores() { + + $oscore = MockData::makeObjectScore(['object_ds' => 'entry']); + $mt = MT::get_instance(); + $score = $mt->db()->fetch_avg_scores('foo', 'entry', 'asc', ''); + $this->assertEquals('ADORecordSet_pdo', get_class($score)); + } + + public function testBlog_ping_count() { + + $blog = Mockdata::makeBlog(['name' => 'MyBlog']); + $entry = Mockdata::makeEntry(); + $category = Mockdata::makeCategory(); + $trackback = MockData::makeTrackback(); + $ping = MockData::makeTbping(); + + $mt = MT::get_instance(); + $count = $mt->db()->blog_ping_count(['blog_id' => $ping->blog_id]); + $this->assertEquals(1, $count); + } + + // @TODO SKIP MTC-29547 + + // public function testTags_entry_count() { + + // $entry = Mockdata::makeEntry(['status' => 2]); + // $tag = MockData::makeTag(['name' => 'foo']); + // $otag = MockData::makeObjectTag(['object_datasource' => 'entry', 'tag_id' => $tag->id]); + + // $mt = MT::get_instance(); + // $count = $mt->db()->tags_entry_count($tag->id); + // $this->assertEquals(1, $count); + // } + + public function testEntry_comment_count() { + + $entry = Mockdata::makeEntry(['status' => 2]); + $comment = Mockdata::makeComment(); + $comment = Mockdata::makeComment(); + + $mt = MT::get_instance(); + $count = $mt->db()->entry_comment_count($entry->id); + $this->assertEquals(2, $count); + } + + public function testEntry_tbping_count() { + + $entry = Mockdata::makeEntry(['status' => 2]); + $tbping = Mockdata::makeTbping(); + $tbping = Mockdata::makeTbping(); + + $mt = MT::get_instance(); + $count = $mt->db()->entry_ping_count($entry->id); + $this->assertEquals(2, $count); + } + + public function testCategory_ping_count() { + + $blog = Mockdata::makeBlog(['name' => 'MyBlog']); + $entry = Mockdata::makeEntry(['status' => 2]); + $category = Mockdata::makeCategory(); + $trackback = Mockdata::makeTrackback(); + $tbping = Mockdata::makeTbping(); + $tbping = Mockdata::makeTbping(); + + $mt = MT::get_instance(); + $count = $mt->db()->category_ping_count($category->id); + $this->assertEquals(2, $count); + + $pings = $mt->db()->fetch_pings(['blog_id' => $blog->id]); + $this->assertEquals('TBPing', get_class($pings[0])); + $this->assertEquals(2, count($pings)); + } + + public function testGet_latest_touch() { + + $blog = Mockdata::makeBlog(['name' => 'MyBlog']); + $entry = Mockdata::makeEntry(['status' => 2]); + $touch = Mockdata::makeTouch(['object_type' => 'author', 'blog_id' => 0]); + $touch = Mockdata::makeTouch(['object_type' => 'entry', 'blog_id' => $blog->id]); + + $mt = MT::get_instance(); + $touches = $mt->db()->get_latest_touch($blog->id, 'author'); + $this->assertEquals('Touch', get_class($touches)); + $touches = $mt->db()->get_latest_touch($blog->id, 'entry'); + $this->assertEquals('Touch', get_class($touches)); + } + + public function testFetch_rebuild_trigger() { + + $blog = Mockdata::makeBlog(['name' => 'MyBlog']); + $trigger = Mockdata::makeRebuildTrigger(); + + $mt = MT::get_instance(); + $trigger2 = $mt->db()->fetch_rebuild_trigger($blog->id); + $this->assertEquals('RebuildTrigger', get_class($trigger2)); + } + public function testFetchPermission() { - include_once("php/mt.php"); - include_once("php/lib/MTUtil.php"); - $cfg_file = realpath( "t/mysql-test.cfg" ); - $this->mt = MT::get_instance(1, $cfg_file); - $this->ctx =& $this->mt->context(); - - error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); - $perm = $this->mt->db()->fetch_permission(array('blog_id' => 1, 'id' => 1)); + + $perm = MT::get_instance()->db()->fetch_permission(array('blog_id' => 1, 'id' => 1)); $this->assertTrue(is_array($perm) && !empty($perm)); $this->assertEquals(1, $perm[0]->blog_id); $this->assertEquals(1, $perm[0]->author_id); $this->assertTrue(preg_match("{'administer_site'}", $perm[0]->permission_permissions) !== false); - - include_once("php/lib/class.mt_author.php"); + + require_once('class.mt_author.php'); $author = new Author; $author->Load(1); $perm2 = $author->permissions(1); @@ -57,7 +197,7 @@ public function testFetchPermission() { $this->assertEquals(1, $perm3[1]->author_id); $this->assertTrue(preg_match("{'administer_site'}", $perm3[1]->permission_permissions) !== false); - include_once("php/lib/class.mt_blog.php"); + require_once('class.mt_blog.php'); $b = new Blog; $b->Load(1); $b->set_values(array('blog_name' => 'test_name', 'blog_site_url' => 'test_url')); @@ -77,19 +217,19 @@ public function testCaptchaLib() { } public function testArchiverFactory() { - include_once("php/lib/archive_lib.php"); + require_once('archive_lib.php'); ArchiverFactory::add_archiver('ContentType', 'ContentTypeArchiver'); $a = ArchiverFactory::get_archiver('ContentType'); $this->assertTrue($a instanceof ArchiveType); } public function testCC() { - include_once("php/lib/cc_lib.php"); + require_once('cc_lib.php'); $this->assertEquals(cc_name('by'), 'Attribution'); } public function testDatetimeToTimestamp() { - include_once("php/lib/MTUtil.php"); + require_once('MTUtil.php'); $ret = datetime_to_timestamp('2005-12-30 23:23:59'); $this->assertEquals(1135952639, $ret); @@ -145,6 +285,36 @@ public function testDaysIn() { $this->assertEquals(31, $ret); // Jan 1970 } } + + public function testAssociation() { + require_once('class.mt_association.php'); + $assoc = new Association(); + $assoc->Load('association_id=1'); + $role = $assoc->role(); + $this->assertEquals('Role', get_class($role)); + $this->assertEquals('1', $role->id); + $this->assertEquals('1', $role->role_id); + } + + public function testFileinfo() { + require_once('class.mt_fileinfo.php'); + require_once('class.mt_category.php'); + $cat = new Category(); + $cat->blog_id = 1; + $cat->category_category_set_id = 1; + $cat->label = 'test'; + $cat->save(); + $finfo = new FileInfo(); + $finfo->blog_id = 1; + $finfo->entry_id = 1; + $finfo->category_id = 1; + $finfo->save(); + $finfo->Load('fileinfo_id=1'); + $cat = $finfo->category(); + $this->assertEquals('Category', get_class($cat)); + $this->assertEquals('1', $cat->id); + $this->assertEquals('1', $cat->category_id); + } } class MyCaptchaProvider implements CaptchaProvider {