Skip to content

Commit

Permalink
feat(ResolveConfig): apply resolveEntity filters
Browse files Browse the repository at this point in the history
  • Loading branch information
domtra committed Nov 8, 2016
1 parent 43b3b0a commit 66d7596
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ACFComposer/ResolveConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ protected static function forEntity($config, $requiredAttributes, $parentKeySuff

$keySuffix = empty($parentKeySuffix) ? $output['name'] : "{$parentKeySuffix}_{$output['name']}";
$output['key'] = "field_{$keySuffix}";

$output = apply_filters('ACFComposer/resolveEntity', $output);
$output = apply_filters("ACFComposer/resolveEntity?name={$output['name']}", $output);
$output = apply_filters("ACFComposer/resolveEntity?key={$output['key']}", $output);

$output = self::forNestedEntities($output, $keySuffix);
return $output;
}
Expand Down
54 changes: 54 additions & 0 deletions tests/test-resolveConfigForField.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,58 @@ function testForFieldWithValidLayout() {
$layoutConfig['key'] = 'field_someField_someLayout';
$this->assertEquals($layoutConfig, $output['layouts'][0]);
}

function testAppliesResolveFilterGeneric() {
$config = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
$resolvedConfig = $config;
$resolvedConfig['key'] = 'field_someField';
Filters::expectApplied('ACFComposer/resolveEntity')
->once()
->with($resolvedConfig)
->andReturn(array_merge($resolvedConfig, ['foo' => 'bar']));

$output = ResolveConfig::forField($config);
$resolvedConfig['foo'] = 'bar';
$this->assertEquals($resolvedConfig, $output);
}

function testAppliesResolveFilterByName() {
$config = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
$resolvedConfig = $config;
$resolvedConfig['key'] = 'field_someField';
Filters::expectApplied('ACFComposer/resolveEntity?name=someField')
->once()
->with($resolvedConfig)
->andReturn(array_merge($resolvedConfig, ['foo' => 'bar']));

$output = ResolveConfig::forField($config);
$resolvedConfig['foo'] = 'bar';
$this->assertEquals($resolvedConfig, $output);
}

function testAppliesResolveFilterByKey() {
$config = [
'name' => 'someField',
'label' => 'Some Field',
'type' => 'someType'
];
$resolvedConfig = $config;
$resolvedConfig['key'] = 'field_someField';
Filters::expectApplied('ACFComposer/resolveEntity?key=field_someField')
->once()
->with($resolvedConfig)
->andReturn(array_merge($resolvedConfig, ['foo' => 'bar']));

$output = ResolveConfig::forField($config);
$resolvedConfig['foo'] = 'bar';
$this->assertEquals($resolvedConfig, $output);
}
}

0 comments on commit 66d7596

Please sign in to comment.