public function renderSectionBody(array $section, DataCollection $collection, array $sections = [], $sectionName = '') { if ($this->isSilent()) { return $this; } $division = $collection->getDefaultProperties(); $ua = $division->getUserAgents(); $defaultproperties = $ua[0]['properties']; $properties = array_merge(['Parent'], array_keys($defaultproperties)); foreach ($defaultproperties as $propertyName => $propertyValue) { $defaultproperties[$propertyName] = $this->expander->trimProperty($propertyValue); } $propertiesToOutput = []; foreach ($properties as $property) { if (!isset($section[$property])) { continue; } if (!isset($this->outputProperties[$property])) { $this->outputProperties[$property] = $this->getFilter()->isOutputProperty($property, $this); } if (!$this->outputProperties[$property]) { continue; } if (isset($section['Parent']) && 'Parent' !== $property) { if ('DefaultProperties' === $section['Parent'] || !isset($sections[$section['Parent']])) { if (isset($defaultproperties[$property]) && $defaultproperties[$property] === $section[$property]) { continue; } } else { $parentProperties = $sections[$section['Parent']]; if (isset($parentProperties[$property]) && $parentProperties[$property] === $section[$property]) { continue; } } } $propertiesToOutput[$property] = $section[$property]; } fputs($this->file, $this->getFormatter()->formatPropertyValue(json_encode($propertiesToOutput), 'Comment')); return $this; }
/** * tests rendering the body of one section * * @group writer * @group sourcetest */ public function testRenderSectionBodyIfSilent() { $this->object->setSilent(true); $section = array('Test' => 1, 'isTest' => true, 'abc' => 'bcd'); $mockCollection = $this->getMock('\\Browscap\\Data\\DataCollection', array(), array(), '', false); self::assertSame($this->object, $this->object->renderSectionBody($section, $mockCollection)); self::assertSame('', file_get_contents($this->file)); }