/** * Update the currently processed CSS selector by prefixing it * with the appropriate id. */ protected function updateSelector() { $buffer = implode('', $this->getBuffer()); if (strpos($buffer, ',') === false) { // Do not rescope if already scoped! if (strpos($buffer, '#' . $this->getId()) === false) { $buffer = $this->doesMapQtiClasses() === true ? CssUtils::mapSelector($buffer, self::getQtiClassMapping()) : $buffer; $this->output('#' . $this->getId() . ' ' . $buffer . '{'); } else { $this->output($buffer . '{'); } } else { $classes = explode(',', $buffer); $newClasses = array(); foreach ($classes as $c) { // Same as above, do not rescope if already scoped... if (strpos($c, '#' . $this->getId()) === false) { $c = $this->doesMapQtiClasses() === true ? CssUtils::mapSelector($c, self::getQtiClassMapping()) : $c; $newC = '#' . $this->getId() . ' ' . trim($c); $newC = str_replace(trim($c), $newC, $c); } else { $newC = $c; } $newClasses[] = $newC; } $this->output(implode(',', $newClasses) . '{'); } }
/** * @dataProvider mapSelectorProvider * * @param string $expected * @param string $selector * @param array $map */ public function testMapSelector($selector, $expected, array $map) { $this->assertEquals($expected, CssUtils::mapSelector($selector, $map)); }