File manager - Edit - /var/www/html/homologBancodetalentos/tests/Feature/TalentBank/VagasWebFlowTest.php
Back
<?php namespace Tests\Feature\TalentBank; use App\Models\TalentBank\Candidate; use App\Models\TalentBank\Company; use App\Models\TalentBank\ContractType; use App\Models\TalentBank\Ethnicity; use App\Models\TalentBank\ExpertiseLevel; use App\Models\TalentBank\Gender; use App\Models\TalentBank\JobListing; use App\Models\TalentBank\Modality; use App\Models\TalentBank\Neighbourhood; use App\Models\TalentBank\Occupation; use App\Models\TalentBank\SalaryRange; use App\Models\TalentBank\Workload; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; use Tests\TestCase; class VagasWebFlowTest extends TestCase { use DatabaseTransactions; protected function setUp(): void { parent::setUp(); config([ 'talent_bank.bypass_auth' => true, ]); } public function test_vagas_index_renders_with_job_data(): void { $this->createJobFixture(); $response = $this->get('/vagas'); $response->assertOk(); $response->assertViewIs('pages.vagas'); $response->assertViewHas('jobs'); $response->assertViewHas('filterOptions'); } public function test_vagas_show_renders(): void { $job = $this->createJobFixture(); $response = $this->get(route('vagas.show', $job)); $response->assertOk(); $response->assertViewIs('pages.detalhes-vagas'); $response->assertViewHas('job'); $response->assertViewHas('applied', false); } public function test_candidate_can_apply_and_withdraw_on_web_routes(): void { Mail::fake(); $cpf = $this->generateValidCpf(); config(['talent_bank.bypass_document' => $cpf]); $this->createCandidateWithCpf($cpf); $job = $this->createJobFixture(); $apply = $this->post(route('vagas.apply', $job)); $apply->assertRedirect(route('vagas.show', $job)); $this->assertSame(1, (int) DB::table('job_listing_candidate')->where('job_listing_id', $job->id)->count()); $withdraw = $this->delete(route('vagas.withdraw', $job)); $withdraw->assertRedirect(route('vagas.show', $job)); $this->assertSame(0, (int) DB::table('job_listing_candidate')->where('job_listing_id', $job->id)->count()); } private function createCandidateWithCpf(string $cpf): Candidate { $neighbourhood = Neighbourhood::query()->create([ 'name' => 'Centro Vagas Web '.uniqid(), ]); $occupation = Occupation::query()->create([ 'name' => 'Analista Vagas Web '.uniqid(), ]); $gender = Gender::query()->create([ 'name' => 'Outro', ]); $ethnicity = Ethnicity::query()->create([ 'name' => 'Branco', ]); return Candidate::query()->create([ 'cpf' => $cpf, 'name' => 'Candidato Vagas Web', 'email' => 'vagas.web+'.uniqid().'@example.com', 'neighbourhood_id' => $neighbourhood->id, 'occupation_id' => $occupation->id, 'gender_id' => $gender->id, 'ethnicity_id' => $ethnicity->id, 'active' => true, ]); } private function createJobFixture(): JobListing { $company = Company::query()->create([ 'cnpj' => $this->generateValidCnpj(), 'corporate_name' => 'Empresa Vagas Web LTDA', 'trading_name' => 'Empresa Vagas Web', 'email' => 'empresa.vagas.web+'.uniqid().'@example.com', 'neighbourhood_id' => Neighbourhood::query()->create(['name' => 'Bairro Co '.uniqid()])->id, 'active' => true, ]); $occupation = Occupation::query()->create(['name' => 'Ocupacao Web '.uniqid()]); $salaryRange = SalaryRange::query()->create(['name' => 'A combinar Web '.uniqid()]); $contractType = ContractType::query()->create(['name' => 'CLT Web '.uniqid()]); $neighbourhood = Neighbourhood::query()->create(['name' => 'Bairro Vaga Web '.uniqid()]); $expertiseLevel = ExpertiseLevel::query()->create(['name' => 'Pleno Web '.uniqid()]); $modality = Modality::query()->create(['name' => 'Presencial Web '.uniqid()]); $workload = Workload::query()->create(['name' => '40h Web '.uniqid()]); return JobListing::query()->create([ 'company_id' => $company->id, 'occupation_id' => $occupation->id, 'salary_range_id' => $salaryRange->id, 'contract_type_id' => $contractType->id, 'neighbourhood_id' => $neighbourhood->id, 'expertise_level_id' => $expertiseLevel->id, 'modality_id' => $modality->id, 'workload_id' => $workload->id, 'spots_total' => 3, 'spots_filled' => 0, 'description' => 'Descricao vaga web flow test', 'requirements_mandatory' => 'Requisitos obrigatorios', 'requirements_optional' => null, 'benefits' => 'Beneficios', 'misc_info' => null, 'hide_company' => false, 'is_hiring' => true, ]); } private function generateValidCpf(): string { $digits = []; for ($i = 0; $i < 9; $i++) { $digits[$i] = random_int(0, 9); } for ($t = 9; $t < 11; $t++) { $sum = 0; for ($c = 0; $c < $t; $c++) { $sum += $digits[$c] * (($t + 1) - $c); } $digits[$t] = ((10 * $sum) % 11) % 10; } return implode('', $digits); } private function generateValidCnpj(): string { $base = []; for ($i = 0; $i < 12; $i++) { $base[$i] = random_int(0, 9); } $weights1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; $sum1 = 0; for ($i = 0; $i < 12; $i++) { $sum1 += $base[$i] * $weights1[$i]; } $rest1 = $sum1 % 11; $digit1 = $rest1 < 2 ? 0 : 11 - $rest1; $base[] = $digit1; $weights2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; $sum2 = 0; for ($i = 0; $i < 13; $i++) { $sum2 += $base[$i] * $weights2[$i]; } $rest2 = $sum2 % 11; $digit2 = $rest2 < 2 ? 0 : 11 - $rest2; $base[] = $digit2; return implode('', $base); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings