Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgrainger committed Nov 16, 2024
1 parent e37ce1d commit 5b812fd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
54 changes: 52 additions & 2 deletions tests/ColumnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,33 @@ public function canSetColumns()
}

/** @test */
public function canAddColumns()
public function canAddColumnsWithArray()
{
$columns = [
'genre' => 'Genre'
'genre' => 'Genre',
];

$this->columns->add($columns);

$this->assertEquals($this->columns->add, $columns);
}

/** @test */
public function canAddColumnsWithArgs()
{
$this->columns->add('genre', 'Genre');

// Auto generated label1
$this->columns->add('price');

$expected = [
'genre' => 'Genre',
'price' => 'Price',
];

$this->assertEquals($this->columns->add, $expected);
}

/** @test */
public function canHideColumns()
{
Expand Down Expand Up @@ -209,4 +225,38 @@ public function canModifyColumns()

$this->assertEquals($output, $expected);
}

/** @test */
public function canIdentifySortableColumns()
{
$columns = [
'rating' => ['_rating', true],
'price' => '_price',
'sortable' => ['sortable'],
];

$this->columns->sortable($columns);

$this->assertTrue($this->columns->isSortable('_rating'));
$this->assertTrue($this->columns->isSortable('_price'));
$this->assertTrue($this->columns->isSortable('sortable'));
$this->assertFalse($this->columns->isSortable('not_a_column'));
}

/** @test */
public function returnsCorrectSortableMetaKey()
{
$columns = [
'rating' => ['_rating', true],
'price' => '_price',
'column' => ['sortable'],
];

$this->columns->sortable($columns);

$this->assertEquals($this->columns->sortableMeta('rating'), ['_rating', true]);
$this->assertEquals($this->columns->sortableMeta('_price'), '_price');
$this->assertEquals($this->columns->sortableMeta('sortable'), ['sortable']);
$this->assertEquals($this->columns->sortableMeta('not_a_column'), '');
}
}
38 changes: 38 additions & 0 deletions tests/PostTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ public function namesCreatedFromName()
$this->assertEquals($this->books->slug, 'books');
}

/** @test */
public function smartNamesCreatedFromName()
{
$story = new PostType('story');

$this->assertEquals($story->name, 'story');
$this->assertEquals($story->singular, 'Story');
$this->assertEquals($story->plural, 'Stories');
$this->assertEquals($story->slug, 'stories');
}

/** @test */
public function passedNamesAreUsed()
{
Expand Down Expand Up @@ -197,6 +208,33 @@ public function defaultOptionsUsedIfNotSet()
$this->assertEquals($options, $defaults);
}

/** @test */
public function optionsGeneratedCorrectly()
{
// Set custom options
$this->books->options([
'public' => false,
]);

// Set option with helper method
$this->books->icon('dashicon-book-alt');

// generated options
$options = $this->books->createOptions();

// expected options
$expected = [
'public' => false,
'labels' => $this->books->createLabels(),
'menu_icon' => $this->books->icon,
'rewrite' => [
'slug' => $this->books->slug
]
];

$this->assertEquals($options, $expected);
}

/** @test */
public function defaultLabelsAreGenerated()
{
Expand Down

0 comments on commit 5b812fd

Please sign in to comment.