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 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);
 }
Example #4
0
 public function testEdit()
 {
     $this->mock->shouldReceive('with')->with('role')->andReturn($this->mock);
     $this->mock->shouldReceive('findOrFail')->with(3)->once()->andReturn(Factory::make($this->factory, array('id' => 3)));
     $this->get($this->url . '/3/edit', 3);
     $this->assertViewHas(substr($this->var, 0, -1));
 }
 public function test_validacion_exitosa_con_formato_de_url()
 {
     $clienteFake = factory(App\Cliente::class)->make();
     $cliente = Factory::attributesFor('App\\Cliente', ['clt_nombre' => $clienteFake->clt_nombre, 'clt_descripcion' => '', 'clt_dominio' => $clienteFake->clt_dominio]);
     $validator = Validator::make($cliente, ClienteRequest::$rules, ClienteRequest::$messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que la validacion de url sea exitosa.');
 }
 public function test_validacion_exitosa()
 {
     $equipo = factory(App\Equipo::class)->create();
     $fase = factory(App\Fase::class)->create();
     $penalizacion = Factory::attributesFor('App\\PenalizacionTorneo', ['eqp_id' => $equipo->eqp_id, 'fas_id' => $fase->fas_id, 'ptr_puntos' => 1, 'ptr_motivo' => 'asd']);
     $validator = Validator::make($penalizacion, $this->rules, $this->messages);
     $this->assertTrue($validator->passes(), 'Se esperaba que la validadicon sea exitosa.');
 }
 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 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 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 testFillableAndGuardedAttributes()
 {
     $product = Factory::make('Giftertipster\\Entity\\Eloquent\\RangeCronJob');
     assertThat($product['guarded'], hasItemInArray('id'));
     assertThat($product['guarded'], hasItemInArray('created_at'));
     assertThat($product['guarded'], hasItemInArray('updated_at'));
     assertThat($product['fillable'], hasItemInArray('job_name'));
     assertThat($product['fillable'], hasItemInArray('last_id_processed'));
     assertThat($product['fillable'], hasItemInArray('last_status'));
 }
 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);
 }
Example #13
0
 public function testUsesRoleReturnsPermissionsArray()
 {
     $mock = Mockery::mock('Sorora\\Aurp\\Models\\Role');
     $mock->shouldReceive('load')->with('permissions')->once();
     $permissions = array(Factory::make('Sorora\\Aurp\\Models\\' . $this->model, array('id' => 1, 'task' => 'Foo')), Factory::make('Sorora\\Aurp\\Models\\' . $this->model, array('id' => 5, 'task' => 'Bar')));
     $mock->shouldReceive('getAttribute')->once()->andReturn((object) $permissions);
     $item = new Permission();
     $permissions = $item->usesRole($mock);
     $this->assertEquals($permissions, array(1 => 'Foo', 5 => 'Bar'));
 }
 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 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 test_validacion_falla_por_campos_demasiado_cortos()
 {
     $tipoFase = Factory::attributesFor('App\\TipoFase', ['tfa_nombre' => 'as', 'tfa_descripcion' => 'as']);
     $validator = Validator::make($tipoFase, $this->rules, $this->messages);
     $this->assertFalse($validator->passes(), 'Se esperaba que falle la validadicon.');
     $this->assertTrue($validator->errors()->has('tfa_nombre'), 'Se esperaba que exista la clave tfa_nombre');
     $this->assertCount(1, $validator->errors()->get('tfa_nombre'), 'Se esperaba que exista 1 error en la clave tfa_nombre');
     $this->assertTrue($validator->errors()->has('tfa_descripcion'), 'Se esperaba que exista la clave tfa_descripcion');
     $this->assertCount(1, $validator->errors()->get('tfa_descripcion'), 'Se esperaba que exista 1 error en la clave tfa_descripcion');
     $this->assertCount(2, $validator->errors()->all(), 'Se esperaban 2 errores de validacion');
 }
 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 test_validacion_exitoso_con_formato_sitio_web_http_abc_dot_com()
 {
     $auspiciante = Factory::attributesFor('App\\Auspiciante', ['aus_nombre' => 'asd', 'aus_sitioweb' => 'http://asd.com', 'aus_imagen' => '']);
     $validator = Validator::make($auspiciante, AuspicianteRequest::$rules, AuspicianteRequest::$messages);
     $this->assertCount(1, $validator->errors()->all(), 'Se esperaban 1 error de validacion');
 }
Example #23
0
 public function setUp()
 {
     parent::setUp();
     $this->attributes = Factory::group(['id' => 1]);
     $this->app->instance('Group', $this->mock);
 }
Example #24
0
 public function setUp()
 {
     parent::setUp();
     $this->attributes = Factory::todo(['id' => 1]);
     $this->app->instance('Todo', $this->mock);
 }
 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.');
 }
 function testKeywordsArrayWhenEmpty()
 {
     $model = Factory::create('Giftertipster\\Entity\\Eloquent\\Category\\AgeCategory', ['priority' => 1, 'keywords' => ' ?']);
     assertThat($model->keywordsArray(), identicalTo([]));
 }
Example #27
0
 public function setUp()
 {
     parent::setUp();
     $this->attributes = Factory::image(['id' => 1]);
     $this->app->instance('Image', $this->mock);
 }
Example #28
0
 public function testValidWithAllFields()
 {
     $item = Factory::make('Sorora\\Aurp\\Models\\' . $this->model);
     $this->assertValid($item);
 }
 public function testIsInvalidWhenIconNameIsMoreThan100Chars()
 {
     Factory::make('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['label' => 'foobar']);
     $invalid_input = str_pad('a', 101);
     $model = Factory::make('Giftertipster\\Entity\\Eloquent\\Category\\SubInterestCategory', ['icon_name' => $invalid_input, 'priority' => 5]);
     $this->assertNotValid($model);
 }
 public function testIsInvalidWhenUseridDoesntExistInUsersTable()
 {
     $model = Factory::make('Giftertipster\\Entity\\Eloquent\\Analytic\\UserAnalytic', ['user_id' => 2]);
     $this->assertNotValid($model);
 }