Commits

Vasiliy Toporov committed e88f622

Done Functional tests.

  • Participants
  • Parent commits 15ddaad

Comments (0)

Files changed (3)

src/Ens/JobeetBundle/Resources/views/Job/index.html.twig

 {% block content %}
   <div id="jobs">
     {% for category in categories %}
-      <div>
-        <div class="category">
+      <div id="{{ category.slug }}">
+        <div class="category_{{ category.slug }}">
           <div class="feed">
             <a href="">Feed</a>
           </div>

src/Ens/JobeetBundle/Tests/Controller/CategoryControllerTest.php

+<?php
+
+namespace Ens\JobeetBundle\Tests\Controller;
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+ 
+class CategoryControllerTest extends WebTestCase
+{
+    public function testShow()
+    {
+        // get the custom parameters from app config.yml
+        $kernel = static::createKernel();
+        $kernel->boot();
+        $max_jobs_on_homepage = $kernel->getContainer()->getParameter('max_jobs_on_homepage');
+        $max_jobs_on_category = $kernel->getContainer()->getParameter('max_jobs_on_category');
+
+        $client = static::createClient();
+
+        // categories on homepage are clickable
+        $crawler = $client->request('GET', '/');
+        $link = $crawler->selectLink('Programming')->link();
+        $crawler = $client->click($link);
+        $this->assertEquals('Ens\JobeetBundle\Controller\CategoryController::showAction', $client->getRequest()->attributes->get('_controller'));
+        $this->assertEquals('programming', $client->getRequest()->attributes->get('slug'));
+
+        // categories with more than $max_jobs_on_homepage jobs also have a "more" link
+        $crawler = $client->request('GET', '/');
+        $link = $crawler->selectLink('22')->link();
+        $crawler = $client->click($link);
+        $this->assertEquals('Ens\JobeetBundle\Controller\CategoryController::showAction', $client->getRequest()->attributes->get('_controller'));
+        $this->assertEquals('programming', $client->getRequest()->attributes->get('slug'));
+
+        // only $max_jobs_on_category jobs are listed
+        $this->assertTrue($crawler->filter('.jobs tr')->count() == 20);
+        $this->assertRegExp('/32 jobs/', $crawler->filter('.pagination_desc')->text());
+        $this->assertRegExp('/page 1\/2/', $crawler->filter('.pagination_desc')->text());
+
+        $link = $crawler->selectLink('2')->link();
+        $crawler = $client->click($link);
+        $this->assertEquals(2, $client->getRequest()->attributes->get('page'));
+        $this->assertRegExp('/page 2\/2/', $crawler->filter('.pagination_desc')->text());
+    }
+}

src/Ens/JobeetBundle/Tests/Controller/JobControllerTest.php

 <?php
 
 namespace Ens\JobeetBundle\Tests\Controller;
-
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
-
+ 
 class JobControllerTest extends WebTestCase
 {
-    /*
-    public function testCompleteScenario()
+    public function getMostRecentProgrammingJob()
     {
-        // Create a new client to browse the application
+        $kernel = static::createKernel();
+        $kernel->boot();
+        $em = $kernel->getContainer()->get('doctrine.orm.entity_manager');
+
+        $query = $em->createQuery('SELECT j from EnsJobeetBundle:Job j LEFT JOIN j.category c WHERE c.slug = :slug AND j.expires_at > :date ORDER BY j.created_at DESC');
+        $query->setParameter('slug', 'programming');
+        $query->setParameter('date', date('Y-m-d H:i:s', time()));
+        $query->setMaxResults(1);
+        return $query->getSingleResult();
+    }
+
+    public function getExpiredJob()
+    {
+        $kernel = static::createKernel();
+        $kernel->boot();
+        $em = $kernel->getContainer()->get('doctrine.orm.entity_manager');
+
+        $query = $em->createQuery('SELECT j from EnsJobeetBundle:Job j WHERE j.expires_at < :date');     $query->setParameter('date', date('Y-m-d H:i:s', time()));
+        $query->setMaxResults(1);
+        return $query->getSingleResult();
+    }
+
+    public function testIndex()
+    {
+        // get the custom parameters from app config.yml
+        $kernel = static::createKernel();
+        $kernel->boot();
+        $max_jobs_on_homepage = $kernel->getContainer()->getParameter('max_jobs_on_homepage');
+        $max_jobs_on_category = $kernel->getContainer()->getParameter('max_jobs_on_category');
+
         $client = static::createClient();
 
-        // Create a new entry in the database
-        $crawler = $client->request('GET', '/ens_job/');
-        $this->assertTrue(200 === $client->getResponse()->getStatusCode());
-        $crawler = $client->click($crawler->selectLink('Create a new entry')->link());
+        $crawler = $client->request('GET', '/');
+        $this->assertEquals('Ens\JobeetBundle\Controller\JobController::indexAction', $client->getRequest()->attributes->get('_controller'));
 
-        // Fill in the form and submit it
-        $form = $crawler->selectButton('Create')->form(array(
-            'ens_jobeetbundle_jobtype[field_name]'  => 'Test',
-            // ... other fields to fill
-        ));
+        // expired jobs are not listed
+        $this->assertTrue($crawler->filter('.jobs td.position:contains("Expired")')->count() == 0);
 
-        $client->submit($form);
-        $crawler = $client->followRedirect();
+        // only $max_jobs_on_homepage jobs are listed for a category
+        $this->assertTrue($crawler->filter('#programming .jobs tr')->count() == 10);
+        $this->assertTrue($crawler->filter('#design .more_jobs')->count() == 0);
+        $this->assertTrue($crawler->filter('#programming .more_jobs')->count() == 1);
 
-        // Check data in the show view
-        $this->assertTrue($crawler->filter('td:contains("Test")')->count() > 0);
+        // jobs are sorted by date
+        $this->assertTrue($crawler->filter('#programming .jobs tr')->first()->filter(sprintf('a[href*="/%d/"]', $this->getMostRecentProgrammingJob()->getId()))->count() == 1);
 
-        // Edit the entity
-        $crawler = $client->click($crawler->selectLink('Edit')->link());
+        // each job on the homepage is clickable and give detailed information
+        $job = $this->getMostRecentProgrammingJob();
+        $link = $crawler->selectLink('Web Developer')->first()->link();
+        $crawler = $client->click($link);
+        $this->assertEquals('Ens\JobeetBundle\Controller\JobController::showAction', $client->getRequest()->attributes->get('_controller'));
+        $this->assertEquals($job->getCompanySlug(), $client->getRequest()->attributes->get('company'));
+        $this->assertEquals($job->getLocationSlug(), $client->getRequest()->attributes->get('location'));
+        $this->assertEquals($job->getPositionSlug(), $client->getRequest()->attributes->get('position'));
+        $this->assertEquals($job->getId(), $client->getRequest()->attributes->get('id'));
 
-        $form = $crawler->selectButton('Edit')->form(array(
-            'ens_jobeetbundle_jobtype[field_name]'  => 'Foo',
-            // ... other fields to fill
-        ));
+        // a non-existent job forwards the user to a 404
+        $crawler = $client->request('GET', '/job/foo-inc/milano-italy/0/painter');
+        $this->assertTrue(404 === $client->getResponse()->getStatusCode());
 
-        $client->submit($form);
-        $crawler = $client->followRedirect();
-
-        // Check the element contains an attribute with value equals "Foo"
-        $this->assertTrue($crawler->filter('[value="Foo"]')->count() > 0);
-
-        // Delete the entity
-        $client->submit($crawler->selectButton('Delete')->form());
-        $crawler = $client->followRedirect();
-
-        // Check the entity has been delete on the list
-        $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
+        // an expired job page forwards the user to a 404
+        $crawler = $client->request('GET', sprintf('/job/sensio-labs/paris-france/%d/web-developer-expired', $this->getExpiredJob()->getId()));
+        $this->assertTrue(404 === $client->getResponse()->getStatusCode());
     }
-
-    */
 }