Skip to content

Commit

Permalink
feat(field): get field config from passed filter name
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Nov 8, 2016
1 parent b1b7ce3 commit 0629020
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ACFComposer/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class Field {
function __construct($config) {
if(is_string($config)) {
$config = apply_filters($config, null);
}
$this->config = $this->validateConfig($config);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/test-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ACFComposer\TestCase;
use ACFComposer\Field;
use Brain\Monkey\WP\Filters;

class FieldTest extends TestCase {
function testAssignsValidConfig() {
Expand Down Expand Up @@ -53,4 +54,18 @@ function testFailsWithKey() {
$this->expectException(Exception::class);
new Field($config);
}

function testGetConfigFromFilter() {
$config = 'ACFComposer/Fields/someField';
$someField = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
Filters::expectApplied($config)
->once()
->andReturn($someField);
$field = new Field($config);
$this->assertEquals($someField, $field->config);
}
}

0 comments on commit 0629020

Please sign in to comment.