Best Atoum code snippet using data.testGetData
JobControllerTest.php
Source:JobControllerTest.php
...182 $this->assertNotEmpty($job);183 }184 // Edit Job Test185 public function testEditJobError() {186 $testGetData = [187 'id' => 11188 ];189 $testPostData = [190 'job' => [191 'id' => '11',192 'title' => '',193 'description' => 'This is a job opening for an experienced Sous Chef for a company based in Northampton.',194 'locationId' => '850',195 'salary' => '£4000',196 'categoryId' => '3',197 'closingDate' => '2020-06-20',198 'userId' => 1199 ],200 'submit' => true201 ];202 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, []);203 $job = $jobController->editJobSubmit();204 $this->assertCount(1, $job['variables']['errors']);205 }206 public function testEditJob() {207 $testGetData = [208 'id' => 11209 ];210 $testPostData = [211 'job' => [212 'id' => '11',213 'title' => 'Sous Chef',214 'description' => 'This is a job opening for an experienced Sous Chef for a company based in Northampton.',215 'locationId' => '850',216 'salary' => '£4000',217 'categoryId' => '3',218 'closingDate' => '2020-06-20',219 'userId' => 1220 ],221 'submit' => true222 ];223 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, []);224 $jobController->editJobSubmit();225 $job = $this->pdo->query('SELECT id, description FROM job WHERE id = 11')->fetch();226 $this->assertEquals($job['description'], 'This is a job opening for an experienced Sous Chef for a company based in Northampton.');227 }228 // Apply To Job Tests229 public function testApplyNoDetails() {230 $testGetData = [231 'id' => 11232 ];233 $testPostData = [234 'apply' => [235 'name' => '',236 'email' => '',237 'details' => '',238 'jobId' => 11239 ],240 'submit' => true241 ];242 $testFilesData = [243 'cv' => [244 'error' => 4245 ]246 ];247 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);248 $application = $jobController->applySubmit();249 $this->assertCount(4, $application['variables']['errors']);250 }251 public function testApplyOnlyName() {252 $testGetData = [253 'id' => 11254 ];255 $testPostData = [256 'apply' => [257 'name' => 'Jim Bob',258 'email' => '',259 'details' => '',260 'jobId' => 11261 ],262 'submit' => true263 ];264 $testFilesData = [265 'cv' => [266 'name' => '',267 'tmp_name' => '',268 'error' => 4269 ]270 ];271 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);272 $application = $jobController->applySubmit();273 $this->assertCount(3, $application['variables']['errors']);274 }275 public function testApplyOnlyEmail() {276 $testGetData = [277 'id' => 11278 ];279 $testPostData = [280 'apply' => [281 'name' => '',282 'email' => 'jim@bob.com',283 'details' => '',284 'jobId' => 11285 ],286 'submit' => true287 ];288 $testFilesData = [289 'cv' => [290 'name' => '',291 'tmp_name' => '',292 'error' => 4293 ]294 ];295 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);296 $application = $jobController->applySubmit();297 $this->assertCount(3, $application['variables']['errors']);298 }299 public function testApplyOnlyCoverLetter() {300 $testGetData = [301 'id' => 11302 ];303 $testPostData = [304 'apply' => [305 'name' => '',306 'email' => '',307 'details' => 'This is my cover letter!',308 'jobId' => 11309 ],310 'submit' => true311 ];312 $testFilesData = [313 'cv' => [314 'name' => '',315 'tmp_name' => '',316 'error' => 4317 ]318 ];319 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);320 $application = $jobController->applySubmit();321 $this->assertCount(3, $application['variables']['errors']);322 }323 public function testApplyOnlyCV() {324 $testGetData = [325 'id' => 11326 ];327 $testPostData = [328 'apply' => [329 'name' => '',330 'email' => '',331 'details' => '',332 'jobId' => 11333 ],334 'submit' => true335 ];336 $testFilesData = [337 'cv' => [338 'name' => 'cv.php',339 'tmp_name' => 'cv128.php',340 'error' => 2341 ]342 ];343 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);344 $application = $jobController->applySubmit();345 $this->assertCount(3, $application['variables']['errors']);346 }347 public function testApplyOnlyCVError() {348 $testGetData = [349 'id' => 11350 ];351 $testPostData = [352 'apply' => [353 'name' => '',354 'email' => '',355 'details' => '',356 'jobId' => 11357 ],358 'submit' => true359 ];360 $testFilesData = [361 'cv' => [362 'name' => 'cv.php',363 'tmp_name' => 'cv128.php',364 'error' => 1365 ]366 ];367 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);368 $application = $jobController->applySubmit();369 $this->assertCount(4, $application['variables']['errors']);370 }371 public function testApplyAllDetails() {372 $testGetData = [373 'id' => 11374 ];375 $testPostData = [376 'apply' => [377 'name' => 'Jim Bob',378 'email' => 'jim@bob.com',379 'details' => 'This is my cover letter!',380 'jobId' => 11381 ],382 'submit' => true383 ];384 $testFilesData = [385 'cv' => [386 'name' => 'cv.php',387 'tmp_name' => 'cv128.php',388 'error' => 2389 ]390 ];391 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, $testPostData, $testFilesData);392 $jobController->applySubmit();393 $application = $this->pdo->query('SELECT name FROM applicants WHERE name = "Jim Bob" AND jobId = 11;')->fetch();394 $this->assertEquals($application['name'], 'Jim Bob');395 }396 /* List Jobs Tests */397 // List Jobs 398 public function testListJobsWithoutCategoryFilter() {399 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);400 $jobs = $jobController->listJobs([$this->categoriesTable->retrieveAllRecords()]);401 $this->assertNotEmpty($jobs['variables']['categories']);402 }403 public function testListJobsWithInvalidCategory() {404 $testGetData = [405 'category' => 'Plumbing'406 ];407 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);408 $jobs = $jobController->listJobs([]);409 $this->assertFalse(isset($jobs['variables']['categoryName']));410 }411 public function testListJobsWithValidCategory() {412 $testGetData = [413 'category' => 'Sales'414 ];415 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);416 $jobs = $jobController->listJobs([]);417 $this->assertNotEmpty($jobs['variables']['categoryName']);418 }419 public function testListJobsWithCategoryFilterAndNoLocation() {420 $testGetData = [421 'category' => 'Sales',422 'location' => ''423 ];424 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);425 $jobs = $jobController->listJobs([]);426 $this->assertNotEmpty($jobs['variables']['categoryName']);427 }428 public function testListJobsWithCategoryFilterAndLocation() {429 $testGetData = [430 'category' => 'Sales',431 'location' => 'Northampton'432 ];433 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);434 $jobs = $jobController->listJobs([]);435 $this->assertNotEmpty($jobs['variables']['categoryName']);436 }437 public function testListJobsWithCategoryFilterAndAllLocations() {438 $testGetData = [439 'category' => 'Sales',440 'location' => 'All'441 ];442 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);443 $jobs = $jobController->listJobs([]);444 $this->assertNotEmpty($jobs['variables']['categoryName']);445 }446 447 // Admin List Jobs448 public function testAdminListJobsWithoutParams() {449 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);450 $jobs = @$jobController->listJobsAdmin([]);451 $this->assertEmpty($jobs['variables']);452 } 453 public function testAdminListActiveJobsWithoutCategoryFilter() {454 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);455 $_SESSION['id'] = 1;456 $jobs = @$jobController->listJobsAdmin(['active']);457 $this->assertEquals($jobs['variables']['title'], 'Jobs');458 unset($_SESSION['id']);459 } 460 public function testAdminListJobsAsOwnerWithoutCategoryFilter() {461 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);462 $_SESSION['isOwner'] = true;463 $jobs = @$jobController->listJobsAdmin(['active']);464 $this->assertEquals($jobs['variables']['title'], 'Jobs');465 unset($_SESSION['isOwner']);466 } 467 public function testAdminListArchivedJobsWithoutCategoryFilter() {468 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);469 $_SESSION['id'] = 1;470 $jobs = @$jobController->listJobsAdmin(['archived']);471 $this->assertEquals($jobs['variables']['title'], 'Archived Jobs');472 unset($_SESSION['id']);473 } 474 public function testAdminListActiveJobsWithInvalidCategoryFilter() {475 $testGetData = [476 'category' => 'Cooking'477 ];478 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);479 $jobs = @$jobController->listJobsAdmin(['active']);480 $this->assertEquals($jobs['variables']['title'], 'Jobs');481 } 482 public function testAdminListArchivedJobsWithInvalidCategoryFilter() {483 $testGetData = [484 'category' => 'Cooking'485 ];486 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);487 $jobs = @$jobController->listJobsAdmin(['archived']);488 $this->assertEquals($jobs['variables']['title'], 'Archived Jobs');489 } 490 public function testAdminListActiveJobsWithCategoryFilter() {491 $testGetData = [492 'category' => 'Sales'493 ];494 $_SESSION['id'] = 1;495 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);496 $jobs = @$jobController->listJobsAdmin(['active']);497 $this->assertEquals($jobs['variables']['title'], 'Jobs');498 unset($_SESSION['id']);499 } 500 public function testAdminListArchivedJobsWithCategoryFilter() {501 $testGetData = [502 'category' => 'Sales'503 ];504 $_SESSION['id'] = 1;505 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);506 $jobs = @$jobController->listJobsAdmin(['archived']);507 $this->assertEquals($jobs['variables']['title'], 'Archived Jobs');508 unset($_SESSION['id']);509 } 510 511 public function testAdminListActiveJobsWithCategoryFilterAsOwner() {512 $testGetData = [513 'category' => 'Sales'514 ];515 $_SESSION['isOwner'] = true;516 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);517 $jobs = @$jobController->listJobsAdmin(['active']);518 $this->assertEquals($jobs['variables']['title'], 'Jobs');519 unset($_SESSION['isOwner']);520 } 521 // Delete Job Test522 public function testDeleteJob () {523 $testPostData = [524 'id' => 11525 ];526 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], $testPostData, []);527 @$jobController->deleteJob();528 $job = $this->pdo->query('SELECT id FROM job WHERE id = 11;')->fetch();529 $application = $this->pdo->query('SELECT jobId FROM applicants WHERE jobId = 4;')->fetch();530 $this->assertTrue(empty($job) && empty($application));531 $this->pdo->query('ALTER TABLE job AUTO_INCREMENT = 11;');532 $this->pdo->query('ALTER TABLE applicants AUTO_INCREMENT = 3;');533 }534 // Show Job Test535 public function testShowJobInvalid() {536 $testGetData = [537 'id' => 99538 ];539 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);540 $job = @$jobController->showJob();541 $this->assertEmpty($job['variables']['job']);542 }543 public function testShowJobValid() {544 $testGetData = [545 'id' => 1546 ];547 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);548 $job = @$jobController->showJob();549 $this->assertNotEmpty($job['variables']['job']);550 }551 // List Applicants Tests552 public function testListApplicantsNonExistantJob() {553 $testGetData = [554 'id' => 99555 ];556 $_SESSION['isOwner'] = true;557 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);558 $job = @$jobController->listApplicants();559 $this->assertEmpty($job['variables']);560 unset($_SESSION['isOwner']);561 }562 public function testListApplicants() {563 $testGetData = [564 'id' => 1565 ];566 $_SESSION['id'] = 1;567 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);568 $job = @$jobController->listApplicants();569 $this->assertNotEmpty($job['variables']);570 unset($_SESSION['id']);571 }572 /* Form Tests */573 // Apply Form Tests574 public function testShowApplyFormWithoutId() {575 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);576 $form = @$jobController->applyForm();577 $this->assertEmpty($form['variables']['title']);578 }579 public function testShowApplyFormWithInvalidId() {580 $testGetData = [581 'id' => 99582 ];583 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);584 $form = $jobController->applyForm();585 $this->assertEmpty($form['variables']);586 }587 public function testShowApplyFormWithInactiveJob() {588 $testGetData = [589 'id' => 4590 ];591 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);592 $form = $jobController->applyForm();593 $this->assertEmpty($form['variables']);594 }595 public function testShowApplyFormWithValidId() {596 $testGetData = [597 'id' => 1598 ];599 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);600 $form = $jobController->applyForm();601 $this->assertEquals($form['variables']['title'], 'First level tech support');602 }603 // Edit Job Form Tests604 public function testShowEditJobFormWithoutId() {605 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, [], [], []);606 $form = @$jobController->editJobForm();607 $this->assertFalse(isset($form['variables']['job']));608 }609 public function testShowEditJobFormWithIdAsClient() {610 $testGetData = [611 'id' => 1612 ];613 $_SESSION['isClient'] = true;614 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);615 $form = @$jobController->editJobForm();616 $this->assertFalse(isset($form['variables']['job']));617 unset($_SESSION['isClient']);618 }619 public function testShowEditJobFormWithIdAsOwner() {620 $testGetData = [621 'id' => 1622 ];623 $_SESSION['isOwner'] = true;624 $jobController = new \JobSite\Controllers\JobController($this->jobsTable, $this->applicantsTable, $this->locationsTable, $this->categoriesTable, $testGetData, [], []);625 $form = @$jobController->editJobForm();626 $this->assertTrue(isset($form['variables']['job']));627 unset($_SESSION['isOwner']);628 }629}630?>...
ApplyJobTest.php
Source:ApplyJobTest.php
...24 * @runInSeparateProcess25 */26 public function testValid()27 {28 $testGetData = [29 'id' => 130 ];31 $testPostData = [32 'application' => [33 'name' => 'John Smith',34 'email' => 'john.smith@example.org',35 'details' => '',36 'job_id' => 137 ]38 ];39 $constructorArgs = [40 [41 'cv' => [42 'name' => 'my-resume.pdf',43 'type' => 'application/pdf',44 'tmp_name' => '/tmp/phpIbsIbf',45 'error' => 0,46 'size' => 2500047 ]48 ],49 'cv',50 [51 'uploadsDir' => '/uploads/cvs/',52 'namePrefix' => 'cv_',53 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],54 'maxFileSizeMB' => 0.555 ]56 ];57 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')58 ->setConstructorArgs($constructorArgs)59 ->setMethods(['upload', 'checkFile', 'getNewFileName'])60 ->getMock();61 $fileUpload->expects($this->any())62 ->method('upload')63 ->will($this->returnValue(true));64 $fileUpload->expects($this->once())65 ->method('checkFile')66 ->will($this->returnValue([]));67 $jobController = new \JosJobs\Controllers\Job(68 $this->authentication,69 $this->applicationsTable,70 $this->categoriesTable,71 $this->jobsTable,72 $this->locationsTable,73 $this->usersTable,74 $testGetData,75 $testPostData,76 $fileUpload77 );78 $this->assertEquals($jobController->saveApply(), 302);79 }80 /**81 * Given invalid data, a job is not created and the82 * user is shown the form again with errors.83 */84 public function testNullName()85 {86 $testGetData = [87 'id' => 188 ];89 $testPostData = [90 'application' => [91 'name' => '',92 'email' => 'john.smith@example.org',93 'details' => '',94 'job_id' => 195 ]96 ];97 $constructorArgs = [98 [99 'cv' => [100 'name' => 'my-resume.pdf',101 'type' => 'application/pdf',102 'tmp_name' => '/tmp/phpIbsIbf',103 'error' => 0,104 'size' => 25000105 ]106 ],107 'cv',108 [109 'uploadsDir' => '/uploads/cvs/',110 'namePrefix' => 'cv_',111 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],112 'maxFileSizeMB' => 0.5113 ]114 ];115 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')116 ->setConstructorArgs($constructorArgs)117 ->setMethods(['upload', 'checkFile', 'getNewFileName'])118 ->getMock();119 $fileUpload->expects($this->any())120 ->method('upload')121 ->will($this->returnValue(true));122 $fileUpload->expects($this->once())123 ->method('checkFile')124 ->will($this->returnValue([]));125 $jobController = new \JosJobs\Controllers\Job(126 $this->authentication,127 $this->applicationsTable,128 $this->categoriesTable,129 $this->jobsTable,130 $this->locationsTable,131 $this->usersTable,132 $testGetData,133 $testPostData,134 $fileUpload135 );136 $this->assertEquals(137 $jobController->saveApply()['template'],138 '/jobs/apply.html.php'139 );140 }141 /**142 * Given invalid data, a job is not created and the143 * user is shown the form again with errors.144 */145 public function testNullEmail()146 {147 $testGetData = [148 'id' => 1149 ];150 $testPostData = [151 'application' => [152 'name' => 'John Smith',153 'email' => '',154 'details' => '',155 'job_id' => 1156 ]157 ];158 $constructorArgs = [159 [160 'cv' => [161 'name' => 'my-resume.pdf',162 'type' => 'application/pdf',163 'tmp_name' => '/tmp/phpIbsIbf',164 'error' => 0,165 'size' => 25000166 ]167 ],168 'cv',169 [170 'uploadsDir' => '/uploads/cvs/',171 'namePrefix' => 'cv_',172 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],173 'maxFileSizeMB' => 0.5174 ]175 ];176 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')177 ->setConstructorArgs($constructorArgs)178 ->setMethods(['upload', 'checkFile', 'getNewFileName'])179 ->getMock();180 $fileUpload->expects($this->any())181 ->method('upload')182 ->will($this->returnValue(true));183 $fileUpload->expects($this->once())184 ->method('checkFile')185 ->will($this->returnValue([]));186 $jobController = new \JosJobs\Controllers\Job(187 $this->authentication,188 $this->applicationsTable,189 $this->categoriesTable,190 $this->jobsTable,191 $this->locationsTable,192 $this->usersTable,193 $testGetData,194 $testPostData,195 $fileUpload196 );197 $this->assertEquals(198 $jobController->saveApply()['template'],199 '/jobs/apply.html.php'200 );201 }202 /**203 * Given invalid data, a job is not created and the204 * user is shown the form again with errors.205 */206 public function testNullAll()207 {208 $testGetData = [209 'id' => 1210 ];211 $testPostData = [212 'application' => [213 'name' => '',214 'email' => '',215 'details' => '',216 'job_id' => null217 ]218 ];219 $constructorArgs = [220 [221 'cv' => [222 'name' => 'my-resume.pdf',223 'type' => 'application/pdf',224 'tmp_name' => '/tmp/phpIbsIbf',225 'error' => 0,226 'size' => 25000227 ]228 ],229 'cv',230 [231 'uploadsDir' => '/uploads/cvs/',232 'namePrefix' => 'cv_',233 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],234 'maxFileSizeMB' => 0.5235 ]236 ];237 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')238 ->setConstructorArgs($constructorArgs)239 ->setMethods(['upload', 'checkFile', 'getNewFileName'])240 ->getMock();241 $fileUpload->expects($this->any())242 ->method('upload')243 ->will($this->returnValue(true));244 $fileUpload->expects($this->once())245 ->method('checkFile')246 ->will($this->returnValue([]));247 $jobController = new \JosJobs\Controllers\Job(248 $this->authentication,249 $this->applicationsTable,250 $this->categoriesTable,251 $this->jobsTable,252 $this->locationsTable,253 $this->usersTable,254 $testGetData,255 $testPostData,256 $fileUpload257 );258 $this->assertEquals(259 $jobController->saveApply()['template'],260 '/jobs/apply.html.php'261 );262 }263 /**264 * Given invalid data, a job is not created and the265 * user is shown the form again with errors.266 */267 public function testNameExceedsLength()268 {269 $testGetData = [270 'id' => 1271 ];272 $testPostData = [273 'application' => [274 'name' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia sequi, ex deleniti officia pariatur adipisci quisquam reprehenderit delectus excepturi libero totam eligendi iusto nam nobis molestiae. Modi et eius id, sapiente doloremque delectus dolore beatae.',275 'email' => 'john.smith@example.org',276 'details' => '',277 'job_id' => null278 ]279 ];280 $constructorArgs = [281 [282 'cv' => [283 'name' => 'my-resume.pdf',284 'type' => 'application/pdf',285 'tmp_name' => '/tmp/phpIbsIbf',286 'error' => 0,287 'size' => 25000288 ]289 ],290 'cv',291 [292 'uploadsDir' => '/uploads/cvs/',293 'namePrefix' => 'cv_',294 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],295 'maxFileSizeMB' => 0.5296 ]297 ];298 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')299 ->setConstructorArgs($constructorArgs)300 ->setMethods(['upload', 'checkFile', 'getNewFileName'])301 ->getMock();302 $fileUpload->expects($this->any())303 ->method('upload')304 ->will($this->returnValue(true));305 $fileUpload->expects($this->once())306 ->method('checkFile')307 ->will($this->returnValue([]));308 $jobController = new \JosJobs\Controllers\Job(309 $this->authentication,310 $this->applicationsTable,311 $this->categoriesTable,312 $this->jobsTable,313 $this->locationsTable,314 $this->usersTable,315 $testGetData,316 $testPostData,317 $fileUpload318 );319 $this->assertEquals(320 $jobController->saveApply()['template'],321 '/jobs/apply.html.php'322 );323 }324 /**325 * Given invalid data, a job is not created and the326 * user is shown the form again with errors.327 */328 public function testEmailExceedsLength()329 {330 $testGetData = [331 'id' => 1332 ];333 $testPostData = [334 'application' => [335 'name' => 'John Smith',336 'email' => 'testtesttesttesttesttesttesttesttesttesttest.testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest@testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest.co.uk',337 'details' => '',338 'job_id' => null339 ]340 ];341 $constructorArgs = [342 [343 'cv' => [344 'name' => 'my-resume.pdf',345 'type' => 'application/pdf',346 'tmp_name' => '/tmp/phpIbsIbf',347 'error' => 0,348 'size' => 25000349 ]350 ],351 'cv',352 [353 'uploadsDir' => '/uploads/cvs/',354 'namePrefix' => 'cv_',355 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],356 'maxFileSizeMB' => 0.5357 ]358 ];359 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')360 ->setConstructorArgs($constructorArgs)361 ->setMethods(['upload', 'checkFile', 'getNewFileName'])362 ->getMock();363 $fileUpload->expects($this->any())364 ->method('upload')365 ->will($this->returnValue(true));366 $fileUpload->expects($this->once())367 ->method('checkFile')368 ->will($this->returnValue([]));369 $jobController = new \JosJobs\Controllers\Job(370 $this->authentication,371 $this->applicationsTable,372 $this->categoriesTable,373 $this->jobsTable,374 $this->locationsTable,375 $this->usersTable,376 $testGetData,377 $testPostData,378 $fileUpload379 );380 $this->assertEquals(381 $jobController->saveApply()['template'],382 '/jobs/apply.html.php'383 );384 }385 /**386 * Given invalid data, a job is not created and the387 * user is shown the form again with errors.388 */389 public function testInvalidEmailFmt()390 {391 $testGetData = [392 'id' => 1393 ];394 $testPostData = [395 'application' => [396 'name' => 'John Smith',397 'email' => 'john.smith[at]example[dot]org',398 'details' => '',399 'job_id' => null400 ]401 ];402 $constructorArgs = [403 [404 'cv' => [405 'name' => 'my-resume.pdf',406 'type' => 'application/pdf',407 'tmp_name' => '/tmp/phpIbsIbf',408 'error' => 0,409 'size' => 25000410 ]411 ],412 'cv',413 [414 'uploadsDir' => '/uploads/cvs/',415 'namePrefix' => 'cv_',416 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],417 'maxFileSizeMB' => 0.5418 ]419 ];420 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')421 ->setConstructorArgs($constructorArgs)422 ->setMethods(['upload', 'checkFile', 'getNewFileName'])423 ->getMock();424 $fileUpload->expects($this->any())425 ->method('upload')426 ->will($this->returnValue(true));427 $fileUpload->expects($this->once())428 ->method('checkFile')429 ->will($this->returnValue([]));430 $jobController = new \JosJobs\Controllers\Job(431 $this->authentication,432 $this->applicationsTable,433 $this->categoriesTable,434 $this->jobsTable,435 $this->locationsTable,436 $this->usersTable,437 $testGetData,438 $testPostData,439 $fileUpload440 );441 $this->assertEquals(442 $jobController->saveApply()['template'],443 '/jobs/apply.html.php'444 );445 }446 /**447 * Given invalid data, a job is not created and the448 * user is shown the form again with errors.449 */450 public function testFileExceedsSize()451 {452 $testGetData = [453 'id' => 1454 ];455 $testPostData = [456 'application' => [457 'name' => 'John Smith',458 'email' => 'john.smith[at]example[dot]org',459 'details' => '',460 'job_id' => null461 ]462 ];463 $constructorArgs = [464 [465 'cv' => [466 'name' => 'my-resume.pdf',467 'type' => 'application/pdf',468 'tmp_name' => '/tmp/phpIbsIbf',469 'error' => 0,470 'size' => 75000471 ]472 ],473 'cv',474 [475 'uploadsDir' => '/uploads/cvs/',476 'namePrefix' => 'cv_',477 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],478 'maxFileSizeMB' => 0.5479 ]480 ];481 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')482 ->setConstructorArgs($constructorArgs)483 ->setMethods(['upload', 'checkFile', 'getNewFileName'])484 ->getMock();485 $fileUpload->expects($this->any())486 ->method('upload')487 ->will($this->returnValue(true));488 $fileUpload->expects($this->once())489 ->method('checkFile')490 ->will($this->returnValue(['File exceeds max size']));491 $jobController = new \JosJobs\Controllers\Job(492 $this->authentication,493 $this->applicationsTable,494 $this->categoriesTable,495 $this->jobsTable,496 $this->locationsTable,497 $this->usersTable,498 $testGetData,499 $testPostData,500 $fileUpload501 );502 $this->assertEquals(503 $jobController->saveApply()['template'],504 '/jobs/apply.html.php'505 );506 }507 /**508 * Given invalid data, a job is not created and the509 * user is shown the form again with errors.510 */511 public function testFileInvalidType()512 {513 $testGetData = [514 'id' => 1515 ];516 $testPostData = [517 'application' => [518 'name' => 'John Smith',519 'email' => 'john.smith[at]example[dot]org',520 'details' => '',521 'job_id' => null522 ]523 ];524 $constructorArgs = [525 [526 'cv' => [527 'name' => 'my-resume.txt',528 'type' => 'application/pdf',529 'tmp_name' => '/tmp/phpIbsIbf',530 'error' => 0,531 'size' => 75000532 ]533 ],534 'cv',535 [536 'uploadsDir' => '/uploads/cvs/',537 'namePrefix' => 'cv_',538 'validFileExts' => ['docx', 'doc', 'pdf', 'rtf'],539 'maxFileSizeMB' => 0.5540 ]541 ];542 $fileUpload = $this->getMockBuilder('\CupOfPHP\FileUpload')543 ->setConstructorArgs($constructorArgs)544 ->setMethods(['upload', 'checkFile', 'getNewFileName'])545 ->getMock();546 $fileUpload->expects($this->any())547 ->method('upload')548 ->will($this->returnValue(true));549 $fileUpload->expects($this->once())550 ->method('checkFile')551 ->will($this->returnValue(['File invalid type']));552 $jobController = new \JosJobs\Controllers\Job(553 $this->authentication,554 $this->applicationsTable,555 $this->categoriesTable,556 $this->jobsTable,557 $this->locationsTable,558 $this->usersTable,559 $testGetData,560 $testPostData,561 $fileUpload562 );563 $this->assertEquals(564 $jobController->saveApply()['template'],565 '/jobs/apply.html.php'566 );567 }568}...
CategoryControllerTest.php
Source:CategoryControllerTest.php
...14 $this->assertNotEmpty($categoryController->listCategories());15 }16 // Edit Category Form Tests17 public function testShowEditCategoryForm() {18 $testGetData = [19 'id' => 120 ];21 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, $testGetData, []); 22 $this->assertNotEmpty($categoryController->editCategoryForm());23 }24 public function testShowEditCategoryFormNoID() {25 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, [], []); 26 $this->assertNotEmpty($categoryController->editCategoryForm());27 }28 // Create Category Tests29 public function testCreateCategoryNoName() {30 $testPostData = [31 'category' => [32 'name' => ''33 ],34 'submit' => true35 ];36 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, [], $testPostData);37 38 $this->assertCount(1, $categoryController->editCategorySubmit()['variables']['errors']);39 }40 public function testCreateCategory() {41 $testPostData = [42 'category' => [43 'name' => 'Test Category'44 ],45 'submit' => true46 ];47 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, [], $testPostData);48 $categoryController->editCategorySubmit();49 50 $category = $this->pdo->query('SELECT name FROM category WHERE name = "Test Category";')->fetch();51 52 $this->assertEquals($category['name'], 'Test Category');53 }54 // Edit Category Tests55 public function testEditCategoryNoName() {56 $testGetData = [57 'id' => 458 ];59 $testPostData = [60 'category' => [61 'id' => 4,62 'name' => ''63 ],64 'submit' => true65 ];66 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, $testGetData, $testPostData);67 68 $this->assertCount(1, $categoryController->editCategorySubmit()['variables']['errors']);69 }70 public function testEditCategory() {71 $testGetData = [72 'id' => 473 ];74 $testPostData = [75 'category' => [76 'id' => 4,77 'name' => 'Testing Category'78 ],79 'submit' => true80 ];81 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, $testGetData, $testPostData);82 $categoryController->editCategorySubmit();83 $category = $this->pdo->query('SELECT id, name FROM category WHERE id = 4;')->fetch();84 $this->assertEquals($category['name'], 'Testing Category'); 85 }86 // Delete Category Test87 public function testDeleteCategory() {88 $testPostData = [89 'category' => [90 'id' => 491 ]92 ];93 $categoryController = new \JobSite\Controllers\CategoryController($this->categoriesTable, [], $testPostData);94 @$categoryController->deleteCategory();95 $category = $this->pdo->query('SELECT name FROM category WHERE name = "Test Category";')->fetch();...
testGetData
Using AI Code Generation
1$obj = new data();2$obj->testGetData();3$obj = new data();4$obj->testGetData();5$obj = new data();6$obj->testGetData();7$obj = new data();8$obj->testGetData();9$obj = new data();10$obj->testGetData();11$obj = new data();12$obj->testGetData();13$obj = new data();14$obj->testGetData();15$obj = new data();16$obj->testGetData();17$obj = new data();18$obj->testGetData();19{20 public static function methodName()21 {22 }23}24{25 public static function testGetData()26 {27 echo "This is a static method.";28 }29}30data::testGetData();
testGetData
Using AI Code Generation
1$test = new data();2$test->testGetData();3$test = new data();4$test->testGetData();5$test = new data();6$test->testGetData();7$test = new data();8$test->testGetData();9$test = new data();10$test->testGetData();11$test = new data();12$test->testGetData();
testGetData
Using AI Code Generation
1$data = new data;2echo $data->testGetData();3$data = new data;4echo $data->testGetData();5$data = new data;6echo $data->testGetData();7$data = new data;8echo $data->testGetData();9$data = new data;10echo $data->testGetData();11$data = new data;12echo $data->testGetData();13$data = new data;14echo $data->testGetData();15$data = new data;16echo $data->testGetData();17$data = new data;18echo $data->testGetData();19$data = new data;20echo $data->testGetData();21$data = new data;22echo $data->testGetData();23$data = new data;24echo $data->testGetData();25$data = new data;26echo $data->testGetData();27$data = new data;28echo $data->testGetData();29$data = new data;30echo $data->testGetData();31$data = new data;32echo $data->testGetData();33$data = new data;34echo $data->testGetData();35$data = new data;36echo $data->testGetData();37$data = new data;38echo $data->testGetData();39$data = new data;40echo $data->testGetData();41$data = new data;42echo $data->testGetData();43$data = new data;44echo $data->testGetData();45$data = new data;46echo $data->testGetData();47$data = new data;48echo $data->testGetData();49$data = new data;50echo $data->testGetData();51$data = new data;52echo $data->testGetData();
testGetData
Using AI Code Generation
1$test = new data();2$test->testGetData();3{4 public function testGetData()5 {6 $data = $this->getData();7 echo $data;8 }9 public function getData()10 {11 return 'data';12 }13}
testGetData
Using AI Code Generation
1include 'data.php';2$obj = new data();3$obj->testGetData();4include 'data.php';5$obj = new data();6$obj->testGetData();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with testGetData on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!