diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7f056a4 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,33 @@ + + + + + ./tests/Feature + + + + ./tests/Unit + + + + + ./src + + + + + + + + + + + diff --git a/tests/Unit/BadgeHandlerTest.php b/tests/Unit/BadgeHandlerTest.php new file mode 100644 index 0000000..adc3d90 --- /dev/null +++ b/tests/Unit/BadgeHandlerTest.php @@ -0,0 +1,49 @@ +'test', + 'eng_name'=>'test', + 'background_color'=>'test', + 'text_color'=>'test' + ]; + $handler->store($args); + $this->assertNotEquals(0, Badge::count()); + } + + public function testUpdate() + { + $this->testStore(); + $badge=Badge::first(); + $handler = new BadgeHandler(); + $handler->update($badge,['name'=>'updateTest']); + $this->assertEquals('updateTest',Badge::find($badge->id)->name); + } + + public function testDestroy() + { + $handler = new BadgeHandler(); + $this->testStore(); + $badge=Badge::first(); + $handler->destroy($badge->id); + $this->assertNull(Badge::find($badge->id)); + + } +} diff --git a/tests/Unit/CartHandlerTest.php b/tests/Unit/CartHandlerTest.php new file mode 100644 index 0000000..6917c65 --- /dev/null +++ b/tests/Unit/CartHandlerTest.php @@ -0,0 +1,112 @@ +getCartList(); + $this->assertTrue(is_iterable($list)); + } + + public function testGetCartListByCartIds() + { + $cartHandler = new CartHandler(); + $list = $cartHandler->getCartListByCartIds(1); + $this->assertTrue(is_iterable($list)); + $list = $cartHandler->getCartListByCartIds([1]); + $this->assertTrue(is_iterable($list)); + } + + public function testMakeCartGroup() + { + $this->makeProduct(); + $cartHandler = new CartHandler(); + $sellUnit = ProductOptionItem::first(); + $cartGroup = $cartHandler->makeCartGroup($sellUnit, 4); + $this->assertInstanceOf(CartGroup::class, $cartGroup); + } + + public function testAddCart() + { + $handler = new CartHandler(); + $this->makeProduct(); + $cartGroup = $handler->makeCartGroup(ProductOptionItem::first(), 4); + $cart = $handler->addCart(Product::first(), collect([$cartGroup]), '선불'); + $this->assertNotNull($cart); + $this->assertInstanceOf(Cart::class, $cart); + return $cart; + } + + /** + * @depends testAddCart + */ + public function testChangeCartItem(Cart $cart) + { + $handler = new CartHandler(); + $original = $cart->sellGroups()->get(); + $id = $cart->id; + $this->makeProduct(); + $handler->changeCartItem($cart, $handler->makeCartGroup(ProductOptionItem::first(), 2), '착불'); + $this->assertNotEquals($original, $cart->sellGroups()->get()); + $handler->changeCartItem($cart, $handler->makeCartGroup(ProductOptionItem::first(), 0), '착불'); + $this->assertNull(Cart::find($id)); + } + + /** + * @depends testAddCart + */ + public function testDrawCart() + { + $handler = new CartHandler(); + $this->makeProduct(); + $cartGroup = $handler->makeCartGroup(ProductOptionItem::first(), 4); + $cart = $handler->addCart(Product::first(), collect([$cartGroup]), '선불'); + $handler->drawCart($cart->id); + $this->assertNull(Cart::find($cart->id)); + } + + public function testResetCart() + { + $handler = new CartHandler(); + $this->makeProduct(); + $cartGroup = $handler->makeCartGroup(ProductOptionItem::first(), 4); + $cart = $handler->addCart(Product::first(), collect([$cartGroup]), '선불'); + $handler->resetCart(); + $this->assertEquals(0, $handler->getCartList()->count()); + } + + public function testSellSetList() + { + $handler = new CartHandler(); + $list = $handler->getSellSetList(); + $this->assertTrue(is_iterable($list)); + } + + public function testGetSummary() + { + $handler = new CartHandler(); + $summary = $handler->getSummary(); + $this->assertArrayHasKey('original_price',$summary); + $this->assertArrayHasKey('sell_price',$summary); + $this->assertArrayHasKey('discount_price',$summary); + $this->assertArrayHasKey('fare',$summary); + $this->assertArrayHasKey('sum',$summary); + } + +} diff --git a/tests/Unit/DefaultSet.php b/tests/Unit/DefaultSet.php new file mode 100644 index 0000000..4315df8 --- /dev/null +++ b/tests/Unit/DefaultSet.php @@ -0,0 +1,144 @@ +singleton('app', 'Illuminate\Container\Container'); + + $app->singleton('config', 'Illuminate\Config\Repository'); +// + $app['config']->set('database.default', 'test'); + $app['config']->set('database.connections.test', [ + 'driver' => 'sqlite', + 'database' => __DIR__.'/test.db' + ]); + $app['config']->set('auth.defaults.guard', 'test'); + $app['config']->set('auth.guards.test',[ + 'driver' => 'test', + 'provider' => 'users', + ]); + + $app->bind('db', function ($app) { + return new \Illuminate\Database\DatabaseManager($app, new \Illuminate\Database\Connectors\ConnectionFactory($app)); + }); + + $app->bind('auth',function ($app) { + $authmanager = new \Illuminate\Auth\AuthManager($app); + $authmanager->extend('test', function ($app, $name, $config) { + $guard = m::mock(\Illuminate\Contracts\Auth\Guard::class); + $guard->shouldReceive('id')->andReturn(1); + $guard->shouldReceive('check')->andReturn(true); + $guard->shouldReceive('user')->andReturn((object)['rating'=>Rating::USER]); + return $guard; + }); + return $authmanager; + }); + + + $app->singleton( + \Illuminate\Contracts\Http\Kernel::class, + Kernel::class + ); + + $app->singleton( + Illuminate\Contracts\Console\Kernel::class, + App\Console\Kernel::class + ); + + DynamicModel::setConnectionResolver($app['db']); + Model::setConnectionResolver($app['db']); + DynamicModel::setKeyGen(new Keygen()); + + \Illuminate\Support\Facades\Facade::setFacadeApplication($app); + \Xpressengine\Plugins\XeroCommerce\Plugin\Database::create(); + } + + public function tearDown() + { + parent::tearDown(); + \Xpressengine\Plugins\XeroCommerce\Plugin\Database::drop(); + } + + protected function makeProduct() + { + $product = new Product(); + $product->shop_id = 1; + $product->product_code = 'test'; + $product->detail_info = json_encode([ + '상품정보' => '샘플 상품', + '비고' => '수정해서 사용' + ]); + $product->name = '지금부터 봄까지 입는 데일리 인기신상 ITEM'; + $product->sub_name = '간단한 상품설명'; + $product->original_price = 1000; + $product->sell_price = $product->original_price; + $product->discount_percentage = 100; + $product->description = '상품설명페이지'; + $product->tax_type = rand(Product::TAX_TYPE_TAX, Product::TAX_TYPE_FREE); + $product->state_display = Product::DISPLAY_VISIBLE; + $product->state_deal = Product::DEAL_ON_SALE; + $product->shop_delivery_id = 1; + $product->save(); + Resources::storeProductOption($product->id); + return $product; + } + + protected function makeShop() + { + $args['user_id'] = 'test'; + $args['shop_type'] = Shop::TYPE_STORE; + $args['shop_name'] = Shop::BASIC_SHOP_NAME; + $newShop = new Shop(); + + $newShop->fill($args); + + $newShop->save(); + + Resources::storeDefaultDeliveryCompanySet(); + + $newShop->deliveryCompanys()->attach(DeliveryCompany::pluck('id'), [ + 'delivery_fare'=>0, + 'up_to_free'=>0, + 'is_default'=>0 + ]); + } +} diff --git a/tests/Unit/FeedbackHandlerTest.php b/tests/Unit/FeedbackHandlerTest.php new file mode 100644 index 0000000..1a07dc7 --- /dev/null +++ b/tests/Unit/FeedbackHandlerTest.php @@ -0,0 +1,62 @@ +makeProduct(); + $args=[ + 'title'=>'test', + 'content'=>'test' + ]; + $handler->store($product,$args); + $this->assertNotEquals(0,$product->feedback()->count()); + } + + public function testGet() + { + $this->testStore(); + $handler = new FeedbackHandler(); + $product = Product::first(); + $list = $handler->get($product); + $this->assertNotEquals(0,$list->count()); + } + + public function testUpdate() + { + $handler = new FeedbackHandler(); + $this->testStore(); + $feedback = FeedBack::first(); + $args=[ + 'content'=>'updateTest' + ]; + $handler->update($feedback,$args); + $this->assertEquals('updateTest',FeedBack::find($feedback->id)->content); + } + + public function testDelete() + { + $handler = new FeedbackHandler(); + $this->testStore(); + $feedback = FeedBack::first(); + $feedback_id = $feedback->id; + $handler->delete($feedback); + $this->assertNull(FeedBack::find($feedback_id)); + } +} diff --git a/tests/Unit/LabelHandlerTest.php b/tests/Unit/LabelHandlerTest.php new file mode 100644 index 0000000..ee54577 --- /dev/null +++ b/tests/Unit/LabelHandlerTest.php @@ -0,0 +1,92 @@ +'test', + 'eng_name'=>'test', + 'background_color'=>'test', + 'text_color'=>'test' + ]; + $handler->store($args); + $this->assertNotEquals(0,Label::count()); + } + + public function testStoreProductLabel() + { + $handler = new LabelHandler(); + $product = $this->makeProduct(); + $this->testStore(); + $handler->storeProductLabel($product->id,Label::pluck('id')->all()); + $this->assertNotEquals(0,$product->labels()->count()); + return $product; + } + + public function testUpdate() + { + $handler = new LabelHandler(); + $this->testStore(); + $label=Label::first(); + $args=[ + 'name'=>'updateTest' + ]; + $handler->update($label,$args); + $this->assertEquals('updateTest',Label::find($label->id)->name); + + } + + public function testGetLabels() + { + $handler = new LabelHandler(); + $list = $handler->getLabels(); + $this->assertTrue(is_iterable($list)); + } + + public function testDestroy() + { + $handler = new LabelHandler(); + $this->testStore(); + $label=Label::first(); + $label_id = $label->id; + $handler->destroy($label->id); + $this->assertNull(Label::find($label_id)); + } + + public function testDestroyProductLabel() + { + $product = $this->testStoreProductLabel(); + + $handler = new LabelHandler(); + $handler->destroyProductLabel($product->id); + $this->assertEquals(0,$product->labels()->count()); + + } + + public function testGetLabel() + { + $handler = new LabelHandler(); + $this->testStore(); + $label_id =Label::first()->id; + $result = $handler->getLabel($label_id); + $this->assertInstanceOf(Label::class,$result); + $result = $handler->getLabel(0); + $this->assertNull($result); + } +} diff --git a/tests/Unit/OrderHandlerTest.php b/tests/Unit/OrderHandlerTest.php new file mode 100644 index 0000000..0a7b6e4 --- /dev/null +++ b/tests/Unit/OrderHandlerTest.php @@ -0,0 +1,211 @@ +getOrderItemList($order); + $this->assertInstanceOf(\Illuminate\Support\Collection::class, $query); + } + + public function testMakeOrder() + { + $handler = new OrderHandler(); + $order = $handler->makeOrder(); + $this->assertInstanceOf(\Xpressengine\Plugins\XeroCommerce\Models\Order::class,$order); + } + + public function testRegister() + { + $orderHandler = new OrderHandler(); + $cartHandler = new \Xpressengine\Plugins\XeroCommerce\Handlers\CartHandler(); + $this->makeProduct(); + $cart = $cartHandler->addCart(Product::first(), $cartHandler->makeCartGroup(ProductOptionItem::first(),2),'선불'); + $order = $orderHandler->register(collect([$cart])); + $this->assertNotEquals(0, $order->orderItems()->count()); + return $order; + } + + public function testPaidCheck() + { + $orderHandler = new OrderHandler(); + $order = $this->testRegister(); + $check = $orderHandler->paidCheck($order); + $this->assertEquals(Order::TEMP, $order->code); + } + + public function testAfterServiceCheck() + { + $orderHandler = new OrderHandler(); + $order = $this->testRegister(); + $check = $orderHandler->afterServiceCheck($order); + $this->assertNull($check); + } + + public function testDeliveryCheck() + { + $orderHandler = new OrderHandler(); + $order = $this->testRegister(); + $check = $orderHandler->deliveryCheck($order); + $this->assertNull($check); + } + + public function testUpdate() + { + $orderHandler = new OrderHandler(); + $order = $this->testRegister(); + $order->code =Order::COMPLETE; + $order = $orderHandler->update($order); + $this->assertEquals(0, count($order->getDirty())); + } + + public function testMakeDelivery() + { + $orderHandler = new OrderHandler(); + $cartHandler = new \Xpressengine\Plugins\XeroCommerce\Handlers\CartHandler(); + $product = $this->makeProduct(); + $this->makeShop(); + $cart = $cartHandler->addCart($product, $cartHandler->makeCartGroup(ProductOptionItem::first(),2),'선불'); + $order = $orderHandler->register(collect([$cart])); + $order = $orderHandler->makeDelivery($order, [ + 'delivery' => [ + 'nickname'=>'test', + 'name'=>'test', + 'phone'=>'t010', + 'addr'=>'test', + 'addr_detail'=>'test', + 'addr_post'=>'00000', + 'msg'=>'test' + ] + ]); + $delivery_count = $order->orderItems()->whereHas('delivery')->count(); + $this->assertNotEquals(0, $delivery_count); + return $order; + } + + public function testMakePayment() + { + $handler = new OrderHandler(); + $order = $this->testMakeDelivery(); + $payment_order = $handler->makePayment($order); + $this->assertNotEquals(Order::TEMP, $payment_order->code); + return $payment_order; + } + + public function testCompleteDelivery() + { + $handler = new OrderHandler(); + $order = $this->testMakePayment(); + $order->orderItems()->each(function(OrderItem $orderItem){ + $sellType = $orderItem->sellType; + $sellType->delivery()->associate(DeliveryCompany::first()); + }); + $order->orderItems->each(function(OrderItem $orderItem) use($handler){ + $handler->completeDelivery($orderItem); + }); + $order = $handler->update($order); + + $this->assertEquals(\Xpressengine\Plugins\XeroCommerce\Models\Order::COMPLETE, $order->code); + } + + public function testIdUpdate() + { + $order =$this->testRegister(); + $order->user_id='notfound'; + $handler = new OrderHandler(); + $handler->idUpdate($order); + $this->assertNotEquals('notfound', $order->user_id); + } + + public function testChangeOrderItem() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $orderItem = $order->orderItems()->first(); + $afterOrder = $handler->changeOrderItem($orderItem, OrderItem::EXCHANGED); + $this->assertNotEquals(Order::ORDERED, $afterOrder->code); + } + + public function testOrderCancel() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $afterOrder = $handler->orderCancel($order,'test'); + $this->assertEquals(Order::CANCELED, $afterOrder->code); + } + + public function testGetSellSetList() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $list = $handler->getSellSetList(); + $this->assertTrue(is_iterable($list)); + } + + public function testGetAfterserviceList() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $list = $handler->getAfterserviceList(); + $this->assertTrue(is_iterable($list)); + } + + public function testGetOrderList() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $list = $handler->getOrderList(1,1); + $this->assertInstanceOf(Paginator::class,$list); + } + + public function testShipNoRegister() + { + $handler = new OrderHandler(); + $order=$this->testMakePayment(); + $order_item= $order->orderItems()->first(); + $updated_order = $handler->shipNoRegister($order_item, 'test'); + $this->assertNotEquals(Order::ORDERED,$updated_order->code); + + } + + public function testDailyBoard() + { + $handler = new OrderHandler(); + $board = $handler->dailyBoard(); + $this->assertArrayHasKey('days',$board); + $this->assertArrayHasKey('count',$board); + } + + public function testWhereUser() + { + $handler = new OrderHandler(); + $query = $handler->whereUser()->select(); + $this->assertInstanceOf(\Xpressengine\Database\Eloquent\Builder::class, $query); + } + + public function testDashboard() + { + $handler = new OrderHandler(); + $dash = $handler->dashboard(); + $this->assertEquals(count(Order::STATUS), count($dash)); + } +} diff --git a/tests/Unit/ProductCategoryHandlerTest.php b/tests/Unit/ProductCategoryHandlerTest.php new file mode 100644 index 0000000..7ae2feb --- /dev/null +++ b/tests/Unit/ProductCategoryHandlerTest.php @@ -0,0 +1,42 @@ +makeProduct(); + $handler->store($product->id,[1]); + $this->assertNotEquals(0,ProductCategory::where('product_id',$product->id)->count()); + } + + public function testRemove() + { + $handler = new ProductCategoryHandler(); + $this->testStore(); + $product = Product::first(); + $handler->remove($product->id); + $this->assertEquals(0,ProductCategory::where('product_id',$product->id)->count()); + } + + public function testGetIds() + { + $handler = new ProductCategoryHandler(); + $product = $this->makeProduct(); + $list = $handler->getIds($product->id); + $this->assertTrue(is_iterable($list)); + } +} diff --git a/tests/Unit/ProductHandlerTest.php b/tests/Unit/ProductHandlerTest.php new file mode 100644 index 0000000..f718818 --- /dev/null +++ b/tests/Unit/ProductHandlerTest.php @@ -0,0 +1,117 @@ +makeProduct(); + $handler = new ProductHandler(); + $product = $handler->getProduct($product->id); + $this->assertNotNull($product); + } + + public function testGetSortAble() + { + $sort_list = ProductHandler::getSortAble(); + $this->assertTrue(is_iterable($sort_list)); + } + + public function testStore() + { + $handler = new ProductHandler(); + $args = [ + 'shop_id' => 1, + 'product_code'=>'test', + 'infoKeys'=>['test'], + 'infoValues'=>['hello'], + 'name'=>'test', + 'sub_name'=>'test', + 'original_price'=>1000, + 'sell_price'=>1000, + 'discount_percentage'=>100, + 'description'=>'test', + 'tax_type'=>1, + 'state_display'=>1, + 'state_deal'=>1, + 'shop_delivery_id'=>1, + 'images'=>[] + ]; + $product = $handler->store($args); + $this->assertNotNull($product); + } + + public function testGetProductsQueryForSetting() + { + $request = \Mockery::mock(Request::class); + $request->shouldReceive('all')->andReturn([ + 'product_name'=>'test', + 'product_code'=>'test', + 'product_deal_state'=>0, + 'product_display_state'=>0, + 'product_tax_type'=>0 + ]); + $handler = new ProductHandler(); + $query = $handler->getProductsQueryForSetting($request); + $ormcollection=$query->get(); + $this->assertInstanceOf(Collection::class, $ormcollection); + } + + public function testSetPublish() + { + $handler = new ProductHandler(); + $product = $this->makeProduct(); + $handler->setPublish($product->id,true); + $this->assertTrue((bool)Product::find($product->id)->publish); + $handler->setPublish($product->id,false); + $this->assertFalse((bool)Product::find($product->id)->publish); + } + + public function testGetProductsQueryForWidget() + { + $handler = new ProductHandler(); + $request = \Mockery::mock(Request::class); + $request->shouldReceive('all')->andReturn([]); + $query = $handler->getProductsQueryForWidget($request); + $ormcollection=$query->get(); + $this->assertInstanceOf(Collection::class, $ormcollection); + } + + public function testDestroy() + { + $handler = new ProductHandler(); + $product = $this->makeProduct(); + $handler->destroy($product); + $this->assertNull(Product::find($product->id)); + } + + public function testUpdate() + { + $handler = new ProductHandler(); + $product=$this->makeProduct(); + $args = [ + 'name'=>'updateTest', + 'sub_name'=>'test', + 'images'=>[] + ]; + $handler->update($product, $args); + $this->assertEquals('updateTest',Product::find($product->id)->name); + } +} diff --git a/tests/Unit/ProductOptionItemHandlerTest.php b/tests/Unit/ProductOptionItemHandlerTest.php new file mode 100644 index 0000000..4d20a1e --- /dev/null +++ b/tests/Unit/ProductOptionItemHandlerTest.php @@ -0,0 +1,67 @@ +1, + 'option_type'=>ProductOptionItem::TYPE_ADDITION_ITEM, + 'name'=>'test', + 'addition_price'=>0, + 'stock'=>10, + 'alert_stock'=>0, + 'state_display'=>0, + 'state_deal'=>0 + ]; + $handler->store($args); + $this->assertNotEquals(0,ProductOptionItem::count()); + } + + public function testGetOptionItem() + { + $handler = new ProductOptionItemHandler(); + $this->testStore(); + $item = ProductOptionItem::first(); + $item = $handler->getOptionItem($item->id); + $this->assertNotNull($item); + } + + public function testUpdate() + { + $handler = new ProductOptionItemHandler(); + $this->testStore(); + $item = ProductOptionItem::first(); + $id = $item->id; + $args = [ + 'name'=>'updateTest' + ]; + $handler->update($item, $args); + $this->assertEquals('updateTest',ProductOptionItem::find($id)->name); + } + + public function testDestroy() + { + $handler = new ProductOptionItemHandler(); + $this->testStore(); + $item = ProductOptionItem::first(); + $id = $item->id; + $handler->destroy($item); + $this->assertNull(ProductOptionItem::find($id)); + + } +} diff --git a/tests/Unit/QnaHandlerTest.php b/tests/Unit/QnaHandlerTest.php new file mode 100644 index 0000000..96b245d --- /dev/null +++ b/tests/Unit/QnaHandlerTest.php @@ -0,0 +1,61 @@ +makeProduct(); + $args=[ + 'title'=>'test', + 'content'=>'test' + ]; + $handler->store($product,$args); + $this->assertNotEquals(0,$product->qna()->count()); + } + + public function testGet() + { + $this->testStore(); + $handler = new QnaHandler(); + $product = Product::first(); + $list = $handler->get($product); + $this->assertNotEquals(0,$list->count()); + } + + public function testUpdate() + { + $handler = new QnaHandler(); + $this->testStore(); + $qna = Qna::first(); + $args=[ + 'content'=>'updateTest' + ]; + $handler->update($qna,$args); + $this->assertEquals('updateTest',Qna::find($qna->id)->content); + } + + public function testDelete() + { + $handler = new QnaHandler(); + $this->testStore(); + $feedback = Qna::first(); + $feedback_id = $feedback->id; + $handler->delete($feedback); + $this->assertNull(Qna::find($feedback_id)); + } +} diff --git a/tests/Unit/ShopHandlerTest.php b/tests/Unit/ShopHandlerTest.php new file mode 100644 index 0000000..c2efc24 --- /dev/null +++ b/tests/Unit/ShopHandlerTest.php @@ -0,0 +1,81 @@ +'test', + 'shop_eng_name'=>'test', + 'shop_type'=>Shop::TYPE_INDIVIDUAL, + 'state_approval'=>Shop::APPROVAL_WAITING, + 'delivery_info'=>'', + 'as_info'=>'', + 'user_id'=>Auth::id() + ]; + $handler->store($args); + $this->assertNotEquals(0, Shop::count()); + } + + public function testGetShopsQuery() + { + $handler= new ShopHandler(); + $query = $handler->getShopsQuery( + [ + 'user_id'=>'test', + 'shop_name'=>'test' + ] + ); + $this->assertInstanceOf(Builder::class, $query); + } + + public function testGetShop() + { + $handler = new ShopHandler(); + $this->testStore(); + $shop = Shop::first(); + $return = $handler->getShop($shop->id); + $this->assertNotNull($return); + } + + public function testUpdate() + { + + $handler = new ShopHandler(); + $this->testStore(); + $shop = Shop::first(); + $handler->update([ + 'shop_name'=>'updateTest' + ], $shop); + $this->assertEquals('updateTest', $shop->shop_name); + } + + public function testDestroy() + { + + + $handler = new ShopHandler(); + $this->testStore(); + $shop = Shop::first(); + $handler->destroy($shop->id); + $this->assertEquals(0, Shop::count()); + } +} diff --git a/tests/Unit/ShopUserHandlerTest.php b/tests/Unit/ShopUserHandlerTest.php new file mode 100644 index 0000000..021410f --- /dev/null +++ b/tests/Unit/ShopUserHandlerTest.php @@ -0,0 +1,44 @@ +1, + 'user_id'=>1 + ]; + $handler->store($args); + $this->assertNotEquals(0, ShopUser::count()); + } + + public function testGetUsersShop() + { + $this->testStore(); + $handler = new ShopUserHandler(); + $shops = $handler->getUsersShop(1); + $this->assertTrue($shops->where('shop_id',1)->count()>0); + } + + public function testGetShopsUser() + { + $this->testStore(); + $handler = new ShopUserHandler(); + $users = $handler->getShopsUser(1); + $this->assertTrue($users->where('user_id',1)->count()>0); + } +} diff --git a/tests/Unit/WishHandlerTest.php b/tests/Unit/WishHandlerTest.php new file mode 100644 index 0000000..c319b2d --- /dev/null +++ b/tests/Unit/WishHandlerTest.php @@ -0,0 +1,76 @@ +makeProduct(); + $handler->store($product); + $this->assertNotEquals(0, Wish::count()); + } + + public function testStoreMany() + { + $handler = new WishHandler(); + $product = $this->makeProduct(); + $handler->storeMany(Product::all()); + $this->assertNotEquals(0, Wish::count()); + } + + public function testIsWish() + { + $handler = new WishHandler(); + $this->testStore(); + $product = Product::first(); + $result = $handler->isWish($product); + $this->assertTrue($result); + + } + + public function testList() + { + $handler = new WishHandler(); + $list = $handler->list(); + $this->assertTrue(is_iterable($list)); + } + + public function testRemoveByModel() + { + $handler = new WishHandler(); + $this->testStore(); + $wish = Wish::first(); + $id = $wish->id; + $handler->removeByModel($wish); + $this->assertNull(Wish::find($id)); + } + + public function testRemove() + { + $handler = new WishHandler(); + $this->testStore(); + $product =Product::first(); + $handler->remove($product); + } + + public function testRemoveMany() + { + $handler = new WishHandler(); + $this->testStore(); + $handler->removeMany(Wish::pluck('id')); + } +} diff --git a/tests/Unit/XeroCommerceImageHandlerTest.php b/tests/Unit/XeroCommerceImageHandlerTest.php new file mode 100644 index 0000000..36b23e6 --- /dev/null +++ b/tests/Unit/XeroCommerceImageHandlerTest.php @@ -0,0 +1,72 @@ +bind('xe.storage', function () { + $storage = \Mockery::mock(Storage::class); + $storage->shouldReceive('create')->andReturn(new File()); + $storage->shouldReceive('find')->andReturn(new File()); + $storage->shouldReceive('delete')->andReturn(new File()); + return $storage; + }); + Thumbnailer::setManager(new ImageManager()); + } + + public function test__construct() + { + $handler = new XeroCommerceImageHandler(); + $this->assertNotNull($handler); + } + + public function testResize() + { + $handler = new XeroCommerceImageHandler(); + $file = UploadedFile::fake()->image('../../assets/sample/tmp_cross.jpg'); + $img = $handler->resize($file, 100, 100); + $this->assertNotNull($img); + } + + public function testSaveImage() + { + $handler = new XeroCommerceImageHandler(); + $file = UploadedFile::fake()->image('../../assets/sample/tmp_cross.jpg'); + $image = $handler->saveImage($file, './testImage'); + $this->assertInstanceOf(File::class, $image); + } + + public function testRemoveFile() + { + $handler = new XeroCommerceImageHandler(); + $result = $handler->removeFile('file_id'); + $this->assertNull($result); + } + + public function getImageUrlByFileId() + { + $handler = new XeroCommerceImageHandler(); + $result = $handler->getImageUrlByFileId('none_file_id'); + $this->assertEquals('',$result); + + } +} diff --git a/tests/Unit/test.db b/tests/Unit/test.db new file mode 100644 index 0000000..ccbf009 Binary files /dev/null and b/tests/Unit/test.db differ