Skip to content

Commit

Permalink
add PostTypeRegistrar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgrainger committed Oct 24, 2024
1 parent 5294c65 commit 7e950e7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
6 changes: 3 additions & 3 deletions src/Registrars/PostTypeRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function register()
// modify filters on the admin edit screen
add_action('restrict_manage_posts', [$this, 'modifyFilters'], 10, 1);

if (isset($this->columns)) {
if (isset($this->posttype->columns)) {
// modify the admin edit columns.
add_filter('manage_' . $name . '_posts_columns', [$this, 'modifyColumns'], 10, 1);

Expand Down Expand Up @@ -85,7 +85,7 @@ public function modifyPostType(array $args, string $posttype)
*/
public function registerTaxonomies()
{
if (empty($this->taxonomies)) {
if (empty($this->posttype->taxonomies)) {
return;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public function modifyColumns($columns)
*/
public function populateColumns($column, $post_id)
{
if (isset($this->columns->populate[$column])) {
if (isset($this->posttype->columns->populate[$column])) {
call_user_func_array($this->posttype->columns()->populate[$column], [$column, $post_id]);
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Registrars/PostTypeRegistrarTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use PHPUnit\Framework\TestCase;
use PostTypes\PostType;
use PostTypes\Registrars\PostTypeRegistrar;

class PostTypeRegistrarTest extends TestCase
{
/** @test */
public function canModifyPostType()
{
$posttype = new PostType('post', [
'public' => false,
]);

$registrar = new PostTypeRegistrar($posttype);

$options = $registrar->modifyPostType([
'public' => true,
], 'post');

$this->assertEquals(false, $options['public']);
}
}

0 comments on commit 7e950e7

Please sign in to comment.