/** * test case for api call if post values are there * * @covers AppBundle\Controller\DemoController::indexAction */ public function testindexAction() { $defaultData = array('message' => 'Enter City Name Or Country Name For Weather'); $dataArray = array('countryname' => 'United States', 'cityname' => 'New york'); $weatherarray = array('Location' => 'ROOSEVELT ROADS PUERTO RICO, PR, United States (TJNR) 18-15N 65-38W 10M', 'Time' => 'Jul 15, 2015 - 05:53 PM EDT / 2015.07.15 2153 UTC', 'Wind' => 'from the ENE (060 degrees) at 12 MPH (10 KT) gusting to 20 MPH (17 KT):0', 'Visibility' => '10 mile(s):0', 'SkyConditions' => 'mostly cloudy', 'Temperature' => '84.0 F (28.9 C)', 'DewPoint' => '75.0 F (23.9 C)', 'RelativeHumidity' => '74%', 'Pressure' => '30.05 in. Hg (1017 hPa)', 'Status' => 'Success'); $this->mockController->expects($this->once())->method('createFormBuilder')->with($this->equalTo($defaultData))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(0))->method('add')->with($this->equalTo('countryname'), $this->equalTo('text'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(1))->method('add')->with($this->equalTo('cityname'), $this->equalTo('text'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->at(2))->method('add')->with($this->equalTo('search'), $this->equalTo('submit'))->will($this->returnValue($this->mockFormBuilder)); $this->mockFormBuilder->expects($this->once())->method('getForm')->will($this->returnValue($this->mockForm)); $this->mockRequest->expects($this->once())->method('isMethod')->with($this->equalTo('POST'))->will($this->returnValue(true)); $this->mockForm->expects($this->once())->method('bind')->with($this->mockRequest); $this->mockForm->expects($this->once())->method('getData')->will($this->returnValue($dataArray)); $this->mockController->expects($this->once())->method('get')->with($this->equalTo('api.weather.handler'))->will($this->returnValue($this->mockService)); $this->mockService->expects($this->once())->method('soapClientCall')->with($this->equalTo('United States'), $this->equalTo('New york'))->will($this->returnValue($weatherarray)); $this->mockController->expects($this->once())->method('render')->with($this->equalTo('AppBundle:Demo:index.html.twig'), $this->equalTo(array('weather' => $weatherarray))); $this->mockController->indexAction($this->mockRequest); }
/** * Returns data for given parameters * * @param entity object $article Article * @param Symfony\Component\Form\Form $form Form * @param bool $status Article of the day status * @param bool $success Shows success message * @param entity object $articleOfTheDay Article of the day * * @return array */ private function returnData($article, $form, $status, $success, $articleOfTheDay) { $em = $this->container->get('em'); $query = ""; $publicationNumbers = explode(',', $articleOfTheDay->getPublicationNumbers()); foreach ($publicationNumbers as $value) { $query .= 'p.id = ' . $value . ' OR '; } $publications = $em->getRepository('Newscoop\\Entity\\Publication')->createQueryBuilder('p')->where(substr($query, 0, -4))->getQuery()->getResult(); foreach ($publications as $publication) { $publicationsArray[] = $publication->getName(); } return $this->container->get('templating')->renderResponse('NewscoopArticlesCalendarBundle:Hooks:hook_content.html.twig', array('article' => $article, 'form' => $form->createView(), 'status' => $status, 'success' => $success, 'articleOfTheDay' => $articleOfTheDay, 'publicationsNames' => $publicationsArray)); }
/** * Adds a new Contribution Type * * @param Symfony\Component\Form\Form $form * @param Contribution $entity */ protected function selectOtherContributionType($form, $entity) { // Check that no type selected if ($form->get('type')->getData() !== 'Outro') { return; } //Get 'other' type $otherType = $form->get('typeOther')->getData(); //Validate if ($projectName === null) { $form->addError(new FormError('Selecione um tipo de contribuição ou forneça um não listado')); } //Define $entity->setType($otherType); }