Exemplo n.º 1
0
 public function testEvaluatesToTrueIfArgumentIsNull()
 {
     assertThat(null, nullValue());
     assertThat(self::ANY_NON_NULL_ARGUMENT, not(nullValue()));
     assertThat(self::ANY_NON_NULL_ARGUMENT, notNullValue());
     assertThat(null, not(notNullValue()));
 }
 public function testSubProductMatchingVendorIdWorks()
 {
     $sub_product = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['vendor_id' => 'asin stub']);
     $sub_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['vendor_id' => 'asin stub2']);
     $sub_product_repo = $this->app->make('Giftertipster\\Repository\\SubProduct\\EloquentSubProductRepository');
     $result_sub_product = $sub_product_repo->subProductMatchingVendorId('asin stub');
     assertThat($result_sub_product, notNullValue());
     assertThat($result_sub_product['id'], equalTo(1));
     assertThat($result_sub_product, hasKey('images'));
 }
 public function testHandleCsv()
 {
     $dbManager = M::mock(DbManager::classname());
     $licenseCsvImport = new LicenseCsvImport($dbManager);
     Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleCsv', array(array('shortname', 'foo', 'text', 'fullname', 'notes')));
     assertThat(Reflectory::getObjectsProperty($licenseCsvImport, 'headrow'), is(notNullValue()));
     $dbManager->shouldReceive('getSingleRow')->with('SELECT rf_shortname,rf_source,rf_pk,rf_risk FROM license_ref WHERE rf_md5=md5($1)', anything())->andReturn(false);
     $dbManager->shouldReceive('prepare');
     $dbManager->shouldReceive('execute');
     $dbManager->shouldReceive('freeResult');
     $dbManager->shouldReceive('fetchArray')->andReturn(array('rf_pk' => 101, 'rf_risk' => 1));
     Reflectory::setObjectsProperty($licenseCsvImport, 'nkMap', array('licA' => false));
     Reflectory::invokeObjectsMethodnameWith($licenseCsvImport, 'handleCsv', array(array('licA', 'bar', 'txA', 'liceA', 'noteA')));
     assertThat(Reflectory::getObjectsProperty($licenseCsvImport, 'nkMap'), is(array('licA' => 101)));
 }
 public function testProductMatchingAsinWorksWhenProductMatches()
 {
     $product = Factory::create('Giftertipster\\Entity\\Eloquent\\Product');
     $product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', ['vendor_id' => 'asin stub']);
     $product_repo = $this->app->make('Giftertipster\\Repository\\Product\\EloquentProductRepository');
     $result_product = $product_repo->productMatchingAsin('asin stub');
     assertThat($result_product, notNullValue());
     assertThat($result_product['id'], equalTo(2));
 }
 public function testDeleteRollsBacknOnIndexDeleteFail()
 {
     $index_repo = Mockery::mock('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface');
     $index_repo->shouldReceive('deleteProductAndAdds')->with(1, true)->once()->andThrow(new \Exception());
     $index_repo->shouldReceive('errors');
     $this->app->instance('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface', $index_repo);
     $data_repo = $this->dataRepoSetup();
     $exception_thrown = false;
     try {
         //index repo is set to return false so this should fail
         $data_repo->delete(1);
     } catch (\Exception $e) {
         $exception_thrown = true;
     }
     assertThat($exception_thrown, identicalTo(true));
     $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product');
     $product = $product->find(1);
     assertThat($product, notNullValue());
 }
 public function testFinderCreateLogsNoticeWhenSomeSubProductVariationsAttributesAreInvalid()
 {
     Factory::create('Giftertipster\\Entity\\Eloquent\\Idea', ['user_id' => 1, 'is_fulfilled' => 0]);
     $suite_attributes = ['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'];
     $suite_attributes['images'] = [];
     $suite_attributes['features'] = [];
     $suite_attributes['descriptions'] = [];
     $suite_attributes['sub_products'][] = ['vendor' => 'amazon', 'vendor_id' => 'b000001', 'parent_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', 'condition' => 'test condition', 'department' => 'test department', 'list_price_amount' => 4000, 'list_price_currency' => 'USD', 'list_price_formatted' => '$40.00', 'price_amount' => 4000, 'price_currency' => 'USD', 'price_formatted' => '$40.00', 'availability' => 'test avail', 'availability_type' => 'test avail type', 'availability_max_hours' => 'test avail max hours', 'availability_min_hours' => 'test avail min hours', 'availability_ship' => 'test avail ship', 'availability_ss_ship' => 1, 'offer_listing_id' => 'foo1', 'images' => [], 'descriptions' => [], 'features' => []];
     $suite_attributes['sub_products'][0]['variations'][] = ['type' => 'variationtype', 'value' => 'variation1'];
     $suite_attributes['sub_products'][0]['variations'][] = ['type' => '', 'value' => 'variation2'];
     $suite_attributes['keyword_profile']['profile'] = [];
     $suite_attributes['category_keywords'] = [];
     $expected_index_attributes = ['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'];
     $expected_index_attributes['images'] = [];
     $expected_index_attributes['features'] = [];
     $expected_index_attributes['descriptions'] = [];
     $expected_index_attributes['sub_products'][] = ['vendor' => 'amazon', 'vendor_id' => 'b000001', 'parent_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', 'condition' => 'test condition', 'department' => 'test department', 'list_price_amount' => 4000, 'list_price_currency' => 'USD', 'list_price_formatted' => '$40.00', 'price_amount' => 4000, 'price_currency' => 'USD', 'price_formatted' => '$40.00', 'availability' => 'test avail', 'availability_type' => 'test avail type', 'availability_max_hours' => 'test avail max hours', 'availability_min_hours' => 'test avail min hours', 'availability_ship' => 'test avail ship', 'availability_ss_ship' => 1, 'offer_listing_id' => 'foo1', 'images' => [], 'descriptions' => [], 'features' => []];
     $expected_index_attributes['sub_products'][0]['variations'][] = ['type' => 'variationtype', 'value' => 'variation1'];
     $expected_index_attributes['keyword_profile']['profile'] = [];
     $expected_index_attributes['category_keywords'] = [];
     \Log::shouldReceive('notice')->once();
     //mock ProductSuiteIndexer
     $expected_product_suite = $expected_index_attributes;
     $indexer = Mockery::mock('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface');
     $indexer->shouldReceive('queueIndex')->with(Mockery::on(function ($product_suite) use($expected_product_suite) {
         if (!empty($this->arrayRecursiveDiff($expected_product_suite, $product_suite))) {
             return false;
         }
         return true;
     }), false, false)->once()->andReturn(true);
     $this->app->instance('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface', $indexer);
     $repo = $this->app->make('Giftertipster\\Repository\\ProductSuite\\EloquentProductSuiteRepository');
     $response = $repo->finderCreate($suite_attributes, 'Idea', 1, 2);
     $errors = $repo->errors();
     assertThat($response, equalTo(true));
     $eloquent_product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product');
     $product = $eloquent_product->find(1);
     $eloquent_variation = $this->app->make('Giftertipster\\Entity\\Eloquent\\Variation');
     $sub_product_variation = $eloquent_variation->where('sub_product_id', '=', 1)->get()->toArray();
     assertThat($errors, nullValue());
     assertThat($product, notNullValue());
     assertThat($sub_product_variation, arrayWithSize(1));
 }