vendor/simpledot/cms-bundle/AWCmsBundle/Behat/Context/CMSFeatureContext.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: albert
  5.  * Date: 27/11/18
  6.  * Time: 18:31
  7.  */
  8. namespace AWCmsBundle\Behat\Context;
  9. use Behat\Behat\Hook\Scope\AfterStepScope;
  10. use Behat\MinkExtension\Context\MinkAwareContext;
  11. use Behat\Symfony2Extension\Context\KernelDictionary;
  12. use Behat\Behat\Hook\Scope\AfterScenarioScope;
  13. use PHPUnit\Framework\Assert;
  14. class CMSFeatureContext extends RawFeatureContext implements MinkAwareContext
  15. {
  16.     use KernelDictionary;
  17.     private $temporal_files = [];
  18.     /**
  19.      * @Given I m logged as an super admin
  20.      */
  21.     public function iMLoggedAsAnSuperAdmin()
  22.     {
  23.         $this->visitPath('/fr/admin/login');
  24.         $this->getPage()->findField('Identifiant')->setValue('super-admin@test.com');
  25.         $this->getPage()->findField('Mot de passe')->setValue('123456');
  26.         $this->getPage()->pressButton('Connexion');
  27.     }
  28.     /**
  29.      * @Then the :arg1 row should contains :arg2
  30.      */
  31.     public function theRowShouldContains($rowText$rowContains)
  32.     {
  33.         $row $this->getPage()->find('css'sprintf('table.table tr:contains("%s")'$rowText));
  34.         Assert::assertNotNull($row'Could not find a row with text '.$rowText);
  35.         $td $row->find('css'sprintf('td:contains("%s")'$rowContains));
  36.         Assert::assertNotNull($td'Could not find a row with text '.$rowContains);
  37.     }
  38.     /**
  39.      * @When I follow :linkText on the :rowText row
  40.      */
  41.     public function iFollowOnTheRow($linkText$rowText)
  42.     {
  43.         $selector sprintf('table.table tr[data-user="%s"]'$rowText);
  44.         $row $this->getPage()->find('css'$selector);
  45.         Assert::assertNotNull($row'Could not find a row with text '.$rowText);
  46.         Assert::assertContains($linkText$row->getHtml());
  47.         $row->clickLink($linkText);
  48.     }
  49.     /**
  50.      * @Given I m logged as an admin
  51.      */
  52.     public function iMLoggedAsAnAdmin()
  53.     {
  54.         $this->visitPath('/fr/admin/login');
  55.         $this->getPage()->findField('Identifiant')->setValue('admin@test.com');
  56.         $this->getPage()->findField('Mot de passe')->setValue('123456');
  57.         $this->getPage()->pressButton('Connexion');
  58.     }
  59.     /**
  60.      * @Then I should see :arg1 in output
  61.      */
  62.     public function iShouldSeeInOutput($arg1)
  63.     {
  64.         Assert::assertContains($arg1$this->getPage()->getContent());
  65.     }
  66.     /**
  67.      * @param $input
  68.      * @Then I should see :input unchecked
  69.      */
  70.     public function iShouldSeeInputUnchecked($input)
  71.     {
  72.         Assert::assertFalse($this->getPage()->findField($input)->isChecked());
  73.     }
  74.     /**
  75.      * @param $input
  76.      * @Then I should see :input checked
  77.      */
  78.     public function iShouldSeeInputChecked($input)
  79.     {
  80.         Assert::assertTrue($this->getPage()->findField($input)->isChecked());
  81.     }
  82.     /**
  83.      * @When I click on label :arg1
  84.      */
  85.     public function iClickOnLabel($arg1)
  86.     {
  87.         $element $this->getPage()->find('css''label[data-label="'.$arg1.'"]');
  88.         if (empty($element)) {
  89.             throw new \Exception("No html element found for the selector ('$arg1')");
  90.         }
  91.         $element->click();
  92.         $this->saveScreenshot('screenshot.jpg''/var/www/web/');
  93.     }
  94.     /**
  95.      * @Given /^print last logs$/
  96.      */
  97.     public function printLastLogs()
  98.     {
  99.         $file $this->getKernel()->getLogDir().'/test.log';
  100.         if(file_exists($file)){
  101.             echo file_get_contents($file);
  102.         }
  103.     }
  104.     /**
  105.      * @Given /^print last apache logs$/
  106.      */
  107.     public function printLastApacheLogs()
  108.     {
  109.         $file '/var/logs/apache2/app_error.log';
  110.         if(file_exists($file)){
  111.             echo file_get_contents($file);
  112.         }
  113.     }
  114.     /**
  115.      * @param $seconds
  116.      * @param $text
  117.      * @When I wait :arg1 seconds until I see :arg2
  118.      */
  119.     public function iWaitSecondsUntilISee($seconds$text)
  120.     {
  121.         $this->getSession()->wait($seconds*1000'document.evaluate(\'contains(., "'.$text.'")\', document, null, XPathResult.ANY_TYPE, null ).booleanValue === true');
  122.     }
  123.     /**
  124.      * @param $seconds
  125.      * @param $text
  126.      * @When I wait :arg1 seconds until I don't see :arg2
  127.      */
  128.     public function iWaitSecondsUntilIDontSee($seconds$text)
  129.     {
  130.         $this->getSession()->wait($seconds*1000'document.evaluate(\'contains(., "'.$text.'")\', document, null, XPathResult.ANY_TYPE, null ).booleanValue === false');
  131.     }
  132.     
  133.     /**
  134.      * @AfterStep
  135.      * @param AfterStepScope $event
  136.      */
  137.     public function errorHandle(AfterStepScope $event){
  138.         if(!$event->getTestResult()->isPassed()){
  139.             if( $this->getPage()->find('css''.exception-message')){
  140.                 echo "\n".$this->getPage()->find('css''.exception-message')->getText();
  141.             }
  142.             if( $this->getPage()->find('css''.trace-file-path')){
  143.                 echo "\n".$this->getPage()->find('css''.trace-file-path')->getText();
  144.             }
  145.         }
  146.     }
  147.     
  148.     /**
  149.      * @When /^I check the "([^"]*)" radio button$/
  150.      */
  151.     public function iCheckTheRadioButton($labelText)
  152.     {
  153.         $page $this->getSession()->getPage();
  154.         $radioButton $page->find('named', ['radio'$labelText]);
  155.         if ($radioButton) {
  156.             $select $radioButton->getAttribute('name');
  157.             $option $radioButton->getAttribute('value');
  158.             $page->selectFieldOption($select$option);
  159.             return;
  160.         }
  161.         
  162.         throw new \Exception("Radio button with label {$labelText} not found");
  163.     }
  164. }