mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-01 00:53:10 +01:00
Cleanup
This commit is contained in:
parent
990d65aa9a
commit
1492282ae5
@ -11,7 +11,9 @@ use router\Router;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractController
|
abstract class AbstractController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @var CoreInterface
|
* @var CoreInterface
|
||||||
*/
|
*/
|
||||||
protected $core;
|
protected $core;
|
||||||
@ -22,16 +24,19 @@ abstract class AbstractController
|
|||||||
*/
|
*/
|
||||||
protected $post;
|
protected $post;
|
||||||
|
|
||||||
public function __construct(CoreInterface $core){
|
public function __construct(CoreInterface $core)
|
||||||
|
{
|
||||||
$this->core = $core;
|
$this->core = $core;
|
||||||
$this->post = $_POST;
|
$this->post = $_POST;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function render(string $template,array $variables=[]):void{
|
protected function render(string $template, array $variables = []): void
|
||||||
|
{
|
||||||
echo $this->core->getTwig()->render($template, $this->addUser($variables));
|
echo $this->core->getTwig()->render($template, $this->addUser($variables));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addUser(array $variables):array{
|
private function addUser(array $variables): array
|
||||||
|
{
|
||||||
if (array_key_exists('user', $variables)) {
|
if (array_key_exists('user', $variables)) {
|
||||||
throw new \Exception('Key user isn\'t allowed!');
|
throw new \Exception('Key user isn\'t allowed!');
|
||||||
}
|
}
|
||||||
@ -39,7 +44,8 @@ abstract class AbstractController
|
|||||||
return $variables;
|
return $variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function route(?array $get =[]):void{
|
protected function route(?array $get = []): void
|
||||||
|
{
|
||||||
$router = new Router();
|
$router = new Router();
|
||||||
$router->setCore($this->core);
|
$router->setCore($this->core);
|
||||||
$router->setGet($get);
|
$router->setGet($get);
|
||||||
|
@ -54,7 +54,8 @@ class AbstractDefaultController extends AbstractController
|
|||||||
], 'logout')
|
], 'logout')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [new LinkCollection('login',[
|
return [
|
||||||
|
new LinkCollection('login', [
|
||||||
new Link([
|
new Link([
|
||||||
Router::CONTROLLER => 'user',
|
Router::CONTROLLER => 'user',
|
||||||
Router::ACTION => 'login'
|
Router::ACTION => 'login'
|
||||||
@ -63,7 +64,8 @@ class AbstractDefaultController extends AbstractController
|
|||||||
Router::CONTROLLER => 'user',
|
Router::CONTROLLER => 'user',
|
||||||
Router::ACTION => 'register'
|
Router::ACTION => 'register'
|
||||||
], 'register')
|
], 'register')
|
||||||
])];
|
])
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ final class Order extends AbstractDefaultController implements OrderInterface
|
|||||||
}
|
}
|
||||||
$this->render('order/basket.html.twig', [
|
$this->render('order/basket.html.twig', [
|
||||||
'basket' => $this->core->getBasket(),
|
'basket' => $this->core->getBasket(),
|
||||||
'payment_methods'=>AbstractPayment::getPaymentMethods(),
|
'payment_methods' => AbstractPayment::getPaymentMethods()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +37,14 @@ final class Product extends AbstractDefaultController implements ProductInterfac
|
|||||||
}
|
}
|
||||||
$this->render('product/list.html.twig', [
|
$this->render('product/list.html.twig', [
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
'add_to_basket'=> new Link(['controller'=>'order','action'=>'basket']),
|
'add_to_basket' => new Link([
|
||||||
|
'controller' => 'order',
|
||||||
|
'action' => 'basket'
|
||||||
|
]),
|
||||||
'colors' => $this->getColors(),
|
'colors' => $this->getColors(),
|
||||||
'menu_items'=>[$this->getColors()]
|
'menu_items' => [
|
||||||
|
$this->getColors()
|
||||||
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ use controller\AbstractDefaultController;
|
|||||||
*/
|
*/
|
||||||
final class Standart extends AbstractDefaultController implements StandartInterface
|
final class Standart extends AbstractDefaultController implements StandartInterface
|
||||||
{
|
{
|
||||||
public function homepage():void{
|
|
||||||
|
public function homepage(): void
|
||||||
|
{
|
||||||
$this->render('standart/homepage.html.twig');
|
$this->render('standart/homepage.html.twig');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace controller\standart;
|
|||||||
*/
|
*/
|
||||||
interface StandartInterface
|
interface StandartInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function homepage(): void;
|
public function homepage(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ use entity\user\User as UserEntity;
|
|||||||
*/
|
*/
|
||||||
final class User extends AbstractDefaultController implements UserInterface
|
final class User extends AbstractDefaultController implements UserInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var UserRepository
|
* @var UserRepository
|
||||||
|
@ -11,6 +11,7 @@ use entity\order\Order;
|
|||||||
*/
|
*/
|
||||||
interface CoreInterface
|
interface CoreInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getDatabase(): \PDO;
|
public function getDatabase(): \PDO;
|
||||||
|
|
||||||
public function getTwig(): \Twig_Environment;
|
public function getTwig(): \Twig_Environment;
|
||||||
|
@ -11,6 +11,7 @@ use entity\user\User;
|
|||||||
*/
|
*/
|
||||||
class CoreTest extends TestCase
|
class CoreTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var Core
|
* @var Core
|
||||||
@ -23,7 +24,8 @@ class CoreTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
protected function setUp():void{
|
protected function setUp(): void
|
||||||
|
{
|
||||||
$this->core = new Core();
|
$this->core = new Core();
|
||||||
$this->user = new User();
|
$this->user = new User();
|
||||||
$this->user->setId(1);
|
$this->user->setId(1);
|
||||||
@ -32,20 +34,25 @@ class CoreTest extends TestCase
|
|||||||
$this->core->setUser($this->user);
|
$this->core->setUser($this->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTwig():void{
|
public function testTwig(): void
|
||||||
|
{
|
||||||
$this->assertInstanceOf(\Twig_Environment::class, $this->core->getTwig());
|
$this->assertInstanceOf(\Twig_Environment::class, $this->core->getTwig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDatabase():void{
|
public function testDatabase(): void
|
||||||
|
{
|
||||||
$this->assertInstanceOf(\PDO::class, $this->core->getDatabase());
|
$this->assertInstanceOf(\PDO::class, $this->core->getDatabase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUser():void{
|
public function testUser(): void
|
||||||
|
{
|
||||||
$this->assertEquals($this->user, $this->core->getUser());
|
$this->assertEquals($this->user, $this->core->getUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSession():void{
|
public function testSession(): void
|
||||||
$this->assertEquals($this->core->getUser()->getPasswordHash(), $_SESSION['user']->getPasswordHash());
|
{
|
||||||
|
$this->assertEquals($this->core->getUser()
|
||||||
|
->getPasswordHash(), $_SESSION['user']->getPasswordHash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace entity\payment\method1;
|
namespace entity\payment\method1;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Method1Test
|
class Method1Test extends TestCase
|
||||||
{
|
{
|
||||||
public function testName():void{
|
public function testName():void{
|
||||||
$this->assertEquals(Method1::getName(), 'method1');
|
$this->assertEquals(Method1::getName(), 'method1');
|
||||||
|
@ -22,12 +22,13 @@
|
|||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
{%for link in item %}
|
{%for link in item %}
|
||||||
<a class="dropdown-item {% if link.active %}active{% endif %}" href="{{ link.url }}">{{ link.name }}</a>
|
<a class="dropdown-item {% if link.active %}active{% endif %}"
|
||||||
|
href="{{ link.url }}"> {{ link.name }}
|
||||||
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div></li>
|
</div></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -28,8 +28,7 @@ basket
|
|||||||
{% for key,payment in payment_methods %}
|
{% for key,payment in payment_methods %}
|
||||||
<option value="{{ key }}">{{ payment.name }}</option>
|
<option value="{{ key }}">{{ payment.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select> <input type="hidden" name="store" value="1" /> <input type="submit"
|
||||||
<input type="hidden" name="store" value="1" />
|
class="btn btn-primary" value="Order" />
|
||||||
<input type="submit" class="btn btn-primary" value="Order" />
|
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -23,8 +23,8 @@ product overview
|
|||||||
</ul>
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
<form action="{{ add_to_basket.url }}" method="post">
|
<form action="{{ add_to_basket.url }}" method="post">
|
||||||
<input type="hidden" name="add" value="{{ product.id }}" />
|
<input type="hidden" name="add" value="{{ product.id }}" /> <input
|
||||||
<input type="submit" class="btn btn-primary" value="Add to basket" />
|
type="submit" class="btn btn-primary" value="Add to basket" />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
{% extends "frames/default.html.twig" %}
|
{% extends "frames/default.html.twig" %}
|
||||||
{% block title %}Homepage{% endblock %}
|
{% block title %}
|
||||||
|
Homepage
|
||||||
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Welcome to the online shop!</h2>
|
<h2>Welcome to the online shop!</h2>
|
||||||
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Signs%2C_signs_and_more_signs_%282504183343%29.jpg/1280px-Signs%2C_signs_and_more_signs_%282504183343%29.jpg" />
|
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Signs%2C_signs_and_more_signs_%282504183343%29.jpg/1280px-Signs%2C_signs_and_more_signs_%282504183343%29.jpg" />
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
{% extends "frames/default.html.twig" %}
|
{% extends "frames/default.html.twig" %}
|
||||||
{% block title %}login{% endblock %}
|
{% block title %}
|
||||||
|
login
|
||||||
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Login</h1>
|
<h1>Login</h1>
|
||||||
<form method='post'>
|
<form method='post'>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email">Email address</label>
|
<label for="email">Email address</label> <input type="email"
|
||||||
<input type="email" name="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter email">
|
name="email" class="form-control" id="email"
|
||||||
|
aria-describedby="emailHelp" placeholder="Enter email">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label> <input type="password"
|
||||||
<input type="password" name="password" class="form-control" id="password" placeholder="Password">
|
name="password" class="form-control" id="password"
|
||||||
|
placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
{% extends "frames/default.html.twig" %}
|
{% extends "frames/default.html.twig" %}
|
||||||
{% block title %}register{% endblock %}
|
{% block title %}
|
||||||
|
register
|
||||||
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Register</h1>
|
<h1>Register</h1>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email">Email address</label>
|
<label for="email">Email address</label> <input type="email"
|
||||||
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" name="email" placeholder="Enter email">
|
class="form-control" id="email" aria-describedby="emailHelp"
|
||||||
|
name="email" placeholder="Enter email">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Username</label>
|
<label for="name">Username</label> <input type="email"
|
||||||
<input type="email" class="form-control" id="name" aria-describedby="emailHelp" name="name" placeholder="Enter Username">
|
class="form-control" id="name" aria-describedby="emailHelp"
|
||||||
|
name="name" placeholder="Enter Username">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="password">Password</label>
|
<label for="password">Password</label> <input type="password"
|
||||||
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
|
class="form-control" id="password" name="password"
|
||||||
|
placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user