Skip to content

Commit

Permalink
Adds tests for posttype struct loading
Browse files Browse the repository at this point in the history
  • Loading branch information
doctordesh committed Sep 5, 2014
1 parent 3610f3c commit 73f9214
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Extends posts, pages and any custom post type with all it's meta data in one ext

### Versions

Current version is v1.0-rc2
Current version is v1.0-rc3

### Setup

Expand Down
10 changes: 4 additions & 6 deletions src/PostExtender.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ public function permalink() {
}

public static function loadAllPostTypes() {
if(!self::$structs) {
$post_types = [];
foreach(glob(self::$config->getStructDir() . '/*.json') as $post_type) {
$post_type_name = pathinfo($post_type);
$post_types[$post_type_name['filename']] = new Struct($post_type);
foreach(glob(self::$config->getStructDir() . '/*.json') as $struct_file) {
$post_type = pathinfo($struct_file, PATHINFO_FILENAME);
if(!isset(self::$structs[$post_type])) {
self::$structs[$post_type] = new Struct($struct_file);
}
self::$structs = $post_types;
}
return self::$structs;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/PostExtenderStructTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php

use \GoBrave\PostExtender\PostExtender;

class PostExtenderStructTest extends PHPUnit_Framework_TestCase
{
public function setUp() {

PostExtender::setConfig(new GoBrave\PostExtender\Config([
'files_url' => MF_FILES_URL,
'files_dir' => MF_FILES_DIR,
'struct_dir' => __DIR__ . '/data/posttypes'
]));
}

public function testStruct() {
$post = Page::find(2);
$struct = $post->getStruct();
$this->assertTrue($struct instanceof GoBrave\PostExtender\Struct, '$struct is instance of Struct');
}

public function testLoadAll() {
$a = PostExtender::loadAllPostTypes();
$this->assertTrue(isset($a['page']));
}
}
14 changes: 14 additions & 0 deletions tests/data/posttypes/post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name" : "post",
"singular" : "Sida",
"plural" : "Sidor",
"parent" : "ui_category",
"has_page" : true,
"single" : true,
"rewrite" : "sida",
"groups" : [
{

}
]
}

0 comments on commit 73f9214

Please sign in to comment.