-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #648 from partkeepr/PartKeepr-647
Bugfix for #647 Filters for Distributor and Manufacturer don…
- Loading branch information
Showing
2 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/PartKeepr/PartBundle/Tests/Issues/DistributorAndManufacturerSearchTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
|
||
namespace PartKeepr\PartBundle\Tests\Issues; | ||
|
||
use Doctrine\Common\DataFixtures\ProxyReferenceRepository; | ||
use PartKeepr\CoreBundle\Tests\WebTestCase; | ||
use PartKeepr\DistributorBundle\Entity\Distributor; | ||
use PartKeepr\ManufacturerBundle\Entity\Manufacturer; | ||
use PartKeepr\PartBundle\Entity\Part; | ||
use PartKeepr\PartBundle\Entity\PartDistributor; | ||
use PartKeepr\PartBundle\Entity\PartManufacturer; | ||
|
||
/** | ||
* Class DistributorAndManufacturerSearchTest | ||
* | ||
* Unit test against issue #647 (Filters for Distributor and Manufacturer don't return any results) | ||
*/ | ||
class DistributorAndManufacturerSearchTest extends WebTestCase | ||
{ | ||
/** | ||
* @var ProxyReferenceRepository | ||
*/ | ||
protected $fixtures; | ||
|
||
public function setUp() | ||
{ | ||
$this->fixtures = $this->loadFixtures( | ||
array( | ||
'PartKeepr\StorageLocationBundle\DataFixtures\CategoryDataLoader', | ||
'PartKeepr\StorageLocationBundle\DataFixtures\StorageLocationLoader', | ||
'PartKeepr\PartBundle\DataFixtures\CategoryDataLoader', | ||
'PartKeepr\PartBundle\DataFixtures\PartDataLoader', | ||
'PartKeepr\AuthBundle\DataFixtures\LoadUserData', | ||
'PartKeepr\ManufacturerBundle\Tests\DataFixtures\ManufacturerDataLoader', | ||
'PartKeepr\DistributorBundle\Tests\DataFixtures\DistributorDataLoader', | ||
) | ||
)->getReferenceRepository(); | ||
} | ||
|
||
public function testManufacturerFilter () { | ||
/** | ||
* @var $part Part | ||
*/ | ||
$part = $this->fixtures->getReference("part.1"); | ||
|
||
/** | ||
* @var $manufacturer Manufacturer | ||
*/ | ||
$manufacturer = $this->fixtures->getReference("manufacturer.first"); | ||
|
||
$partManufacturer = new PartManufacturer(); | ||
$partManufacturer->setManufacturer($manufacturer); | ||
$partManufacturer->setPartNumber("1"); | ||
|
||
$part->addManufacturer($partManufacturer); | ||
$this->getContainer()->get("doctrine.orm.default_entity_manager")->flush(); | ||
|
||
$filter = array( | ||
"property" => "manufacturers.manufacturer", | ||
"operator" => "=", | ||
"value" => $this->getContainer()->get("api.iri_converter")->getIriFromItem($manufacturer) | ||
); | ||
|
||
$filters = array($filter); | ||
|
||
$client = static::makeClient(true); | ||
|
||
$partResource = $this->getContainer()->get("resource.part"); | ||
$iri = $this->getContainer()->get("api.iri_converter")->getIriFromResource($partResource); | ||
|
||
$client->request("GET", $iri, array("filter" => json_encode($filters) )); | ||
|
||
$this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
|
||
$data = json_decode($client->getResponse()->getContent()); | ||
|
||
$this->assertEquals(1, $data->{"hydra:totalItems"}); | ||
} | ||
|
||
public function testDistributorFilter () { | ||
/** | ||
* @var $part Part | ||
*/ | ||
$part = $this->fixtures->getReference("part.1"); | ||
|
||
/** | ||
* @var $distributor Distributor | ||
*/ | ||
$distributor = $this->fixtures->getReference("distributor.first"); | ||
|
||
$partDistributor = new PartDistributor(); | ||
$partDistributor->setDistributor($distributor); | ||
|
||
$part->addDistributor($partDistributor); | ||
$this->getContainer()->get("doctrine.orm.default_entity_manager")->flush(); | ||
|
||
$filter = array( | ||
"property" => "distributors.distributor", | ||
"operator" => "=", | ||
"value" => $this->getContainer()->get("api.iri_converter")->getIriFromItem($distributor) | ||
); | ||
|
||
$filters = array($filter); | ||
|
||
$client = static::makeClient(true); | ||
|
||
$partResource = $this->getContainer()->get("resource.part"); | ||
$iri = $this->getContainer()->get("api.iri_converter")->getIriFromResource($partResource); | ||
|
||
$client->request("GET", $iri, array("filter" => json_encode($filters) )); | ||
|
||
$this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
|
||
$data = json_decode($client->getResponse()->getContent()); | ||
|
||
$this->assertEquals(1, $data->{"hydra:totalItems"}); | ||
} | ||
} |