This commit is contained in:
Kevin Frantz 2018-07-15 16:41:56 +02:00
parent 990d65aa9a
commit 1492282ae5
17 changed files with 129 additions and 91 deletions

View File

@ -11,7 +11,9 @@ use router\Router;
*/
abstract class AbstractController
{
/**
*
* @var CoreInterface
*/
protected $core;
@ -22,16 +24,19 @@ abstract class AbstractController
*/
protected $post;
public function __construct(CoreInterface $core){
public function __construct(CoreInterface $core)
{
$this->core = $core;
$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));
}
private function addUser(array $variables):array{
private function addUser(array $variables): array
{
if (array_key_exists('user', $variables)) {
throw new \Exception('Key user isn\'t allowed!');
}
@ -39,7 +44,8 @@ abstract class AbstractController
return $variables;
}
protected function route(?array $get =[]):void{
protected function route(?array $get = []): void
{
$router = new Router();
$router->setCore($this->core);
$router->setGet($get);

View File

@ -54,7 +54,8 @@ class AbstractDefaultController extends AbstractController
], 'logout')
];
}
return [new LinkCollection('login',[
return [
new LinkCollection('login', [
new Link([
Router::CONTROLLER => 'user',
Router::ACTION => 'login'
@ -63,7 +64,8 @@ class AbstractDefaultController extends AbstractController
Router::CONTROLLER => 'user',
Router::ACTION => 'register'
], 'register')
])];
])
];
}
}

View File

@ -59,7 +59,7 @@ final class Order extends AbstractDefaultController implements OrderInterface
}
$this->render('order/basket.html.twig', [
'basket' => $this->core->getBasket(),
'payment_methods'=>AbstractPayment::getPaymentMethods(),
'payment_methods' => AbstractPayment::getPaymentMethods()
]);
}

View File

@ -37,9 +37,14 @@ final class Product extends AbstractDefaultController implements ProductInterfac
}
$this->render('product/list.html.twig', [
'products' => $products,
'add_to_basket'=> new Link(['controller'=>'order','action'=>'basket']),
'add_to_basket' => new Link([
'controller' => 'order',
'action' => 'basket'
]),
'colors' => $this->getColors(),
'menu_items'=>[$this->getColors()]
'menu_items' => [
$this->getColors()
]
]);
}

View File

@ -10,7 +10,9 @@ use controller\AbstractDefaultController;
*/
final class Standart extends AbstractDefaultController implements StandartInterface
{
public function homepage():void{
public function homepage(): void
{
$this->render('standart/homepage.html.twig');
}
}

View File

@ -8,6 +8,7 @@ namespace controller\standart;
*/
interface StandartInterface
{
public function homepage(): void;
}

View File

@ -13,6 +13,7 @@ use entity\user\User as UserEntity;
*/
final class User extends AbstractDefaultController implements UserInterface
{
/**
*
* @var UserRepository

View File

@ -11,6 +11,7 @@ use entity\order\Order;
*/
interface CoreInterface
{
public function getDatabase(): \PDO;
public function getTwig(): \Twig_Environment;

View File

@ -11,6 +11,7 @@ use entity\user\User;
*/
class CoreTest extends TestCase
{
/**
*
* @var Core
@ -23,7 +24,8 @@ class CoreTest extends TestCase
*/
protected $user;
protected function setUp():void{
protected function setUp(): void
{
$this->core = new Core();
$this->user = new User();
$this->user->setId(1);
@ -32,20 +34,25 @@ class CoreTest extends TestCase
$this->core->setUser($this->user);
}
public function testTwig():void{
public function testTwig(): void
{
$this->assertInstanceOf(\Twig_Environment::class, $this->core->getTwig());
}
public function testDatabase():void{
public function testDatabase(): void
{
$this->assertInstanceOf(\PDO::class, $this->core->getDatabase());
}
public function testUser():void{
public function testUser(): void
{
$this->assertEquals($this->user, $this->core->getUser());
}
public function testSession():void{
$this->assertEquals($this->core->getUser()->getPasswordHash(), $_SESSION['user']->getPasswordHash());
public function testSession(): void
{
$this->assertEquals($this->core->getUser()
->getPasswordHash(), $_SESSION['user']->getPasswordHash());
}
}

View File

@ -1,12 +1,14 @@
<?php
namespace entity\payment\method1;
use PHPUnit\Framework\TestCase;
/**
*
* @author kevinfrantz
*
*/
class Method1Test
class Method1Test extends TestCase
{
public function testName():void{
$this->assertEquals(Method1::getName(), 'method1');

View File

@ -22,12 +22,13 @@
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{%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 %}
</div></li>
{% endif %}
{% endif %}
{% endfor %}
</ul>
</div>

View File

@ -28,8 +28,7 @@ basket
{% for key,payment in payment_methods %}
<option value="{{ key }}">{{ payment.name }}</option>
{% endfor %}
</select>
<input type="hidden" name="store" value="1" />
<input type="submit" class="btn btn-primary" value="Order" />
</select> <input type="hidden" name="store" value="1" /> <input type="submit"
class="btn btn-primary" value="Order" />
</form>
{% endblock %}

View File

@ -23,8 +23,8 @@ product overview
</ul>
</span>
<form action="{{ add_to_basket.url }}" method="post">
<input type="hidden" name="add" value="{{ product.id }}" />
<input type="submit" class="btn btn-primary" value="Add to basket" />
<input type="hidden" name="add" value="{{ product.id }}" /> <input
type="submit" class="btn btn-primary" value="Add to basket" />
</form>
</div>
</div>

View File

@ -1,5 +1,7 @@
{% extends "frames/default.html.twig" %}
{% block title %}Homepage{% endblock %}
{% block title %}
Homepage
{% endblock %}
{% block content %}
<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" />

View File

@ -1,15 +1,19 @@
{% extends "frames/default.html.twig" %}
{% block title %}login{% endblock %}
{% block title %}
login
{% endblock %}
{% block content %}
<h1>Login</h1>
<form method='post'>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" name="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter email">
<label for="email">Email address</label> <input type="email"
name="email" class="form-control" id="email"
aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form-control" id="password" placeholder="Password">
<label for="password">Password</label> <input type="password"
name="password" class="form-control" id="password"
placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

View File

@ -1,19 +1,24 @@
{% extends "frames/default.html.twig" %}
{% block title %}register{% endblock %}
{% block title %}
register
{% endblock %}
{% block content %}
<h1>Register</h1>
<form method="post">
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" name="email" placeholder="Enter email">
<label for="email">Email address</label> <input type="email"
class="form-control" id="email" aria-describedby="emailHelp"
name="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="name">Username</label>
<input type="email" class="form-control" id="name" aria-describedby="emailHelp" name="name" placeholder="Enter Username">
<label for="name">Username</label> <input type="email"
class="form-control" id="name" aria-describedby="emailHelp"
name="name" placeholder="Enter Username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
<label for="password">Password</label> <input type="password"
class="form-control" id="password" name="password"
placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>