-
Notifications
You must be signed in to change notification settings - Fork 110
/
BaseObjectTest.php
104 lines (84 loc) · 3.31 KB
/
BaseObjectTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
use PHPUnit\Framework\TestCase;
class BaseObjectTest extends TestCase {
private static $_cache_driver;
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) {
if (empty($key))
return;
$meta_table = $obj->_table . '_meta';
$obj->$meta_table = array();
$this->cache_driver()->set($key, $obj);
}
private function load_cache($key) {
if (empty($key))
return null;
return $this->cache_driver()->get($key);
}
private function cache_driver() {
if (empty(self::$_cache_driver)) {
require_once('class.basecache.php');
try {
self::$_cache_driver = CacheProviderFactory::get_provider('memcached');
} catch (Exception $e) {
# Memcached not supported.
self::$_cache_driver = CacheProviderFactory::get_provider('memory');
}
}
return self::$_cache_driver;
}
}
?>