Skip to content

Commit

Permalink
Functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysiekpiasecki committed Oct 6, 2016
1 parent b129e07 commit db8152d
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/Resources/views/gentelella/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
<div class="nav toggle">
<a id="menu_toggle"><i class="fa fa-bars"></i></a>
</div>
<a href="{{ path('app_homepage') }}" style="margin-top: 10px;" class="btn btn-success">Back to the application</a>
<a href="{{ path('app_dashboard') }}" style="margin-top: 10px;" class="btn btn-success">Back to the application</a>

<ul class="nav navbar-nav navbar-right">
<li class="">
Expand Down
4 changes: 2 additions & 2 deletions app/Resources/views/gentelella/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<input type="password" class="form-control" placeholder="Password" required="" />
</div>
<div>
<a class="btn btn-default submit" href="{{ path('app_homepage') }}">Log in</a>
<a class="btn btn-default submit" href="{{ path('app_dashboard') }}">Log in</a>
<a class="reset_pass" href="#">Lost your password?</a>
</div>

Expand Down Expand Up @@ -74,7 +74,7 @@
<input type="password" class="form-control" placeholder="Password" required="" />
</div>
<div>
<a class="btn btn-default submit" href="{{ path('app_homepage') }}">Submit</a>
<a class="btn btn-default submit" href="{{ path('app_dashboard') }}">Submit</a>
</div>

<div class="clearfix"></div>
Expand Down
4 changes: 2 additions & 2 deletions app/Resources/views/gentelella/map.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="left_col scroll-view">

<div class="navbar nav_title" style="border: 0;">
<a href="{{ path('app_homepage') }}" class="site_title">Gentelella Alela!</a>
<a href="{{ path('app_dashboard') }}" class="site_title">Gentelella Alela!</a>
</div>

<!-- menu prile quick info -->
Expand All @@ -74,7 +74,7 @@
<ul class="nav side-menu">
<li><a><i class="fa fa-home"></i> Home <span class="fa fa-chevron-down"></span></a>
<ul class="nav child_menu">
<li><a href="{{ path('app_homepage') }}">Dashboard</a>
<li><a href="{{ path('app_dashboard') }}">Dashboard</a>
</li>
<li><a href="{{ path('app_gentelella', {'page': 'index2'}) }}">Dashboard2</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions app/Resources/views/user/sidebar.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="col-md-3 left_col">
<div class="left_col scroll-view">
<div class="navbar nav_title" style="border: 0;">
<a href="{{ path('app_homepage') }}" class="site_title"><i class="fa fa-paw"></i> <span>Gentelella</span></a>
<a href="{{ path('app_dashboard') }}" class="site_title"><i class="fa fa-paw"></i> <span>Gentelella</span></a>
</div>

<div class="clearfix"></div>
Expand All @@ -25,7 +25,7 @@
<div class="menu_section">
<h3>General</h3>
<ul class="nav side-menu">
<li><a href="{{ path('app_homepage') }}"><i class="fa fa-home"></i> Dashboard</a></li>
<li><a href="{{ path('app_dashboard') }}"><i class="fa fa-home"></i> Dashboard</a></li>
</ul>
</div>
<div class="menu_section">
Expand Down
4 changes: 2 additions & 2 deletions src/AppBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function gentelellaAction(Request $request, $page)
}

/**
* @Route("/", name="app_homepage")
* @Route("/", name="app_dashboard")
*
* @param Request $request Request
*
* @return Response
*/
public function homepageAction(Request $request)
public function dashboardAction(Request $request)
{
return $this->render('user/pages/dashboard.html.twig', []);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,37 @@
* that was distributed with this source code.
*/

namespace tests;
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* Smoke test.
* DefaultControllerTest.
*
* @see DefaultController
*/
class SmokeTest extends WebTestCase
class DefaultControllerTest extends WebTestCase
{
/**
* Logged client.
*/
private static $client = null;

/**
* Set up before class.
*/
public static function setUpBeforeClass()
{
if (is_null(self::$client)) {
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$form = $crawler->filter('form')->form(array(
'_username' => 'test',
'_password' => 'test',
));
$client->submit($form);
$crawler = $client->followRedirect();
self::$client = $client;
}
}

/**
* Tear down after class.
* @dataProvider provideUrl
*
* @param string $url Relative page url
*/
public static function tearDownAfterClass()
public function testTemplatePages($url)
{
$client = self::$client;
$client->request('GET', '/logout');
$client = new \WebTestClient('test', 'test');
$authClient = $client->logIn();
$crawler = $authClient->request('GET', $url);
$this->assertEquals(200, $authClient->getResponse()->getStatusCode());
}

/**
* @dataProvider provideUrl
*/
public function testUrl($url)
public function testDashboard()
{
$client = self::$client;
$crawler = $client->request('GET', $url);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$client = new \WebTestClient('test', 'test');
$authClient = $client->logIn();
$crawler = $authClient->request('GET', '/');
$this->assertSame('Total Users', trim($crawler->filter('span.count_top')->text()));
$this->assertEquals(200, $authClient->getResponse()->getStatusCode());
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/AppBundle/Controller/TopNavControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* TopNavControllerTest.
*
* @see TopNavController
*/
class TopNavControllerTest extends WebTestCase
{
public function testProfile()
{
$client = new \WebTestClient();
$authClient = $client->logIn();
$crawler = $authClient->request('GET', '/profile');
$this->assertEquals(200, $authClient->getResponse()->getStatusCode());
}
}
41 changes: 41 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,44 @@
register_shutdown_function(function () {
shell_exec('php bin/console fos:user:deactivate test');
});

class WebTestClient
{
private $username;
private $password;

/**
* WebTestClient constructor.
*
* @param $username
* @param $password
*/
public function __construct($username = 'test', $password = 'test')
{
$this->username = $username;
$this->password = $password;
}

public function logIn()
{
static $client = null;

if ($client === null) {
$kernel = new AppKernel('test', false);
$kernel->boot();
$client = $kernel->getContainer()->get('test.client');

$crawler = $client->request('GET', '/logout');
$crawler = $client->request('GET', '/login');

$form = $crawler->filter('form')->form(array(
'_username' => $this->username,
'_password' => $this->password,
));
$client->submit($form);
$client->followRedirect();
}

return $client;
}
}

0 comments on commit db8152d

Please sign in to comment.