From 0eb056c6c07a212b3036674a06d734546e943f53 Mon Sep 17 00:00:00 2001 From: Davide Bellettini Date: Tue, 5 Mar 2013 14:58:51 +0100 Subject: [PATCH] Stubbing Behat tests #266 --- .../Features/Context/FeatureContext.php | 57 ++++++++++++++++++- .../WebsiteBundle/Features/file_add.feature | 13 +++++ .../WebsiteBundle/Features/login.feature | 12 ++-- .../Features/myuniversibo.feature | 4 +- 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 src/Universibo/Bundle/WebsiteBundle/Features/file_add.feature diff --git a/src/Universibo/Bundle/WebsiteBundle/Features/Context/FeatureContext.php b/src/Universibo/Bundle/WebsiteBundle/Features/Context/FeatureContext.php index e9ac8042..4ba90965 100644 --- a/src/Universibo/Bundle/WebsiteBundle/Features/Context/FeatureContext.php +++ b/src/Universibo/Bundle/WebsiteBundle/Features/Context/FeatureContext.php @@ -2,9 +2,11 @@ namespace Universibo\Bundle\WebsiteBundle\Features\Context; +use Behat\Behat\Exception\PendingException; use Behat\MinkExtension\Context\MinkContext; use Behat\Symfony2Extension\Context\KernelAwareInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Universibo\Bundle\LegacyBundle\Entity\Canale; /** * Feature context. @@ -14,6 +16,7 @@ class FeatureContext extends MinkContext { private $kernel; private $parameters; + private $channelId; /** * Initializes context with parameters from behat.yml. @@ -121,10 +124,62 @@ public function iClickOnButton($button) } /** - * @Then /^Text "([^"]*)" should be present$/ + * @Then /^text "([^"]*)" should be present$/ */ public function textShouldBePresent($text) { $this->assertPageContainsText($text); } + + /** + * @Given /^there is a channel with file service$/ + */ + public function thereIsAChannelWithFileService() + { + $container = $this->kernel->getContainer(); + + $db = $container->get('doctrine.dbal.default_connection'); + + $query = $db + ->createQueryBuilder() + ->select('c.id_canale') + ->from('canale', 'c') + ->where('c.files_attivo = ?') + ->setMaxResults(1) + ->setParameter(1, 'S') + ->execute() + ; + + $id = $query->fetchColumn(); + + if (false === $id) { + $channel = new Canale(); + $channelRepo = $container->get('universibo_legacy.repository.canale'); + + $id = $channel->getIdCanale(); + $channel->setServizioFiles(true); + + $channelRepo->save($channel); + } + + $this->channelId = $id; + + throw new PendingException(); + } + + /** + * @When /^I visit that channel$/ + */ + public function iVisitThatChannel() + { + throw new PendingException(); + } + + /** + * @Given /^I select a PHP file for upload$/ + */ + public function iSelectAPhpFileForUpload() + { + throw new PendingException(); + } } diff --git a/src/Universibo/Bundle/WebsiteBundle/Features/file_add.feature b/src/Universibo/Bundle/WebsiteBundle/Features/file_add.feature new file mode 100644 index 00000000..d79c48a5 --- /dev/null +++ b/src/Universibo/Bundle/WebsiteBundle/Features/file_add.feature @@ -0,0 +1,13 @@ +Feature: Publish a file + In order to make a file available to users + As user with rights on a channel + I want to add a file to it + + Scenario: PHP file upload (forbidden action) + Given I'm logged in as "admin" + And there is a channel with file service + When I visit that channel + And I click on "Invia un nuovo file" link + And I select a PHP file for upload + And I click on "xxx" button + Then text "vietato" should be present \ No newline at end of file diff --git a/src/Universibo/Bundle/WebsiteBundle/Features/login.feature b/src/Universibo/Bundle/WebsiteBundle/Features/login.feature index 8f93d536..870eb1c7 100644 --- a/src/Universibo/Bundle/WebsiteBundle/Features/login.feature +++ b/src/Universibo/Bundle/WebsiteBundle/Features/login.feature @@ -9,7 +9,7 @@ Feature: Login And I type "admin" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto admin" should be present + Then text "Benvenuto admin" should be present And Text "Il tuo livello di utenza è Admin" should be present Scenario: Logging in as a Moderator @@ -18,7 +18,7 @@ Feature: Login And I type "moderator" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto moderator" should be present + Then text "Benvenuto moderator" should be present And Text "Il tuo livello di utenza è Collaboratore" should be present Scenario: Logging in as a Student @@ -27,7 +27,7 @@ Feature: Login And I type "student" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto student" should be present + Then text "Benvenuto student" should be present And Text "Il tuo livello di utenza è Studente" should be present Scenario: Logging in as a Professor @@ -36,7 +36,7 @@ Feature: Login And I type "professor" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto professor" should be present + Then text "Benvenuto professor" should be present And Text "Il tuo livello di utenza è Docente" should be present Scenario: Logging in as a Tutor @@ -45,7 +45,7 @@ Feature: Login And I type "tutor" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto tutor" should be present + Then text "Benvenuto tutor" should be present And Text "Il tuo livello di utenza è Tutor" should be present Scenario: Logging in as a non-teaching staff member @@ -54,5 +54,5 @@ Feature: Login And I type "staff" on "username" field And I type "padrino" on "password" field And I click on "Login" button - Then Text "Benvenuto staff" should be present + Then text "Benvenuto staff" should be present And Text "Il tuo livello di utenza è Personale non docente" should be present \ No newline at end of file diff --git a/src/Universibo/Bundle/WebsiteBundle/Features/myuniversibo.feature b/src/Universibo/Bundle/WebsiteBundle/Features/myuniversibo.feature index 68336ad5..d3a396da 100644 --- a/src/Universibo/Bundle/WebsiteBundle/Features/myuniversibo.feature +++ b/src/Universibo/Bundle/WebsiteBundle/Features/myuniversibo.feature @@ -6,5 +6,5 @@ Feature: ShowMyUniversiBO Scenario: Plain test Given I'm logged in as "student" When I visit "/my/universibo" - Then Text "My News" should be present - And Text "My Files" should be present \ No newline at end of file + Then text "My News" should be present + And text "My Files" should be present \ No newline at end of file