forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-core.php
64 lines (51 loc) · 1.55 KB
/
test-timber-core.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
<?php
class TimberCoreTester extends Timber\Post
{
public $public = 'public A';
protected $protected = 'protected A';
private $private = 'private A';
public $existing = 'value from A';
public function foo()
{
return 'bar';
}
}
class ClassB
{
public $public = 'public B';
protected $protected = 'protected B';
private $private = 'private B';
public $existing = 'value from B';
}
class TestTimberCore extends Timber_UnitTestCase
{
public function testCoreImport()
{
$this->register_post_classmap_temporarily([
'post' => TimberCoreTester::class,
]);
$post_id = $this->factory->post->create();
$tc = Timber::get_post($post_id);
$object = new stdClass();
$object->frank = 'Drebin';
$object->foo = 'Dark Helmet';
$tc->import($object);
$this->assertEquals('Drebin', $tc->frank);
$this->assertEquals('bar', $tc->foo);
$tc->import($object, true);
$this->assertEquals('Dark Helmet', $tc->foo);
$this->assertEquals('Drebin', $tc->frank);
}
public function testCoreImportWithPropertyTypes()
{
$this->register_post_classmap_temporarily([
'post' => TimberCoreTester::class,
]);
$post_id = $this->factory->post->create();
$tc = Timber::get_post($post_id);
$object = new ClassB();
$tc->import((object) (array) $object);
$this->assertEquals('public B', $tc->public);
$this->assertEquals('value from B', $tc->existing);
}
}