From 73f92143fcc75b20176aea6388f48d76302f1343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Lunnerg=C3=A5rd?= Date: Fri, 5 Sep 2014 08:17:38 +0200 Subject: [PATCH] Adds tests for posttype struct loading --- README.md | 2 +- src/PostExtender.php | 10 ++++------ tests/PostExtenderStructTest.php | 13 ++++++++++++- tests/data/posttypes/post.json | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 tests/data/posttypes/post.json diff --git a/README.md b/README.md index 2097fcf..04eeb9b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/PostExtender.php b/src/PostExtender.php index 413ee2e..8f9e0b6 100644 --- a/src/PostExtender.php +++ b/src/PostExtender.php @@ -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; } diff --git a/tests/PostExtenderStructTest.php b/tests/PostExtenderStructTest.php index f1418a9..96d5b95 100644 --- a/tests/PostExtenderStructTest.php +++ b/tests/PostExtenderStructTest.php @@ -1,9 +1,15 @@ MF_FILES_URL, + 'files_dir' => MF_FILES_DIR, + 'struct_dir' => __DIR__ . '/data/posttypes' + ])); } public function testStruct() { @@ -11,4 +17,9 @@ public function testStruct() { $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'])); + } } diff --git a/tests/data/posttypes/post.json b/tests/data/posttypes/post.json new file mode 100644 index 0000000..a050ef4 --- /dev/null +++ b/tests/data/posttypes/post.json @@ -0,0 +1,14 @@ +{ + "name" : "post", + "singular" : "Sida", + "plural" : "Sidor", + "parent" : "ui_category", + "has_page" : true, + "single" : true, + "rewrite" : "sida", + "groups" : [ + { + + } + ] +}