Skip to content

Commit

Permalink
Merge 42cb0ee into c8e5568
Browse files Browse the repository at this point in the history
  • Loading branch information
jarednova committed Jun 16, 2016
2 parents c8e5568 + 42cb0ee commit 7f2b034
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function import( $info, $force = false ) {
}
if ( is_array($info) ) {
foreach ( $info as $key => $value ) {
if ( $key === '' || ord( $key[0] ) === 0 ) {
continue;
}
if ( !empty($key) && $force ) {
$this->$key = $value;
} else if ( !empty($key) && !method_exists($this, $key) ) {
Expand Down Expand Up @@ -114,4 +117,4 @@ public function get_method_values() {
$ret['can_edit'] = $this->can_edit();
return $ret;
}
}
}
5 changes: 4 additions & 1 deletion lib/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public function __toString() {
protected function init( $post_type ) {
$obj = get_post_type_object($post_type);
foreach (get_object_vars($obj) as $key => $value) {
if ( $key === '' || ord( $key[0] ) === 0 ) {
continue;
}
$this->$key = $value;
}
}

}
}
15 changes: 15 additions & 0 deletions tests/test-timber-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ function foo() {
}
}

class IHavePrivates {

public $foo = 'foo';
private $bar = 'bar';
}

class TestTimberCore extends Timber_UnitTestCase {

function testCoreImport() {
Expand All @@ -22,4 +28,13 @@ function testCoreImport() {
$this->assertEquals('Drebin', $tc->frank);
}

function testCoreImportWithPrivateProperties() {
$post_id = $this->factory->post->create();
$tc = new TimberPost($post_id);
$object = new IHavePrivates();
$tc->import($object);
$this->assertEquals($tc->foo, 'foo');
$this->assertEquals($tc->bar, false);
}

}

0 comments on commit 7f2b034

Please sign in to comment.