/** * @param integer $count * * @Given /^the grid should contain (\d+) elements?$/ */ public function theGridShouldContainElement($count) { $this->wait(); if ($count > 10) { $this->iChangePageSize(100); } assertEquals($count, $actualCount = $this->datagrid->getToolbarCount(), sprintf('Expecting to see %d record(s) in the datagrid toolbar, actually saw %d', $count, $actualCount)); assertEquals($count, $actualCount = $this->datagrid->countRows(), sprintf('Expecting to see %d row(s) in the datagrid, actually saw %d.', $count, $actualCount)); }
/** * @param TableNode $table * * @Then /^I should be able to use the following filters:$/ * * @return Then[] */ public function iShouldBeAbleToUseTheFollowingFilters(TableNode $table) { $steps = []; foreach ($table->getHash() as $item) { if (isset($item['result'])) { $count = count($this->getMainContext()->listToArray($item['result'])); } $filter = $item['filter']; $isCategoryFilter = false !== strpos(strtolower($filter), 'category'); $countBeforeFilter = null; if (!$isCategoryFilter) { $countBeforeFilter = $this->datagrid->getToolbarCount(); $steps[] = new Step\Then(sprintf('I show the filter "%s"', $filter)); } $steps[] = new Step\Then(sprintf('I filter by "%s" with operator "%s" and value "%s"', $filter, $item['operator'], $item['value'])); if (isset($item['result']) && '' !== $item['result']) { $steps[] = new Step\Then(sprintf('the grid should contain %d elements', $count)); $steps[] = new Step\Then(sprintf('I should see entities %s', $item['result'])); } if (!$isCategoryFilter) { $steps[] = new Step\Then(sprintf('I hide the filter "%s"', $filter)); if (null !== $countBeforeFilter) { /** * At the end of the loop, we ensure we get back to the initial state of the loop. * To do this, we add a validation step checking if the number of initial elements in the datagrid * is the same than the number of elements in the datagrid after removing the filter. * * This has a second effect: it ensure the fact that the datagrid is well loaded. It fixes some * random features, where Metric and Price filters were closed during behat execution, when the * datagrid finished to be load. * * // TODO Refactor this using a comparison with content of the datagrid. */ $steps[] = new Step\Then(sprintf('the grid toolbar count should be %s elements', $countBeforeFilter)); } } } return $steps; }