Browse Source

Merge pull request #2 from nafiesl/analysis-qypyZN

Apply fixes from StyleCI
pull/3/head
Nafies Luthfi 9 years ago
committed by GitHub
parent
commit
fe975ce27a
  1. 2
      app/Cart/CartCollection.php
  2. 1
      app/Cart/TransactionDraft.php
  3. 9
      app/Helpers/helpers.php
  4. 2
      app/Http/Controllers/CartController.php
  5. 2
      app/Providers/AppServiceProvider.php
  6. 2
      resources/lang/id/cart.php
  7. 14
      tests/Feature/TransactionEntryTest.php

2
app/Cart/CartCollection.php

@ -122,7 +122,7 @@ class CartCollection
{ {
$item = $draft->search($product); $item = $draft->search($product);
return ! is_null($item);
return !is_null($item);
} }
public function updateDraftItem($draftKey, $itemKey, $newItemData) public function updateDraftItem($draftKey, $itemKey, $newItemData)

1
app/Cart/TransactionDraft.php

@ -79,6 +79,7 @@ abstract class TransactionDraft
public function search(Product $product) public function search(Product $product)
{ {
$productItem = $this->items()->where('id', $product->id)->first(); $productItem = $this->items()->where('id', $product->id)->first();
return $productItem; return $productItem;
} }
} }

9
app/Helpers/helpers.php

@ -2,11 +2,14 @@
function formatNo($number) function formatNo($number)
{ {
return number_format($number, 0,',','.');
return number_format($number, 0, ',', '.');
} }
function formatRp($number) function formatRp($number)
{ {
if ($number == 0) { return '-'; }
return 'Rp. ' . formatNo($number);
if ($number == 0) {
return '-';
}
return 'Rp. '.formatNo($number);
} }

2
app/Http/Controllers/CartController.php

@ -23,7 +23,7 @@ class CartController extends Controller
$queriedProducts = []; $queriedProducts = [];
$draft = $this->cart->content()->first(); $draft = $this->cart->content()->first();
return view('cart.index', compact('draft','queriedProducts'));
return view('cart.index', compact('draft', 'queriedProducts'));
} }
public function show(Request $request, $draftKey) public function show(Request $request, $draftKey)

2
app/Providers/AppServiceProvider.php

@ -13,7 +13,7 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
require_once app_path() . '/Helpers/helpers.php';
require_once app_path().'/Helpers/helpers.php';
} }
/** /**

2
resources/lang/id/cart.php

@ -2,5 +2,5 @@
return [ return [
// Labels // Labels
'product_search' => 'Cari Produk'
'product_search' => 'Cari Produk',
]; ];

14
tests/Feature/TransactionEntryTest.php

@ -68,15 +68,15 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->see($product->name); $this->see($product->name);
$this->see($product->credit_price); $this->see($product->credit_price);
$this->seeElement('form', ['action' => route('cart.add-draft-item', [$draft->draftKey, $product->id])]); $this->seeElement('form', ['action' => route('cart.add-draft-item', [$draft->draftKey, $product->id])]);
$this->seeElement('input', ['id' => 'qty-' . $product->id, 'name' => 'qty']);
$this->seeElement('input', ['id' => 'add-product-' . $product->id]);
$this->seeElement('input', ['id' => 'qty-'.$product->id, 'name' => 'qty']);
$this->seeElement('input', ['id' => 'add-product-'.$product->id]);
$this->dontSee($product->cash_price); $this->dontSee($product->cash_price);
} }
/** @test */ /** @test */
public function user_can_add_item_to_draft() public function user_can_add_item_to_draft()
{ {
$product = factory(Product::class)->create(['name' => 'Testing Produk 1','cash_price' => 400,'credit_price' => 500]);
$product = factory(Product::class)->create(['name' => 'Testing Produk 1', 'cash_price' => 400, 'credit_price' => 500]);
$this->loginAsUser(); $this->loginAsUser();
$cart = new CartCollection(); $cart = new CartCollection();
@ -87,14 +87,14 @@ class TransactionEntryTest extends BrowserKitTestCase
$this->visit(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->visit(route('cart.show', [$draft->draftKey, 'query' => 'testing']));
$this->type(2, 'qty'); $this->type(2, 'qty');
$this->press('add-product-' . $product->id);
$this->press('add-product-'.$product->id);
$this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing'])); $this->seePageIs(route('cart.show', [$draft->draftKey, 'query' => 'testing']));
$this->assertTrue($cart->draftHasItem($draft, $product)); $this->assertTrue($cart->draftHasItem($draft, $product));
$this->assertEquals(800, $draft->getTotal()); $this->assertEquals(800, $draft->getTotal());
$this->see(formatRp(800)); $this->see(formatRp(800));
$this->seeElement('input', ['id' => 'qty-' . 0]);
$this->seeElement('input', ['id' => 'item_discount-' . 0]);
$this->seeElement('button', ['id' => 'remove-item-' . 0]);
$this->seeElement('input', ['id' => 'qty-'. 0]);
$this->seeElement('input', ['id' => 'item_discount-'. 0]);
$this->seeElement('button', ['id' => 'remove-item-'. 0]);
} }
} }
Loading…
Cancel
Save