/** * Checks if group from path is declared in manifest. * Manifest is valid if path ends with: configuration/website/[group], * where group is declared in manifest. * * @param \DOMDocument $xml * @param Path $path * @return bool */ public function isValidForPath(\DOMDocument $xml, Path $path) { $allowedGroups = []; $groupsNode = $xml->getElementsByTagName('allowed_groups'); if (!$groupsNode->length) { return false; } // get all allowed group for manifest foreach ($groupsNode->item(0)->childNodes as $group) { if ($group->nodeName === 'group') { $allowedGroups[] = (string) $group->textContent; } } $search = $path->getDirectory() . '/' . $path->getGroup(); $pattern = "#{$search}[/]?\$#"; // skip if group is invalid (allowed groups from manifest) // or if config do not ends with configuration/[website]/[group] if (!in_array($path->getGroup(), $allowedGroups) || 1 !== preg_match($pattern, $path->getParamPath(), $matches)) { return false; } return true; }
/** * @covers ::getGroup * @covers ::_processPath */ public function test_getGroup_should_return_proper_value() { $paramPath = 'configuration/eset/prep/'; $path = new Path($paramPath, '/base/absolute', 'rootdir'); $this->assertEquals('prep', $path->getGroup()); }