forked from EasyCorp/EasyAdminBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functional tests for the data collector
- Loading branch information
1 parent
794308e
commit e543c73
Showing
1 changed file
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <javier.eguiluz@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle\Tests\Controller; | ||
|
||
use Symfony\Component\DomCrawler\Crawler; | ||
use JavierEguiluz\Bundle\EasyAdminBundle\Tests\Fixtures\AbstractTestCase; | ||
|
||
class EasyAdminDataCollectorTest extends AbstractTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->initClient(array('environment' => 'default_backend')); | ||
} | ||
|
||
public function testCollectorIsEnabled() | ||
{ | ||
$this->client->enableProfiler(); | ||
$this->requestListView(); | ||
|
||
$this->assertNotNull($this->client->getProfile()->getCollector('easyadmin')); | ||
} | ||
|
||
public function testCollectorInformationForListView() | ||
{ | ||
$this->client->enableProfiler(); | ||
$this->requestListView(); | ||
$collector = $this->client->getProfile()->getCollector('easyadmin'); | ||
|
||
$this->assertEquals(5, $collector->getNumEntities()); | ||
|
||
$parameters = array( | ||
'action' => 'list', | ||
'entity' => 'Category', | ||
'id' => null, | ||
'sort_field' => 'id', | ||
'sort_direction' => 'DESC', | ||
); | ||
$this->assertEquals($parameters, $collector->getRequestParameters()); | ||
|
||
$currentConfiguration = $collector->getCurrentEntityConfiguration(); | ||
$this->assertEquals('Category', $currentConfiguration['name']); | ||
|
||
$backendConfiguration = $collector->getBackendConfiguration(); | ||
$this->assertCount(5, $backendConfiguration['entities']); | ||
} | ||
|
||
public function testCollectorInformationForEditView() | ||
{ | ||
$this->client->enableProfiler(); | ||
$this->requestEditView(); | ||
$collector = $this->client->getProfile()->getCollector('easyadmin'); | ||
|
||
$this->assertEquals(5, $collector->getNumEntities()); | ||
|
||
$parameters = array( | ||
'action' => 'edit', | ||
'entity' => 'Category', | ||
'id' => 200, | ||
'sort_field' => 'id', | ||
'sort_direction' => 'DESC', | ||
); | ||
$this->assertEquals($parameters, $collector->getRequestParameters()); | ||
|
||
$currentConfiguration = $collector->getCurrentEntityConfiguration(); | ||
$this->assertEquals('Category', $currentConfiguration['name']); | ||
|
||
$backendConfiguration = $collector->getBackendConfiguration(); | ||
$this->assertCount(5, $backendConfiguration['entities']); | ||
} | ||
|
||
/** | ||
* @return Crawler | ||
*/ | ||
private function requestListView() | ||
{ | ||
return $this->getBackendPage(array( | ||
'action' => 'list', | ||
'entity' => 'Category', | ||
)); | ||
} | ||
|
||
/** | ||
* @return Crawler | ||
*/ | ||
private function requestEditView() | ||
{ | ||
return $this->getBackendPage(array( | ||
'action' => 'edit', | ||
'entity' => 'Category', | ||
'id' => '200', | ||
)); | ||
} | ||
} |