public function testComponentRestrictionsWithValidComponentRestrictions() { $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'fr'); $this->autocomplete->setComponentRestrictions($componentRestrictions); $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); $this->assertTrue($this->autocomplete->hasComponentRestrictions()); $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); $this->assertTrue($this->autocomplete->hasComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); $this->assertSame($componentRestrictions[AutocompleteComponentRestriction::COUNTRY], $this->autocomplete->getComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); }
/** * Renders the autocomplete. * * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. * * @return string The JS output. */ public function renderAutocomplete(Autocomplete $autocomplete) { $this->jsonBuilder->reset(); if ($autocomplete->hasTypes()) { $this->jsonBuilder->setValue('[types]', $autocomplete->getTypes()); } if ($autocomplete->hasBound()) { $this->jsonBuilder->setValue('[bounds]', $autocomplete->getBound()->getJavascriptVariable(), false); } if ($autocomplete->hasComponentRestrictions()) { $this->jsonBuilder->setValue('[componentRestrictions]', $autocomplete->getComponentRestrictions()); } if (!$this->jsonBuilder->hasValues()) { $this->jsonBuilder->setJsonEncodeOptions(JSON_FORCE_OBJECT); } return sprintf('%s = new google.maps.places.Autocomplete(document.getElementById(\'%s\'), %s);' . PHP_EOL, $autocomplete->getJavascriptVariable(), $autocomplete->getInputId(), $this->jsonBuilder->build()); }