public function setUp() { parent::setUp(); Artisan::call('migrate'); Product::boot(); Description::boot(); SubProduct::boot(); Image::boot(); Feature::boot(); Variation::boot(); KeywordProfile::boot(); Add::boot(); //es client and index repo for testing integration with index $this->es_client = $this->app->make('Elasticsearch\\Client'); $this->index_repo = $this->app->make('Giftertipster\\Repository\\ProductsIndex\\Product\\ESProductsIndexProductRepository'); $this->config = \Config::get('index.index_products_type_product'); $this->index = $this->config['setup']['index']; $this->type = $this->config['setup']['type']; //seed user id 1 & 2 for tests Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); //seed add type id 1 for tests Factory::create('Giftertipster\\Entity\\Eloquent\\AddType'); $this->createStubCategories(); //mock prod suite validator (validates suite attributes keys) //may be overriden in individual tests $suite_validator = \Mockery::mock('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface'); $suite_validator->shouldReceive('validateSuiteAttributesForCreate')->andReturn(true); $suite_validator->shouldReceive('validateSuiteAttributesForUpdate')->andReturn(true); $this->app->instance('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface', $suite_validator); }
public function testDeleteDeletesProductAndIdeaRelationAndReturnsTrue() { $index_repo = Mockery::mock('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface'); $index_repo->shouldReceive('deleteProductAndAdds')->with(1, true)->once()->andReturn(true); $this->app->instance('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface', $index_repo); $data_repo = $this->dataRepoSetup(); $this->getDataRepoData(); //make second product $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $product->fill(['user_id' => 1, 'vendor' => 'amazon', 'vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'test title', 'department' => 'test department', 'min_price_amount' => 4000, 'min_price_currency' => 'USD', 'min_price_formatted' => '$40.00', 'max_price_amount' => 4000, 'max_price_currency' => 'USD', 'max_price_formatted' => '$40.00', 'reviews_url' => 'reviewsurl.com', 'detail_url' => 'detailurl.com'])->save(); //connect products to idea Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $idea = $this->app->make('Giftertipster\\Entity\\Eloquent\\Idea'); $idea->fill(['user_id' => 1, 'vendor' => 'test', 'vendor_id' => 100, 'description' => 'test', 'add_profile' => '', 'is_fulfilled' => 0]); $this->product->ideas()->save($idea); //product id 1 $product->ideas()->save($idea); //product id 2 $idea_check = $idea->where('product_id', '=', 1)->get(); assertThat($idea_check, not(nullValue())); $idea_check = $idea->where('product_id', '=', 2)->get(); assertThat($idea_check, not(nullValue())); //ACTION $response = $data_repo->delete(1); assertThat($response, identicalTo(true)); $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $product_check = $product->find(1); $idea_check = $idea->has('products')->get()->toArray(); assertThat($product_check, nullValue()); assertThat($idea_check, arrayWithSize(1)); assertThat($idea->exists(), equalTo(true)); //get keyword profile check data $keyword_profile = $this->app->make('Giftertipster\\Entity\\Eloquent\\KeywordProfile'); $keyword_profile_check = $keyword_profile->get()->toArray(); $occasion_category = $this->app->make('Giftertipster\\Entity\\Eloquent\\Category\\OccasionCategory'); $occasion_category_count = $occasion_category->get()->count(); //get "add" check data $add = $this->app->make('Giftertipster\\Entity\\Eloquent\\Add'); $add_check = $add->get()->toArray(); $add_category_pivot_check = \DB::table('add_categories')->get(); assertThat($keyword_profile_check, emptyArray()); assertThat($occasion_category_count, greaterThan(0)); assertThat($add_check, emptyArray()); assertThat($add_category_pivot_check, emptyArray()); assertThat(Image::get()->toArray(), emptyArray()); assertThat(Description::get()->toArray(), emptyArray()); assertThat(Feature::get()->toArray(), emptyArray()); assertThat(SubProduct::get()->toArray(), emptyArray()); assertThat(Variation::get()->toArray(), emptyArray()); }