Skip to content

Commit

Permalink
full test coverage for request filter feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed May 30, 2017
1 parent 1c89ceb commit 45f414e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
40 changes: 35 additions & 5 deletions Tests/Controller/RequestParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public function setUp()
$this->initClient(array('environment' => 'default_backend'));
}

public function testRequestSingleSimpleFilterIsApplied()
public function testRequestSingleFilterIsApplied()
{
$crawler = $this->requestListView('Product', array('entity.enabled' => false));

$this->assertSame(10, $crawler->filter('#main tr[data-id]')->count());
}

public function testRequestManySimpleFiltersAreApplied()
public function testRequestManyFiltersAreApplied()
{
$crawler = $this->requestListView(
'Product', array('entity.enabled' => false, 'entity.oddEven' => 'even')
Expand All @@ -35,15 +35,45 @@ public function testRequestFiltersArePassedToSearchForm()
'Product', array('entity.enabled' => false, 'entity.oddEven' => 'even')
);

$formCrawler = $crawler->filter('.action-search form');
$searchFormCrawler = $crawler->filter('.action-search form');

$this->assertSame(
1,
$formCrawler->filter('input[name="filters[entity.enabled]"][value="0"]')->count()
$searchFormCrawler->filter('input[name="filters[entity.enabled]"][value="0"]')->count()
);
$this->assertSame(
1,
$formCrawler->filter('input[name="filters[entity.oddEven]"][value="even"]')->count()
$searchFormCrawler->filter('input[name="filters[entity.oddEven]"][value="even"]')->count()
);
}

public function testRequestMultivalueFiltersAreApplied()
{
$crawler = $this->requestListView(
'Product', array('entity.oddEven' => array('odd', 'even'))
);

$this->assertContains(
'1 - 15 of 100',
$crawler->filter('#main .list-pagination')->text()
);

$searchFormCrawler = $crawler->filter('.action-search form');

$this->assertSame(
1,
$searchFormCrawler->filter('input[name="filters[entity.oddEven][]"][value="odd"]')->count()
);
$this->assertSame(
1,
$searchFormCrawler->filter('input[name="filters[entity.oddEven][]"][value="even"]')->count()
);
}

public function testRequestFilterIsAppliedToSearchAction()
{
$crawler = $this->requestSearchView('ref000', 'Product', array('entity.enabled' => false));

$this->assertSame(10, $crawler->filter('#main tr[data-id]')->count());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function load(ObjectManager $manager)
$product = new Product();
$product->setEnabled($i <= 90 ? true : false);
$product->setOddEven($i % 2 ? 'odd' : 'even');
$product->setReference('ref'.str_pad($i, 6, '0', STR_PAD_LEFT));
$product->setName($this->getRandomName());
$product->setPrice($this->getRandomPrice());
$product->setTags($this->getRandomTags());
Expand Down
28 changes: 28 additions & 0 deletions Tests/Fixtures/AppTestBundle/Entity/FunctionalTests/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class Product
*/
protected $price = 0.0;

/**
* The reference of the product.
*
* @var string
* @ORM\Column(type="string", unique=true)
*/
protected $reference;

/**
* The name of the product.
*
Expand Down Expand Up @@ -325,6 +333,26 @@ public function getImage()
return $this->image;
}

/**
* Set the product reference.
*
* @param string $reference
*/
public function setReference($reference)
{
$this->reference = $reference;
}

/**
* Retrieve the reference of the product.
*
* @return string
*/
public function getReference()
{
return $this->reference;
}

/**
* Set the product name.
*
Expand Down
8 changes: 3 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,18 @@

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./Configuration</directory>
<directory suffix=".php">./Controller</directory>
<directory suffix=".php">./DependencyInjection</directory>
<directory suffix=".php">./Reflection</directory>
<directory suffix=".php">./Resources</directory>
<directory suffix=".php">./Twig</directory>
<directory suffix=".php">./EventListener</directory>
<exclude>
<directory>./build</directory>
<directory>./Tests</directory>
<directory>./var</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
<blacklist>
<directory>./vendor</directory>
<directory>./var</directory>
<directory>./Tests</directory>
<directory>./build</directory>
</blacklist>
Expand Down

0 comments on commit 45f414e

Please sign in to comment.