/** * Creates a sub context of the given name * @param string $name the context name * @param string $id the id of the new context * @return Context The created context */ public function createContext($name, $id = null) { $context = new Context($name, $id); $id = $context->id(); // add selectors foreach ($this->_selectors as $key => $selector) { $parts = explode(' ', $key); // handle nested selectors $first = array_shift($parts); if (count($parts) > 0 && $context->applies($first)) { $key = implode(' ', $parts); } $context->_selectors[$key] = $selector; } // add tags and ids $context->_tags = $this->_tags; $context->_ids = $this->_ids; // add content $context->_content = $this->_content; $content = $this->getContent(); if (is_array($content) && isset($content[$id])) { $content = $content[$id]; } $context->setContent($name, $content); self::$_log[] = '[Context] Creating context ' . $name . ' with id ' . $id; return $context; }
public function testComputedTags() { $context = new Context('name'); $context->addComputedTag('first'); $this->assertTrue($context->applies('name:first')); }