public function testGetMostViewed() { $user = Factory::create('User'); $this->be($user); $snippets = array(); $tag = Factory::create('Tag'); // create 3 approved snippets for ($i = 0; $i < 3; $i++) { $snippets[] = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); } $redis = App::make('redis'); // add 10 hits in snippet[1] $redis->zIncrBy('hits', 10, $snippets[1]->id); // add 5 hits in snippet[2] $redis->zIncrBy('hits', 5, $snippets[2]->id); // add 1 hit in snippet[0] $redis->zIncrBy('hits', 1, $snippets[0]->id); // expected ranking: // 1. $snippets[1] // 2. $snippets[2] // 3. $snippets[0] $snippetRepo = new EloquentSnippetRepository(new Snippet(), $this->app->make('LaraSnipp\\Repo\\Tag\\TagRepositoryInterface'), $this->app->make('LaraSnipp\\Repo\\User\\UserRepositoryInterface')); $snippetsResult = $snippetRepo->getMostViewed(); $this->assertEquals($snippets[1], $snippetsResult[0]); }
public function testHomePageTopSnippetContributors() { // with 2 approved and 1 not yet approved snippet $user = Factory::create('User', array('active' => 1)); $this->be($user); Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null)); // with 1 not yet approved snippet $secondUser = Factory::create('User', array('active' => 1)); $this->be($secondUser); Factory::create('Snippet', array('author_id' => $secondUser->id, 'approved' => 0, 'deleted_at' => null)); // with 1 approved and 3 not yet approved snippets $thirdUser = Factory::create('User', array('active' => 1)); $this->be($thirdUser); Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 1, 'deleted_at' => null)); Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null)); Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null)); Factory::create('Snippet', array('author_id' => $thirdUser->id, 'approved' => 0, 'deleted_at' => null)); $response = $this->call('GET', '/'); $view = $response->original; // only 2 is expected since we are only rendering contributors w/ approved snippets $this->assertEquals(count($view['topSnippetContributors']), 2); # rank 1 should be $user $this->assertEquals($view['topSnippetContributors'][0]->full_name, $user->full_name); $this->assertEquals($view['topSnippetContributors'][0]->snippets_count, 2); # rank 2 should be $thirdUser $this->assertEquals($view['topSnippetContributors'][1]->full_name, $thirdUser->full_name); $this->assertEquals($view['topSnippetContributors'][1]->snippets_count, 1); }
public function test_validacion_exitosa_con_clave_foranea_lugar() { $padre = Factory::create('App\\Lugar'); $lugar = Factory::attributesFor('App\\Lugar', ['lug_abreviatura' => 'asd', 'lug_nombre' => 'asd', 'lug_tipo' => 'pais', 'parent_lug_id' => $padre->lug_id]); $validator = Validator::make($lugar, $this->rules, $this->messages); $this->assertTrue($validator->passes(), 'Se esperaba que falle la validadicon.'); }
public function testUpdateForProduct() { $product = Factory::create('Giftertipster\\Entity\\Eloquent\\Product'); $keyword_profile = Factory::make('Giftertipster\\Entity\\Eloquent\\KeywordProfile'); $product->keywordProfile()->save($keyword_profile); $this->repo->updateForProduct(1, ['profile' => ['updated', 'profile']]); assertThat(KeywordProfile::find(1)->profile, identicalTo(['updated', 'profile'])); }
public function testInvalidLoginUsingWrongCredentials() { $user = Factory::create('User', array('password' => 'admin', 'active' => 1)); $inputs = array('username' => $user->username, 'password' => 'wrong password'); $crawler = $this->client->request('POST', route('auth.postLogin', $inputs)); $this->assertRedirectedToRoute('auth.getLogin'); $this->assertSessionHas('message', 'Wrong username or password'); }
public function testGetAdminAddTypes() { Factory::create('Giftertipster\\Entity\\Eloquent\\AddType', ['label' => 'foobar']); Factory::create('Giftertipster\\Entity\\Eloquent\\AddType', ['label' => 'admin-foobar']); $response = $this->repo->getAdminAddTypes(); assertThat($response[0], hasKeyValuePair('label', 'admin-foobar')); assertThat($response[0], hasKeyValuePair('id', 2)); }
public function testGetShowRendersApprovedSnippets() { $user = Factory::create('User'); $this->be($user); $snippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); $response = $this->call('GET', route('snippet.getShow', $snippet->slug)); $this->assertResponseOk(); $view = $response->original; $this->assertEquals($view['snippet']->title, $snippet->title); }
public function testGetMySnippetsRendersApprovedAndNotYetApprovedSnippets() { $user = Factory::create('User'); $this->be($user); $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null)); $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); $response = $this->call('GET', route('member.user.dashboard')); $view = $response->original; $this->assertEquals(count($view['my_snippets']), 2); }
public function test_validacion_exitosa() { Factory::create('App\\Lugar', ['lug_id' => 1]); Factory::create('App\\TipoTorneo', ['ttr_id' => 1]); Factory::create('App\\Equipo', ['eqp_id' => 1, 'lug_id' => 1]); Factory::create('App\\Jugador', ['jug_id' => 1, 'jug_nacionalidad' => 1]); Factory::create('App\\Torneo', ['tor_id' => 1, 'lug_id' => 1, 'ttr_id' => 1]); $plantillaTorneo = Factory::attributesFor('App\\PlantillaTorneo', ['plt_numero_camiseta' => 1, 'eqp_id' => 1, 'jug_id' => 1, 'tor_id' => 1]); $validator = Validator::make($plantillaTorneo, $this->rules, $this->messages); $this->assertTrue($validator->passes(), 'Se esperaba que la validadicon sea exitosa.'); }
public function testGetTrustedSitesByRealm() { $realm = 'https://*.test.com'; $service = $this->app[OpenIdServiceCatalog::TrustedSitesService]; $user = Factory::create('auth\\User'); $res = $service->addTrustedSite($user, $realm, IAuthService::AuthorizationResponse_AllowForever, $data = array('email', 'profile', 'address')); $this->assertTrue(!is_null($res)); $sites = $service->getTrustedSites($user, 'https://www.dev.test.com', $data = array('email', 'address')); $this->assertTrue(is_array($sites)); $this->assertTrue(count($sites) > 0); }
public function testGetShowOnlyRendersApprovedSnippets() { $user = Factory::create('User'); $this->be($user); $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null)); $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); $response = $this->call('GET', route('snippet.getIndex')); $view = $response->original; $this->assertEquals(count($view['snippets']), 1); $this->assertEquals($approvedSnippet->title, $view['snippets'][0]->title); }
public function testGetUnfulfilledRequestsReturnsFalseWhenAllRequestsAreFulfilled() { Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); Factory::create('Giftertipster\\Entity\\Eloquent\\Product'); Factory::create('Giftertipster\\Entity\\Eloquent\\Product'); $seed_request1 = Factory::create('Giftertipster\\Entity\\Eloquent\\ProductDeleteRequest', ['user_id' => 1, 'product_id' => 1, 'is_fulfilled' => 1, 'delete_type' => 'delete']); $seed_request2 = Factory::create('Giftertipster\\Entity\\Eloquent\\ProductDeleteRequest', ['user_id' => 1, 'product_id' => 2, 'is_fulfilled' => 1, 'delete_type' => 'delete']); $repo = $this->app->make('Giftertipster\\Repository\\ProductDeleteRequest\\EloquentProductDeleteRequestRepository'); $requests = $repo->getUnfulfilledRequests(); assertThat($requests, identicalTo(false)); }
public function testCreateFailsIfIdeaAlreadyExistsAndReturnsFalseWithErrors() { Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $idea_repo = $this->app->make('Giftertipster\\Repository\\Idea\\EloquentIdeaRepository'); $new_idea = 'blender'; $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]); $idea = $this->eloquent_idea->find(1); $response = $idea_repo->create(['user_id' => 1, 'description' => $new_idea, 'is_fulfilled' => 0]); $errors = $idea_repo->errors(); assertThat($response, identicalTo(false)); assertThat($errors->first(), equalTo('The description has already been taken.')); }
public function testGetSnippets() { $user = Factory::create('User', array('active' => 1)); $this->be($user); $notYetApprovedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 0, 'deleted_at' => null)); $approvedSnippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); $response = $this->call('GET', route('user.getSnippets', $user->slug)); $this->assertResponseOk(); $view = $response->original; # should be 1 because only 1 submitted snippet of $user is approved $this->assertEquals(1, count($view['snippets'])); $this->assertViewHas('user'); }
public function testSubProductForCartAddWorks() { $sub_product = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct', ['id' => 1, 'vendor_id' => 'asin stub', 'offer_listing_id' => 'offer listing id stub']); $image = Factory::make('Giftertipster\\Entity\\Eloquent\\Image', ['category' => 'variation']); $image2 = Factory::make('Giftertipster\\Entity\\Eloquent\\Image', ['category' => 'primary']); $sub_product->images()->save($image); $sub_product->images()->save($image2); $sub_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\SubProduct'); $sub_product_repo = $this->app->make('Giftertipster\\Repository\\SubProduct\\EloquentSubProductRepository'); $result_sub_product = $sub_product_repo->subProductDataForCartAdd(1); assertThat($result_sub_product, hasKeyValuePair('id', 1)); assertThat($result_sub_product, hasKey('images')); assertThat($result_sub_product['images'], not(emptyArray())); }
public function setUp() { parent::setUp(); Artisan::call('migrate'); Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); }
public function testGetSalesAgentIdsByEmailWhenNotInCache() { \Artisan::call('db:seed'); //stubs $expected_response = ['*****@*****.**' => 'sales_agent_id']; //user 1 is already seeded $user2 = Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => ['test']]); $user_profile1 = Factory::create('Jacopo\\Authentication\\Models\\UserProfile', ['user_id' => 1]); $profile_field = Factory::create('Jacopo\\Authentication\\Models\\ProfileField', ['user_profile_id' => 1, 'profile_field_type_id' => 1, 'value' => 'sales_agent_id']); $user3 = Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => ['test']]); //mocks $cache_mgr_mock = \Mockery::mock('Giftertipster\\Service\\Cache\\Users\\UsersCacheMgrInterface'); $cache_mgr_mock->shouldReceive('salesAgentIdsByEmail')->twice()->andReturn(\Mockery::self()); $cache_mgr_mock->shouldReceive('exists')->once()->andReturn(false); $cache_mgr_mock->shouldReceive('store')->once()->with($expected_response); $this->app->instance('Giftertipster\\Service\\Cache\\Users\\UsersCacheMgrInterface', $cache_mgr_mock); //actions $response = $this->repo()->getSalesAgentIdsByEmail(); //assertions assertThat($response, identicalTo($expected_response)); }
public function testIsInvalidWhenLabelAlreadyExists() { Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\GenderCategory', ['label' => 'foobar', 'priority' => 5]); $invalid_input = 'foobar'; $model = Factory::make('Giftertipster\\Entity\\Eloquent\\Category\\GenderCategory', ['label' => $invalid_input, 'priority' => 5]); $this->assertNotValid($model); }
public function testPostUpdateUpdatesSnippetOnValidInput() { $user = Factory::create('User'); $user->id = (string) $user->id; $this->be($user); $tag = Factory::create('Tag'); $secondTag = Factory::create('Tag'); $snippet = Factory::create('Snippet', array('author_id' => $user->id, 'approved' => 1, 'deleted_at' => null)); $input = array('title' => 'dummy title', 'body' => 'dummy body', 'resource' => Config::get('site.url'), 'tags' => array($tag->id, $secondTag->id)); $uri = route('member.snippet.postUpdate', $snippet->slug); $response = $this->call('POST', $uri, $input); $snippetFromDB = Snippet::where('slug', $snippet->slug)->first(); $this->assertEquals($input['title'], $snippetFromDB->title); $this->assertRedirectedToRoute('member.snippet.getShow', $snippet->slug); $this->assertSessionHas('message', 'Update successful'); }
public function testInvalidWithUsedEmail() { $item = Factory::create('Sorora\\Aurp\\Models\\' . $this->model, array('email' => '*****@*****.**')); $item = Factory::make('Sorora\\Aurp\\Models\\' . $this->model, array('email' => '*****@*****.**')); $this->assertNotValid($item); }
public function test_validacion_exitosa() { Factory::create('App\\Lugar'); $jugador = Factory::attributesFor('App\\Jugador', ['jug_id' => '', 'jug_apellido' => 'asp', 'jug_nombre' => 'asp', 'jug_apodo' => 'asp', 'jug_fecha_nacimiento' => '', 'jug_altura' => '', 'jug_sitioweb' => '', 'jug_twitter' => '', 'jug_foto' => '', 'jug_nacionalidad' => '1']); $validator = Validator::make($jugador, JugadorRequest::$rules, JugadorRequest::$messages); // var_dump($validator->errors()); $this->assertTrue($validator->passes(), 'Se esperaba que falle la validadicon.'); }
public function testIsValidWhenLabelAlreadyExistsButIsTiedToAnotherInterestId() { $model = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['label' => 'foobar', 'priority' => 5, 'interest_category_id' => 1]); assertThat($model->exists, identicalTo(true)); $invalid_input = 'foobar'; $model = Factory::make('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['label' => $invalid_input, 'priority' => 5, 'interest_category_id' => 2]); $this->assertValid($model); }
public function testIsInvalidWhenVendorVendorIdComboAlreadyExists() { Factory::create('Giftertipster\\Entity\\Eloquent\\Product'); Factory::create('Giftertipster\\Entity\\Eloquent\\ProductRequest', ['user_id' => 1, 'product_id' => 1, 'vendor' => 'amazon.com', 'vendor_id' => 'b1']); $model = Factory::make('Giftertipster\\Entity\\Eloquent\\ProductRequest', ['user_id' => 1, 'product_id' => 1, 'vendor' => 'amazon.com', 'vendor_id' => 'b1']); $this->assertNotValid($model); }
protected function createStubCategories() { $this->occasion = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\OccasionCategory', ['priority' => 5, 'keywords' => 'ofoobar']); $this->occasion2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\OccasionCategory', ['priority' => 5, 'keywords' => 'ofoobar2']); $this->relation = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\RelationCategory', ['priority' => 5, 'keywords' => 'rfoobar']); $this->gender = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\GenderCategory', ['priority' => 5, 'keywords' => 'gfoobar']); $this->age = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\AgeCategory', ['priority' => 5, 'keywords' => 'afoobar']); $this->interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\InterestCategory', ['priority' => 5, 'keywords' => 'ifoobar']); $this->sub_interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['priority' => 5, 'keywords' => 'sifoobar']); }
public function testIsInvalidWithoutUniqueDescription() { $idea = Factory::create('Giftertipster\\Entity\\Eloquent\\Idea', ['user_id' => 1, 'description' => 'foo']); $idea2 = Factory::make('Giftertipster\\Entity\\Eloquent\\Idea', ['user_id' => 1, 'description' => 'foo']); $this->assertNotValid($idea2); }
public function testQueueIndexReturnsTrueWhenHighPriorityQueueIsRequested() { $product_attributes = ['id' => 100, 'user_id' => 1, 'title' => 'foobartitle', 'binding' => 'foobar binding', 'brand' => 'foobar brand', 'manufacturer' => 'foobar manufacturer', 'model' => 'foobar model', 'group' => 'foobar group', 'size' => 'foobar size', 'clothing_size' => 'foobar clothing_size', 'min_price_amount' => 10, 'max_price_amount' => 20]; $product_model = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', $product_attributes); $suite_attributes = ['id' => 100, 'user_id' => $product_model->user_id, 'is_refreshed' => 1, 'title' => $product_model->title, 'binding' => $product_model->binding, 'brand' => $product_model->brand, 'manufacturer' => $product_model->manufacturer, 'model' => $product_model->model, 'group' => $product_model->group, 'size' => $product_model->size, 'clothing_size' => $product_model->clothing_size, 'min_price' => $product_model->min_price_amount, 'max_price' => $product_model->max_price_amount, 'features' => [['description' => 'foobar feature 1'], ['description' => 'foobar feature 2']], 'descriptions' => [['value' => 'foobar description 1'], ['value' => 'foobar description 2']], 'sub_products' => [['id' => 'fake sub product', 'features' => [['description' => 'sub product foobar feature 1'], ['description' => 'sub product foobar feature 2']], 'descriptions' => [['value' => 'sub product foobar description 1'], ['value' => 'sub product foobar description 2']]], ['id' => 'fake sub product2', 'features' => [['description' => 'sub product foobar feature 3'], ['description' => 'sub product foobar feature 4']], 'descriptions' => [['value' => 'sub product foobar description 3'], ['value' => 'sub product foobar description 4']]]], 'keyword_profile' => ['profile' => ['keyword1', 'keyword2']], 'category_keywords' => ['category', 'keywords']]; $expected_params_for_product_index_repo = ['fields' => ['_id' => 100, 'user_id' => 1, 'datetime' => $product_model->updated_at->toDateTimeString(), 'title' => $product_model->title, 'descriptions' => ['foobar description 1', 'foobar description 2', 'sub product foobar description 1', 'sub product foobar description 2', 'sub product foobar description 3', 'sub product foobar description 4'], 'features' => ['foobar feature 1', 'foobar feature 2', 'sub product foobar feature 1', 'sub product foobar feature 2', 'sub product foobar feature 3', 'sub product foobar feature 4'], 'binding' => $product_model->binding, 'brand' => $product_model->brand, 'manufacturer' => $product_model->manufacturer, 'model' => $product_model->model, 'group' => $product_model->group, 'size' => $product_model->size, 'clothing_size' => $product_model->clothing_size, 'min_price' => $product_model->min_price_amount, 'max_price' => $product_model->max_price_amount, 'keyword_profile' => ['keyword1', 'keyword2'], 'category_keywords' => ['category', 'keywords'], 'soft_delete_status' => false]]; \Queue::shouldReceive('push')->with('Giftertipster\\Service\\JobHandler\\IndexProduct\\IndexProductInterface', $expected_params_for_product_index_repo, 'high')->once()->andReturn(true); $indexer_service = $this->app->make('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexer'); $product_suite = $suite_attributes; $product_suite = array_merge($product_model->toArray(), $product_suite); $response = $indexer_service->queueIndex($product_suite, true); }
function testKeywordsArrayWhenEmpty() { $model = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\AgeCategory', ['priority' => 1, 'keywords' => ' ?']); assertThat($model->keywordsArray(), identicalTo([])); }
public function testGetRefreshedIdRange() { $seed_product = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', ['group' => 'bar1', 'is_refreshed' => 0]); $seed_product2 = Factory::create('Giftertipster\\Entity\\Eloquent\\Product', ['group' => 'bar2', 'is_refreshed' => 1]); $product = $this->app->make('Giftertipster\\Repository\\Product\\EloquentProductRepository'); $products = $product->getRefreshedIdRange(1, null, 2); assertThat($products[0], hasKeyValuePair('id', 2)); }
public function testGetCategorySelections() { $this->createStubCategories(); //make another interest and sub interest for this test $interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\InterestCategory', ['priority' => 5]); $sub_interest = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['priority' => 5, 'interest_category_id' => 2]); $this->repo = $this->app->make('Giftertipster\\Repository\\Categories\\EloquentCategoriesRepository'); $result = $this->repo->getCategorySelections($this->repo->getCategories(true)); assertThat($result, hasKey('Occasion')); assertThat($result['Occasion'], hasKey('occasion.1')); assertThat($result['Occasion'], hasKey('occasion.2')); assertThat($result['Occasion'], hasKey('occasion.3')); assertThat($result, hasKey('Relation')); assertThat($result['Relation'], hasKey('relation.1')); assertThat($result, hasKey('Age')); assertThat($result['Age'], hasKey('age.1')); assertThat($result, hasKey('Gender')); assertThat($result['Gender'], hasKey('gender.1')); assertThat($result, hasKey('Interest')); assertThat($result['Interest'], hasKey('interest.1')); assertThat($result['Interest'], hasKey('interest.2')); assertThat($result, hasKey('Sub Interest')); assertThat($result['Sub Interest'], hasKey('sub_interest.1')); assertThat($result['Sub Interest'], hasKey('sub_interest.2')); }
public function testIsInvalidWithoutUniqueEmail() { Factory::create('author', ['name' => 'Joy', 'email' => '*****@*****.**']); $author = Factory::author(['name' => 'Frank', 'email' => '*****@*****.**']); $this->assertNotValid($author); }