diff --git a/config/schema/replication.replication_settings.schema.yml b/config/schema/replication.replication_settings.schema.yml index 86c6fcc..b3fedc1 100644 --- a/config/schema/replication.replication_settings.schema.yml +++ b/config/schema/replication.replication_settings.schema.yml @@ -12,5 +12,5 @@ replication.replication_settings.*: type: string label: 'Filter plugin id' parameters: - type: sequence + type: ignore label: 'Filter parameters' diff --git a/src/Plugin/ReplicationFilter/EntityTypeFilter.php b/src/Plugin/ReplicationFilter/EntityTypeFilter.php index ce588aa..794a012 100644 --- a/src/Plugin/ReplicationFilter/EntityTypeFilter.php +++ b/src/Plugin/ReplicationFilter/EntityTypeFilter.php @@ -25,9 +25,24 @@ class EntityTypeFilter extends ReplicationFilterBase { * {@inheritdoc} */ public function filter(EntityInterface $entity, ParameterBag $parameters) { - $type_ids = $this->parseParameterValues($parameters, 'entity_type_id'); + $entity_type_ids = $this->parseParameterValues($parameters, 'entity_type_id'); $bundles = $this->parseParameterValues($parameters, 'bundle'); - return in_array($entity->getEntityTypeId(), $type_ids) && in_array($entity->bundle(), $bundles); + + // Ensure length of entity_type_ids and bundles are equal. + if (count($entity_type_ids) != count($bundles)) { + return FALSE; + } + + $entity_type_id = $entity->getEntityTypeId(); + $bundle = $entity->bundle(); + + for ($i = 0; $i < count($entity_type_ids); $i++) { + if ($entity_type_ids[$i] == $entity_type_id && $bundles[$i] == $bundle) { + return TRUE; + } + } + + return FALSE; } /** diff --git a/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php b/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php index 4d97d94..2ed7f16 100644 --- a/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php +++ b/tests/src/Unit/Plugin/ReplicationFilter/EntityTypeFilterTest.php @@ -16,9 +16,16 @@ class EntityTypeFilterTest extends \PHPUnit_Framework_TestCase { /** * Test filtering entity types. * + * @param string $entity_type_id + * The entity type id filter parameter. + * @param string $bundle + * The bundle filter parameter. + * @param string $expected + * The expected return value from the filter method. + * * @dataProvider filterTestProvider */ - public function testFilter($entity_type, $parameter_value, $expected) { + public function testFilter($entity_type_id, $bundle, $expected) { // Use a mock builder for the class under test to eliminate the need to // mock all the dependencies. This is OK since the method under test is a // pure function, i.e. does not use the state createdy by the constructor. @@ -27,9 +34,11 @@ class EntityTypeFilterTest extends \PHPUnit_Framework_TestCase { ->setMethods(NULL) ->getMock(); $entity = $this->getMock(EntityInterface::class); + $entity->method('getEntityTypeId') + ->willReturn('node'); $entity->method('bundle') ->willReturn('article'); - $parameters = new ParameterBag(['entity_type' => $parameter_value]); + $parameters = new ParameterBag(['entity_type_id' => $entity_type_id, 'bundle' => $bundle]); $value = $filter->filter($entity, $parameters); @@ -37,23 +46,26 @@ class EntityTypeFilterTest extends \PHPUnit_Framework_TestCase { } /** - * Provide test cases for the "entity_type" parameter. + * Provide test cases for the "entity_type_id" and "bundle" parameters. */ public function filterTestProvider() { return [ // Test singular parameter values. - ['article', 'article', TRUE], - ['article', 'page', FALSE], + ['node', 'article', TRUE], + ['node', 'page', FALSE], // Test multiple parameter values. - ['article', 'page,article', TRUE], - ['article', 'article,page', TRUE], - ['article', 'page,news', FALSE], + ['node,node', 'page,article', TRUE], + ['node,node', 'article,page', TRUE], + ['node,node', 'page,news', FALSE], + // Test mismatched multiple parameter values. + ['node', 'page,article', FALSE], + ['node,node', 'node', FALSE], // Test bad data that might be entered into the parameters: - ['article', '', FALSE], - ['article', NULL, FALSE], - ['article', FALSE, FALSE], - ['article', TRUE, FALSE], - ['article', 0, FALSE], + ['', '', FALSE], + [NULL, NULL, FALSE], + [FALSE, FALSE, FALSE], + [TRUE, TRUE, FALSE], + [0, 0, FALSE], ]; }