Example #1
0
 public function testProduct()
 {
     //nazwa $stockQty jest zdefiniowana w klasie a w funkcji getStockQty jest zapisana jako stockqty
     //co uniemożliwiało pobranie wartości
     $prod = new Product();
     $this->assertFalse(false, $prod->hasStock());
     $this->assertTrue(true, $prod->hasStock());
     /*
     Jako, że funckaj sell nie zwraca wartości nie mogę użyć czegoś takiego
     chyba, że dopiszę return do tej funkcji
     $quantity = 2;
     $this->assertEquals($prod->getStockQty()-2, $prod->sell($quantity));
     */
     $quantity = 2;
     $quantityBefore = $prod->getStockQty();
     $prod->sell($quantity);
     $this->assertEquals($quantityBefore, $prod->getStockQty() - $quantity);
     /*
     Jako, że funkcja buy nie zwraca wartości nie mogę użyć czegoś takiego
     chyba, że dopiszę return do tej funkcji
     $quantity = 3;
     $this->assertEquals($prod->getStockQty()+3, $prod->buy($quantity));
     */
     $quantity = 3;
     $quantityBefore = $prod->getStockQty();
     $prod->buy($quantity);
     $this->assertEquals($quantityBefore, $prod->getStockQty() + $quantity);
     /*
     funkcja nie zwróci wartości z użytą zmienną bo nie używa zmiennej $quantity w swoim ciele
     domyślnie będzie zawsze 0
     */
     $quantity = 5;
     $this->assertEquals(0, $prod->getPriceForQuantity($quantity));
     //skoro nastawiamy $product_code na 10 powinien zwrócic 10
     $product_code = 10;
     $prod->setProductCode($product_code);
     $this->assertEquals(10, $prod->getProductCode());
     /*
     Skoro ustawiam $unitPrice na 15 powinno zwrócic 15 jako tą sama wartość
     */
     $unitPrice = 15;
     $prod->setUnitPrice($unitPrice);
     $this->assertEquals($prod->getUnitPrice(), $unitPrice);
 }
// Create and load administrator
$user = UserFactory::registerUser('*****@*****.**', 'johnsmith', 'John Smith', 'Administrator');
// Load user by email
$user = new User('*****@*****.**');
// Load user by login
$user = new User('johndoe', 'login');
// Check if subscription is valid
$user->isSubscribed();
// Buy subscription via PayPal for 4 days
Subscription::buy($user, 4, new PayPal(), $paymentDetails);
// Buy subscription via PayPal for 10 days
Subscription::buy($user, 10, new WebMoney(), $paymentDetails);
// Load a product by title
$product = new Product('TV');
// Load a product by ID
$product = new Product(736);
// Get product info
$product->getProductInfo();
// Buy the product
$order = $product->buy($user, new PayPal(), $paymentDetails);
// Get order by ID
$order = new Order();
$order->load(123);
// Set different statuses of order
$order->changeStatus(Order::ORDER_STATUS_CANCELLED);
$order->changeStatus(Order::ORDER_STATUS_IN_PROGRESS);
$order->changeStatus(Order::ORDER_STATUS_CLOSED);
$adminUser = new User('*****@*****.**');
$report = new OrderCollection($adminUser);
// Get sum of sold special product in a date rang for specific user
$sum = $report->addDateRangeFilter('2015-02-05', '2015-02-09')->addUserFilter($user)->addSpecialProductsFilter();