Ejemplo n.º 1
0
 /**
  * @Given /^I "([^"]*)" the user$/
  */
 public function iUpdateTheUser($buttonLabel)
 {
     $label = strtolower($buttonLabel);
     $elements = $this->getPage()->findAll('css', 'a.btn');
     $didFindButton = false;
     $button = null;
     foreach ($elements as $element) {
         if (strtolower($element->getText()) == $label) {
             $didFindButton = true;
             $button = $element;
         }
     }
     WebTestCase::assertTrue($didFindButton, "the ban button was not found.");
     $button->click();
 }
 /**
  * @Given /^I should be logged in$/
  */
 public function iShouldBeLoggedIn()
 {
     WebTestCase::assertTrue($this->kernel->getContainer()->get('security.context')->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\UserInterface);
 }
 /**
  *
  * @Given /^I select from "([^"]*)" a date "([^"]*)"$/
  */
 public function iSelectFromADateDaysFromNow($cssQuery, $diff)
 {
     $items = $this->getPage()->findAll('css', $cssQuery);
     $fields = array();
     foreach ($items as $item) {
         $id = $item->getAttribute('id');
         if (substr($id, strlen($id) - strlen('year'), strlen($id)) == 'year') {
             $fields['year'] = $item;
             continue;
         }
         if (substr($id, strlen($id) - strlen('month'), strlen($id)) == 'month') {
             $fields['month'] = $item;
             continue;
         }
         if (substr($id, strlen($id) - strlen('day'), strlen($id)) == 'day') {
             $fields['day'] = $item;
             continue;
         }
     }
     WebTestCase::assertCount(3, $fields, 'Date fields could not be found!');
     WebTestCase::assertArrayHasKey('year', $fields, 'The year field could not be found!');
     WebTestCase::assertArrayHasKey('month', $fields, 'The month field could not be found!');
     WebTestCase::assertArrayHasKey('day', $fields, 'The day field could not be found!');
     $date = new \Datetime($diff);
     $filterFunc = function ($options, $has) {
         foreach ($options as $option) {
             if ($option->getText() == $has) {
                 return true;
             }
         }
         return false;
     };
     WebTestCase::assertTrue(call_user_func_array($filterFunc, array($fields['year']->findAll('css', 'option'), $date->format('Y'))));
     WebTestCase::assertTrue(call_user_func_array($filterFunc, array($fields['month']->findAll('css', 'option'), $date->format('M'))));
     WebTestCase::assertTrue(call_user_func_array($filterFunc, array($fields['day']->findAll('css', 'option'), $date->format('j'))));
     $fields['year']->selectOption($date->format('Y'));
     $fields['month']->selectOption($date->format('M'));
     $fields['day']->selectOption($date->format('j'));
 }