public function ajax_getSuggestionByCoordinates(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response) { $lat = $params->getFloat('lat'); $lon = $params->getFloat('lon'); $location = CM_Model_Location::findByCoordinates($lat, $lon); $location = $this->_squashLocationInConstraints($location); if (!$location) { throw new CM_Exception('Cannot find a location by coordinates `' . $lat . '` / `' . $lon . '`.'); } return $this->getSuggestion($location, $response->getRender()); }
public function testGetFloat() { $testDataList = array(array(34.28, 34.28), array(-34.28, -34.28), array(0.0, 0.0), array(-34.0, -34), array(34.0, 34), array(0.0, 0), array(34.28, '34.28'), array(-34.28, '-34.28'), array(34.2, '34.2'), array(-34.2, '-34.2'), array(34.0, '34.'), array(-34.0, '-34.'), array(4.28, '4.28'), array(-4.28, '-4.28'), array(0.28, '.28'), array(-0.28, '-.28'), array(0.28, '0.28'), array(-0.28, '-0.28'), array(0.0, '0.'), array(0.0, '-0.'), array(0.0, '.0'), array(0.0, '-.0'), array(34.0, '34'), array(-34.0, '-34'), array(0.0, '0'), array(0.0, '-0')); foreach ($testDataList as $testData) { $expected = $testData[0]; $userInput = $testData[1]; $params = new CM_Params(array('userInput' => $userInput)); $this->assertSame($expected, $params->getFloat('userInput')); } $userInputInvalidList = array('', '-', '.', '-.', '1.2.3', '12 ', ' 12', '12,345', false, true, array('1'), new stdClass(), fopen(__FILE__, 'r')); foreach ($userInputInvalidList as $userInputInvalid) { $params = new CM_Params(array('userInput' => $userInputInvalid)); try { $params->getFloat('userInput'); $this->fail('User input is not a float'); } catch (CM_Exception_InvalidParam $e) { $this->assertTrue(true); } } }