Skip to content

Commit

Permalink
first functionnal test
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Jan 10, 2021
1 parent 4b9685b commit 07c164d
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/admin/composer.json
Expand Up @@ -22,7 +22,8 @@
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"symfony/panther": "^0.9.0"
},
"authors": [
{
Expand Down
63 changes: 63 additions & 0 deletions packages/admin/tests/AdminTest.php
@@ -0,0 +1,63 @@
<?php

namespace Pushword\Tests;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Console\Tester\CommandTester;

class AdminTest extends WebTestCase
{
private bool $userCreated = false;

public function testLogin()
{
$client = static::createClient();

$client->request('GET', '/admin/');
$this->assertEquals(301, $client->getResponse()->getStatusCode());

$client->request('GET', '/login');
$this->assertStringContainsString('Connexion', $client->getResponse());
}

public function loginUser(): KernelBrowser
{
if (false === $this->userCreated) {
$this->createUser();
}

$client = static::createClient();
$crawler = $client->request('GET', '/login');
$form = $crawler->filter('[method=post]')->form();
$form['email'] = 'admin@example.tld';
$form['password'] = 'mySecr3tpAssword';
$crawler = $client->submit($form);

return $client;
}

public function testPageList()
{
$client = $this->loginUser();

$crawler = $client->request('GET', '/admin/app/page/list');

$this->assertResponseIsSuccessful();
}

private function createUser()
{
$kernel = static::createKernel();
$application = new Application($kernel);

$command = $application->find('pushword:user:create');
$commandTester = new CommandTester($command);
$commandTester->execute([
'email' => 'admin@example.tld',
'password' => 'mySecr3tpAssword',
'role' => 'ROLE_SUPER_ADMIN',
]);
}
}
2 changes: 1 addition & 1 deletion packages/core/src/Component/App/AppConfig.php
Expand Up @@ -147,7 +147,7 @@ public function getView(?string $path = null, ?Twig $twig = null, $fallback = '@

// check if twig template exist
try {
$twig->loadTemplate($name);
$twig->load($name);

return $name;
} finally {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/Repository/UserRepository.php
@@ -0,0 +1,11 @@
<?php

namespace Pushword\Core\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Collections\Selectable;
use Doctrine\Persistence\ObjectRepository;

class UserRepository extends ServiceEntityRepository implements ObjectRepository, Selectable
{
}
4 changes: 4 additions & 0 deletions packages/core/src/Resources/config/services/all.yaml
Expand Up @@ -126,6 +126,10 @@ services:
arguments: ['@doctrine', '%pw.entity_media%']
tags: ['doctrine.repository_service']

Pushword\Core\Repository\UserRepository:
arguments: ['@doctrine', '%pw.entity_user%']
tags: ['doctrine.repository_service']

# --------
# TWIG extension
# --------
Expand Down
7 changes: 7 additions & 0 deletions packages/skeleton/config/packages/test/framework.php
@@ -0,0 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'ide' => 'vscode',
'test' => true,
'session' => ['storage_id' => 'session.storage.mock_file']
]);
3 changes: 2 additions & 1 deletion packages/skeleton/src/Entity/User.php
Expand Up @@ -4,9 +4,10 @@

use Doctrine\ORM\Mapping as ORM;
use Pushword\Core\Entity\User as BaseUser;
use Pushword\Core\Repository\UserRepository;

/**
* @ORM\Entity
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User extends BaseUser
{
Expand Down

0 comments on commit 07c164d

Please sign in to comment.