[TASK] Add modal dialog helper for acceptance tests 70/47670/4
authorSascha Egerer <sascha@sascha-egerer.de>
Thu, 14 Apr 2016 15:17:48 +0000 (17:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 14 Apr 2016 21:04:44 +0000 (23:04 +0200)
Add a new helper to interact with modal dialogs in acceptance
tests.
Also refactor the Scheduler Tasks test to use that helper.

Change-Id: Ie1fc4f0b2c98aa5dcdaa7c114d5c257707b65ba7
Resolves: #75620
Releases: master
Reviewed-on: https://review.typo3.org/47670
Reviewed-by: Dirk Jüttner <dirk.juettner@gmail.com>
Tested-by: Dirk Jüttner <dirk.juettner@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Acceptance/Backend/Scheduler/TasksCest.php
typo3/sysext/core/Tests/Acceptance/Support/Helper/ModalDialog.php [new file with mode: 0644]

index 15990f8..115c683 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Scheduler;
  */
 
 use TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Admin;
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\ModalDialog;
 
 /**
  * Scheduler task tests
@@ -78,14 +79,22 @@ class TasksCest
     /**
      * @depends createASchedulerTask
      * @param Admin $I
+     * @param ModalDialog $modalDialog
      */
-    public function canDeleteTask(Admin $I)
+    public function canDeleteTask(Admin $I, ModalDialog $modalDialog)
     {
-        // delete the task
+        $I->wantTo('See a delete button for a task');
+        $I->seeElement('//a[contains(@title, "Delete")]');
+
         $I->click('//a[contains(@title, "Delete")]');
-        $I->switchToIFrame();
-        $I->waitForElement('.t3-modal.modal');
-        $I->click('.t3-modal.modal .btn.btn-warning');
+        $I->wantTo('Cancel the delete dialog');
+        $modalDialog->clickButtonInDialog('Cancel');
+        $I->switchToIFrame('content');
+
+        $I->wantTo('Still see and can click the Delete button as the deletion has been canceled');
+        $I->click('//a[contains(@title, "Delete")]');
+        $modalDialog->clickButtonInDialog('OK');
+
         $I->switchToIFrame('content');
         $I->see('The task was successfully deleted.');
         $I->see('No tasks defined yet');
diff --git a/typo3/sysext/core/Tests/Acceptance/Support/Helper/ModalDialog.php b/typo3/sysext/core/Tests/Acceptance/Support/Helper/ModalDialog.php
new file mode 100644 (file)
index 0000000..cddf85c
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Acceptance\Support\Helper;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use AcceptanceTester;
+
+/**
+ * Helper to interact with modal dialogs that appear for example when
+ * you delete a record or have to confirm something.
+ *
+ *  --------------------------------
+ * | Would you like to continue?    |
+ * |                                |
+ * |            [no] [maybe] [yeah] |
+ *  --------------------------------
+ */
+class ModalDialog
+{
+    /**
+     * Selector for a visible modal window
+     *
+     * @var string
+     */
+    public static $openedModalSelector = '.t3-modal.in';
+
+    /**
+     * Selector for the container in the modal where the buttons are located
+     *
+     * @var string
+     */
+    public static $openedModalButtonContainerSelector = '.t3-modal.in .modal-footer';
+
+    /**
+     * @var AcceptanceTester
+     */
+    protected $tester;
+
+    /**
+     * @param AcceptanceTester $I
+     */
+    public function __construct(\AcceptanceTester $I)
+    {
+        $this->tester = $I;
+    }
+
+    /**
+     * Perform a click on a link or a button, given by a locator.
+     *
+     * @param string $buttonLinkLocator the button title
+     * @see \Codeception\Module\WebDriver::click()
+     */
+    public function clickButtonInDialog(string $buttonLinkLocator)
+    {
+        $I = $this->tester;
+        $this->canSeeDialog();
+        $I->click($buttonLinkLocator, self::$openedModalButtonContainerSelector);
+    }
+
+    /**
+     * Check if modal dialog is visible in top frame
+     */
+    public function canSeeDialog()
+    {
+        $I = $this->tester;
+        $I->switchToIFrame();
+        $I->waitForElement(self::$openedModalSelector);
+    }
+}