public function testUpdate()
 {
     $faker = TestCase::faker();
     $product = TestCase::getFixture('products.product_8');
     /*
      * NOT OK
      */
     // "product" not defined
     $response = $this->callJSON('PATCH', "/api/v1/products/{$product->sku}");
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     /*
      * OK
      */
     // "product" defined but empty
     $response = $this->callJSON('PATCH', "/api/v1/products/{$product->sku}", array('product' => array()));
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('product', $this->productJSONFormat);
     $this->assertJSONEquals('product', $product);
     // "products" with datas
     $data = array('name' => $faker->word);
     $response = $this->callJSON('PATCH', "/api/v1/products/{$product->sku}", array('product' => $data));
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('product', $this->productJSONFormat);
     $this->assertJSONEquals('product', $data);
 }
 public function testUpdate()
 {
     $setting = Subbly::api('subbly.setting')->all()->take(1)->toArray();
     $settingValue = reset($setting);
     $settingKey = key($setting);
     /**
      * NOT OK
      */
     // "setting" not defined
     $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}");
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     /**
      * OK
      */
     $settingKey = 'test.subbly.string_setting';
     // Test with string setting and with wrong array value
     $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}", array('value' => array()));
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     // "settings" with datas
     $value = TestCase::faker()->word;
     $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}", array('value' => $value));
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     // $json = $this->getJSONContent();
 }
 public function run()
 {
     $faker = TestCase::faker();
     for ($i = 1; $i <= 10; $i++) {
         $productCategory = ProductCategory::create(array('product_id' => TestCase::getFixture('products.product_1')->id, 'name' => $faker->name));
         TestCase::addFixture('product_categories.product_category_' . $i, $productCategory);
     }
 }
 public function testFind()
 {
     $fixture = TestCase::getFixture('product_images.product_image_4');
     $uid = $fixture->uid;
     $productImage = $this->getService()->find($uid);
     $this->assertInstanceOf('Subbly\\Model\\ProductImage', $productImage);
     $this->assertEquals($fixture->name, $productImage->name);
 }
 public function run()
 {
     $faker = TestCase::faker();
     for ($i = 1; $i <= 10; $i++) {
         $userAddress = UserAddress::create(array('user_id' => TestCase::getFixture('users.jon_snow')->id, 'name' => $faker->name, 'firstname' => $faker->firstName, 'lastname' => $faker->lastName, 'address1' => $faker->streetAddress, 'zipcode' => $faker->postcode, 'city' => $faker->city, 'country' => $faker->country, 'phone_work' => rand(0, 1) === 0 ? null : $faker->phoneNumber, 'phone_home' => rand(0, 1) === 0 ? null : $faker->phoneNumber, 'phone_mobile' => rand(0, 1) === 0 ? null : $faker->phoneNumber));
         TestCase::addFixture('user_addresses.user_address_' . $i, $userAddress);
     }
 }
 public function run()
 {
     $faker = TestCase::faker();
     for ($i = 1; $i <= 10; $i++) {
         $order = Order::create(array('user_id' => TestCase::getFixture('users.jon_snow')->id));
         TestCase::addFixture('orders.order_' . $i, $order);
     }
 }
Exemple #7
0
 public function run()
 {
     $faker = TestCase::faker();
     for ($i = 1; $i <= 10; $i++) {
         $price = round($faker->randomFloat(2, 0, 99999999.98999999), 2);
         $sale_price = round($price - $price * (rand(5, 25) / 100), 2);
         $product = Product::create(array('sku' => $faker->unique()->bothify('????????##'), 'name' => $faker->words(3, true), 'description' => $faker->text(), 'price' => (double) $price, 'sale_price' => (double) ($i % 2) === 0 ? null : $sale_price, 'quantity' => $faker->randomNumber(4)));
         TestCase::addFixture('products.product_' . $i, $product);
     }
 }
 public function testFind()
 {
     $fixture = TestCase::getFixture('user_addresses.user_address_4');
     $uid = $fixture->uid;
     $userAddress = $this->getService()->find($uid);
     $this->assertInstanceOf('Subbly\\Model\\UserAddress', $userAddress);
     $this->assertEquals($fixture->name, $userAddress->name);
     $this->assertEquals($fixture->firstname, $userAddress->firstname);
     $this->assertEquals($fixture->lastname, $userAddress->lastname);
 }
Exemple #9
0
 public function run()
 {
     $faker = TestCase::faker();
     $user = User::create(array('email' => '*****@*****.**', 'password' => 'hodor123', 'firstname' => 'Jon', 'lastname' => 'Snow', 'activated' => true));
     TestCase::addFixture('users.jon_snow', $user);
     // generate some others users
     for ($i = 1; $i <= 10; $i++) {
         $user = User::create(array('email' => $faker->email, 'password' => $faker->password(), 'firstname' => $faker->firstName, 'lastname' => $faker->lastName, 'activated' => $i === 0 ? true : rand(0, 1)));
         TestCase::addFixture('users.user_' . $i, $user);
     }
 }
Exemple #10
0
 public function testShow()
 {
     // TODO test 404
     $order = TestCase::getFixture('orders.order_1');
     $response = $this->callJSON('GET', "/api/v1/orders/{$order->id}");
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('order', $this->orderJSONFormat);
     $this->assertJSONEquals('order', $order);
 }
Exemple #11
0
 public function testFind()
 {
     $fixture = TestCase::getFixture('orders.order_1');
     $id = $fixture->id;
     $order = $this->getService()->find($id);
     $this->assertInstanceOf('Subbly\\Model\\Order', $order);
     $this->assertEquals($fixture->id, $order->id);
     $this->assertEquals($fixture->user, $order->user);
     $this->assertEquals($fixture->total_price, $order->total_price);
     $this->assertEquals($fixture->status, $order->status);
 }
 public function run()
 {
     $groups = array(array('name' => 'Administrator', 'permissions' => array('subbly.backend.auth' => 1, 'subbly.backend.products' => 1, 'subbly.backend.settings' => 1, 'subbly.frontend' => 1)), array('name' => 'Customer', 'permissions' => array('subbly.frontend' => 1)));
     foreach ($groups as $group) {
         try {
             $group = Sentry::createGroup($group);
             TestCase::addFixture('groups.group_' . snake_case($group['name']), $group);
         } catch (\Exception $e) {
         }
     }
 }
Exemple #13
0
 public function testUpdate()
 {
     $faker = TestCase::faker();
     $user = TestCase::getFixture('users.user_1');
     // Events
     Subbly::events()->listen($this->getService()->name() . ':updating', function ($model) use($user) {
         $this->assertEquals($user->id, $model->id);
         Subbly::events()->forget($this->getService()->name() . ':updating');
     });
     Subbly::events()->listen($this->getService()->name() . ':updated', function ($model) use($user) {
         $this->assertEquals($user->id, $model->id);
         Subbly::events()->forget($this->getService()->name() . ':updated');
     });
     $user->firstname = $faker->firstname;
     $user->lastname = $faker->lastname;
     $returnedUser = $this->getService()->update($user);
     $this->assertInstanceOf('Subbly\\Model\\User', $user);
     $this->assertInstanceOf('Subbly\\Model\\User', $returnedUser);
     $this->assertEquals($user->id, $returnedUser->id);
 }
 public function testStore()
 {
     $faker = TestCase::faker();
     $user = TestCase::getFixture('users.jon_snow');
     /*
      * NOT OK
      */
     // "user_address" not defined
     $response = $this->callJSON('POST', "/api/v1/users/{$user->uid}/addresses");
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     // :user_uid not found
     $response = $this->callJSON('POST', "/api/v1/users/b42fdf18bbd6291136f3b48b9ab378dd/addresses");
     $this->assertResponseStatus(404);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     // "user" defined but empty
     $response = $this->callJSON('POST', "/api/v1/users/{$user->uid}/addresses", array('user_address' => array()));
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     /*
      * OK
      */
     $data = array('name' => $faker->name, 'firstname' => $faker->firstName, 'lastname' => $faker->lastName, 'address1' => $faker->streetAddress, 'zipcode' => $faker->postcode, 'city' => $faker->city, 'country' => $faker->country);
     $response = $this->callJSON('POST', "/api/v1/users/{$user->uid}/addresses", array('user_address' => $data));
     $this->assertResponseStatus(201);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('user_address', $this->userAddressJSONFormat);
     $this->assertJSONEquals('user_address', $data);
 }
 public function testUpdate()
 {
     $user = TestCase::getFixture('users.user_8');
     /*
      * NOT OK
      */
     // "user" not defined
     $response = $this->callJSON('PATCH', "/api/v1/users/{$user->uid}");
     $this->assertResponseStatus(400);
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertObjectHasAttribute('error', $json->response);
     /*
      * OK
      */
     // "user" defined but empty
     $response = $this->callJSON('PATCH', "/api/v1/users/{$user->uid}", array('user' => array()));
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('user', $this->userJSONFormat);
     $this->assertJSONEquals('user', $user);
     // "users" with datas
     $data = array('firstname' => TestCase::faker()->firstName);
     $response = $this->callJSON('PATCH', "/api/v1/users/{$user->uid}", array('user' => $data));
     $this->assertResponseOk();
     $this->assertResponseJSONValid();
     $json = $this->getJSONContent();
     $this->assertJSONTypes('user', $this->userJSONFormat);
     $this->assertJSONEquals('user', $data);
 }