Skip to content

Commit

Permalink
Merge pull request #189 from jgrossi/dev
Browse files Browse the repository at this point in the history
Merging from dev for 1.1.2
  • Loading branch information
jgrossi committed Aug 5, 2016
2 parents 486e921 + 7d9ecc6 commit cb273d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,10 @@ public function getKeywordsStrAttribute()
*/
public function newFromBuilder($attributes = [], $connection = null)
{
if (array_key_exists($attributes->post_type, static::$postTypes)) {
if (is_object($attributes) && array_key_exists($attributes->post_type, static::$postTypes)) {
$class = static::$postTypes[$attributes->post_type];
} elseif (is_array($attributes) && array_key_exists($attributes['post_type'], static::$postTypes)) {
$class = static::$postTypes[$attributes['post_type']];
} else {
$class = get_called_class();
}
Expand Down
21 changes: 21 additions & 0 deletions tests/PostTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Corcel\Post;
use Corcel\Page;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

class Video extends Post
{
}

class PostTypeTest extends PHPUnit_Framework_TestCase
{
public function testPostTypeConstructor()
{
Post::registerPostType('video', 'Video');

$post = new Post();
$model = $post->newFromBuilder(['post_type' => 'video']);
$this->assertInstanceOf("Video", $model);
}
}

0 comments on commit cb273d1

Please sign in to comment.