Skip to content

Commit

Permalink
Made tests more robust and reduced code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed May 20, 2015
1 parent e2d5a40 commit 1962c72
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 84 deletions.
156 changes: 73 additions & 83 deletions Tests/AppBundleTest/CategoryEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,89 +16,6 @@

class CategoryEntityTest extends AbstractTestCase
{
/**
* @return Crawler
*/
private function requestListView()
{
$parameters = array(
'action' => 'list',
'entity' => 'Category',
'view' => 'list',
);

$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters));
}

/**
* @return Crawler
*/
private function requestShowView()
{
$parameters = array(
'action' => 'show',
'entity' => 'Category',
'id' => '200',
'view' => 'list',
);

$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters));
}

/**
* @return Crawler
*/
private function requestEditView()
{
$parameters = array(
'action' => 'edit',
'entity' => 'Category',
'id' => '200',
'view' => 'list',
);

$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters));
}

/**
* @return Crawler
*/
private function requestNewView()
{
$parameters = array(
'action' => 'new',
'entity' => 'Category',
'view' => 'list',
);

$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters));
}

/**
* @return Crawler
*/
private function requestSearchView()
{
$parameters = array(
'action' => 'search',
'entity' => 'Category',
'query' => 'cat',
'view' => 'list',
);

$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters));
}

public function testListViewPageMainMenu()
{
$crawler = $this->requestShowView();
Expand Down Expand Up @@ -622,4 +539,77 @@ public function testSearchViewShowActionReferer()

$this->assertEquals($parameters, $refererParameters);
}

/**
* @return Crawler
*/
private function doGetRequest(array $parameters)
{
$client = static::createClient();

return $client->request('GET', '/admin/?'.http_build_query($parameters, '', '&'));
}

/**
* @return Crawler
*/
private function requestListView()
{
return $this->doGetRequest(array(
'action' => 'list',
'entity' => 'Category',
'view' => 'list',
));
}

/**
* @return Crawler
*/
private function requestShowView()
{
return $this->doGetRequest(array(
'action' => 'show',
'entity' => 'Category',
'id' => '200',
'view' => 'list',
));
}

/**
* @return Crawler
*/
private function requestEditView()
{
return $this->doGetRequest(array(
'action' => 'edit',
'entity' => 'Category',
'id' => '200',
'view' => 'list',
));
}

/**
* @return Crawler
*/
private function requestNewView()
{
return $this->doGetRequest(array(
'action' => 'new',
'entity' => 'Category',
'view' => 'list',
));
}

/**
* @return Crawler
*/
private function requestSearchView()
{
return $this->doGetRequest(array(
'action' => 'search',
'entity' => 'Category',
'query' => 'cat',
'view' => 'list',
));
}
}
2 changes: 1 addition & 1 deletion Tests/AppBundleTest/DefaultBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testUndefinedEntityError()
);

$client = static::createClient();
$crawler = $client->request('GET', '/admin/?'.http_build_query($parameters));
$crawler = $client->request('GET', '/admin/?'.http_build_query($parameters, '', '&'));

$this->assertEquals(404, $client->getResponse()->getStatusCode());
$this->assertContains('Undefined entity', $crawler->filter('head title')->text());
Expand Down

0 comments on commit 1962c72

Please sign in to comment.