/** * @test **/ public function it_saves_db_data_on_commit_and_clear_session() { $service = new OrderServiceStub(); $product = Product::create(["description" => "desc", "code" => "code", "name" => "name", "slug" => "slug", "slug_lang" => "", "description_long" => "", "featured" => 1, "public" => 1, "offer" => 1, "stock" => 4, "video_link" => "http://www.google.com/video/12312422313", "price" => "1.12"]); $user_stub = new User(); $user_stub->id = 1; // mock authenticator $mock_auth = m::mock('StdClass')->shouldReceive('check')->once()->andReturn(true)->shouldReceive('getLoggedUser')->andReturn($user_stub)->shouldReceive('getLoggedUserProfile')->andReturn([])->getMock(); $quantity = 10; App::instance('authenticator', $mock_auth); $service->addRow($product, $quantity); // mock mailer $mock_mailer = m::mock('Palmabit\\Library\\Email\\MailerInterface')->shouldReceive('sendTo')->andReturn(true)->getMock(); App::instance('palmamailer', $mock_mailer); // mock auth helper $mock_auth_helper = m::mock('StdClass')->shouldReceive('getNotificationRegistrationUsersEmail')->once()->andReturn([""])->getMock(); App::instance('authentication_helper', $mock_auth_helper); $service->commit(); $row = RowOrder::first(); $this->assertEquals(1, $row->id); $this->assertFalse(Session::has($service->getSessionKey())); $this->assertFalse(Session::has($service->getSessionMailOrder())); }
/** * @test **/ public function it_saves_himself_and_his_collection_to_db_and_set_completed_and_user_id() { $order = new Order(); $product = new Product(["description" => "desc", "code" => "code", "name" => "name", "slug" => "slug", "slug_lang" => "", "description_long" => "", "featured" => 1, "public" => 1, "offer" => 1, "stock" => 4, "video_link" => "http://www.google.com/video/12312422313", "price" => "1.00", "quantity_pricing_quantity" => 10, "quantity_pricing_enabled" => 1]); $mock_row = m::mock('Palmabit\\Catalog\\Models\\RowOrder')->makePartial()->shouldReceive('setItem')->once()->with($product, 10)->andReturn(true)->getMock(); $mock_row->product_id = 10; $mock_row->quantity = 1; $mock_row->total_price = 1.0; $mock_row->single_price = 1.0; $order->addRow($product, 10, $mock_row); $user_stub = new User(); $user_stub->id = 10; $mock_auth = m::mock('StdClass')->shouldReceive('getLoggedUser')->once()->andReturn($user_stub)->getMock(); App::instance('authenticator', $mock_auth); $order->save(); // set completed state $this->assertTrue($order->completed); // set user_id $this->assertEquals(10, $order->user_id); // save his collection $row = RowOrder::first(); $this->assertEquals(10, $row->product_id); $this->assertEquals($order->id, $order->getRowOrders()->first()->order_id); }