/** * Receives a possibly dirty user input string and stores it in an * instance of Wikia\Search\Query\Select. * Uses the methods within that class to determine if we need to * record a specific namespace associated with that query. * * @param string $query * @return \Wikia\Search\Config provides fluent interface */ public function setQuery($query) { $this->query = new Query($query); $namespace = $this->query->getNamespaceId(); if ($namespace !== null) { $namespaces = $this->getNamespaces(); if (empty($namespaces) || !in_array($namespace, $namespaces)) { $this->queryNamespace = $namespace; } } return $this; }
/** * @group Slow * @slowExecutionTime 0.09147 ms * @covers Wikia\Search\Query\Select::initializeNamespaceData * @covers Wikia\Search\Query\Select::getNamespacePrefix * @covers Wikia\Search\Query\Select::getNamespaceId */ public function testNamespaceLogic() { $query = new Query('ThisIsNotANamespace:Bar'); $this->assertNull($query->getNamespaceId()); $this->assertNull($query->getNamespacePrefix()); $query = new Query('Category:Things That Are Namespaces'); $this->assertEquals(NS_CATEGORY, $query->getNamespaceId()); $this->assertEquals('Category', $query->getNamespacePrefix()); }