[TASK] Add acceptance tests for client side validation for basic elements 32/47732/5
authorSascha Egerer <sascha@sascha-egerer.de>
Sat, 16 Apr 2016 19:46:46 +0000 (21:46 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 18 Apr 2016 21:24:43 +0000 (23:24 +0200)
Change-Id: If043e3a90a5326521c335b9f0158eb59256a3767
Related: #75626
Releases: master
Reviewed-on: https://review.typo3.org/47732
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.suite.yml
typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicCest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Acceptance/Backend/Page/AddPageInPageModuleCest.php
typo3/sysext/core/Tests/Acceptance/Support/Helper/Formhandler.php [new file with mode: 0644]

index ab03114..fab19fb 100644 (file)
@@ -12,6 +12,14 @@ modules:
       window_size: 1440x570
       wait: 1
       restart: true
+      capabilities:
+        # Disable the "scroll to element before clicking" behavior as this breaks tests
+        # where for example a fixed docbar is used. Selenium scrolls to the element before
+        # clicking it and then complains that it can't click the element because another elemnt
+        # is overlaying it.
+        # You have to ensure that the element is in the viewport by your own before clicking it!
+        # You can simply do that by scrolling to it.
+        elementScrollBehavior: 1
 env:
   firefox:
     modules:
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicCest.php
new file mode 100644 (file)
index 0000000..9f2da7b
--- /dev/null
@@ -0,0 +1,319 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Acceptance\Backend\Formhandler;
+
+/*
+ * 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 TYPO3\CMS\Core\Tests\Acceptance\Step\Backend\Admin;
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Helper\Formhandler;
+use TYPO3\CMS\Core\Tests\Acceptance\Support\Page\PageTree;
+
+/**
+ * Tests for basic element fields
+ */
+class ElementsBasicCest
+{
+    /**
+     * Selector of the record container in the listview
+     * @var string
+     */
+    protected static $listViewRecordSelector = '#recordlist-tx_styleguide_elements_basic';
+
+    public function _before(Admin $I, PageTree $pageTree)
+    {
+        $I->useExistingSession();
+
+        $I->click('List');
+        $pageTree->openPath(['styleguide TCA demo', 'elements basic']);
+        $I->switchToIFrame('content');
+    }
+
+    /**
+     * @param Admin $I
+     * @param Formhandler $formhandler
+     */
+    public function checkThatBrowserSideValidationsWorkAndSaveRecord(Admin $I, Formhandler $formhandler)
+    {
+        $I->click(self::$listViewRecordSelector . ' a[data-original-title="Edit record"]');
+        $I->waitForText('Edit Form', 3, 'h1');
+
+        $fieldTests = [
+            'input_1' => [
+                [
+                    'This is a demo text with 2 numbers #!',
+                    'This is a demo text with 2 numbers #!',
+                ],
+            ],
+            'input_2, size=10' => [
+                [
+                    'This is a demo text with 2 numbers #!',
+                    'This is a demo text with 2 numbers #!',
+                ],
+            ],
+            'input_3 max=4' => [
+                [
+                    'Kasper',
+                    'Kasp',
+                ],
+            ],
+            'input_4 eval=alpha' => [
+                [
+                    'Kasper = TYPO3',
+                    'Kasper  TYPO',
+                ],
+            ],
+            'input_5 eval=alphanum' => [
+                [
+                    'Kasper = TYPO3',
+                    'Kasper  TYPO3',
+                ],
+            ],
+            'input_6 eval=date' => [
+                [
+                    '29-01-2016',
+                    '29-01-2016',
+                    '1454025600',
+                ],
+                [
+                    '13-13-2016',
+                    '13-01-2017',
+                    '1484265600',
+                ],
+
+                'check valid leap year input' => [
+                    '29-02-2016',
+                    '29-02-2016',
+                    '1456704000',
+                ],
+                'check invalid leap year transformation' => [
+                    '29-02-2015',
+                    '01-03-2015',
+                    '1425168000',
+                ],
+            ],
+            'input_8 eval=double2' => [
+                [
+                    '12.335',
+                    '12.34',
+                ],
+                [
+                    '12,335',
+                    '12.34',
+                ],
+                [
+                    '1.1',
+                    '1.10',
+                ],
+                [
+                    'TYPO3',
+                    '3.00',
+                ],
+                [
+                    '3TYPO',
+                    '3.00',
+                ],
+            ],
+            'input_9 eval=int' => [
+                [
+                    '12.335',
+                    '12',
+                ],
+                [
+                    '12,9',
+                    '12',
+                ],
+                [
+                    'TYPO3',
+                    '0',
+                ],
+                [
+                    '3TYPO',
+                    '3',
+                ],
+            ],
+            'input_10 eval=is_in, is_in=abc123' => [
+                [
+                    'abcd1234',
+                    'abc123',
+                ],
+                [
+                    'Kasper TYPO3',
+                    'a3',
+                ],
+            ],
+            'input_11 eval=lower' => [
+                [
+                    'Kasper TYPO3!',
+                    'kasper typo3!',
+                ],
+            ],
+            'input_12 eval=md5' => [
+                [
+                    'Kasper TYPO3!',
+                    '748469dd64911af8df8f9a3dcb2c9378',
+                ],
+                'check that whitespace is not trimmed' => [
+                    'Kasper TYPO3! ',
+                    '265e09df9b9b08ab1f946510f510d3ef',
+                ],
+            ],
+            'input_13 eval=nospace' => [
+                [
+                    ' Kasper TYPO3! ',
+                    'KasperTYPO3!',
+                ],
+            ],
+            // @todo define test
+            //'input_14 eval=null' => [
+            //],
+            'input_15 eval=num' => [
+                [
+                    '12.335',
+                    '12335',
+                ],
+                [
+                    '12,9',
+                    '129',
+                ],
+                [
+                    'TYPO3',
+                    '3',
+                ],
+                [
+                    '3TYPO',
+                    '3',
+                ],
+            ],
+            'input_16 eval=password' => [
+                [
+                    'Kasper',
+                    '********',
+                    'Kasper',
+                ],
+            ],
+            'input_17 eval=time' => [
+                [
+                    '13:30',
+                    '13:30',
+                    '48600',
+                ],
+                [
+                    '123',
+                    '12:03',
+                    '43380',
+                ],
+                [
+                    '12345',
+                    '12:34',
+                    '45240',
+                ],
+                [
+                    '12:04+5',
+                    '12:09',
+                    '43740',
+                ],
+                [
+                    '12:09-3',
+                    '12:06',
+                    '43560',
+                ]
+            ],
+            'input_18 eval=timesec' => [
+                [
+                    '13:30:00',
+                    '13:30:00',
+                    '48600',
+                ],
+                [
+                    '12345',
+                    '12:34:05',
+                    '45245',
+                ],
+                [
+                    // @todo is that the expected behavior?
+                    '12:04:04+5',
+                    '12:09:04',
+                    '43744',
+                ],
+            ],
+            'input_19 eval=trim' => [
+                [
+                    ' Kasper ',
+                    'Kasper',
+                ],
+                [
+                    ' Kasper TYPO3 ',
+                    'Kasper TYPO3',
+                ],
+            ],
+            // @todo Check why this test is currently broken
+            //'input_20 eval with user function' => [
+            //    [
+            //        'Kasper',
+            //        'KasperJSfoo',
+            //    ]
+            //],
+            'input_23 eval=upper' => [
+                [
+                    'Kasper TYPO3!',
+                    'KASPER TYPO3!',
+                ],
+            ],
+            'input_24 eval=year' => [
+                [
+                    '2016',
+                    '2016',
+                ],
+                [
+                    '12',
+                    '2012',
+                ],
+                'Invalid character is converted to current year' => [
+                    'Kasper',
+                    date('Y'),
+                ],
+            ],
+            'input_25 eval=int, default=0, range lower=-2, range upper=2' => [
+                [
+                    'Kasper TYPO3',
+                    '0',
+                ],
+                [
+                    '2',
+                    '2',
+                ],
+                [
+                    '-1',
+                    '-1',
+                ],
+                [
+                    '-3',
+                    '-3',
+                    // @todo Check for validation error
+                ],
+                [
+                    '3',
+                    '3',
+                    // @todo Check for validation error
+                ],
+            ],
+        ];
+
+        foreach ($fieldTests as $fieldKey => $testData) {
+            $formhandler->fillSeeDeleteInputField(
+                $formhandler->getContextForFormhandlerField($fieldKey),
+                $testData
+            );
+        }
+    }
+}
index 19511e8..643439a 100644 (file)
@@ -68,7 +68,9 @@ class AddPageInPageModuleCest
         $I->wait(2);
         $editControllerDiv = '#EditDocumentController > div';
         $generalTab = $editControllerDiv . ' > div:nth-child(1) > ul > li';
-        $classString = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) use ($generalTab) {
+        $classString = $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) use (
+            $generalTab
+        ) {
             return $webdriver->findElement(\WebDriverBy::cssSelector($generalTab))->getAttribute('class');
         });
         $I->assertContains('has-validation-error', $classString);
diff --git a/typo3/sysext/core/Tests/Acceptance/Support/Helper/Formhandler.php b/typo3/sysext/core/Tests/Acceptance/Support/Helper/Formhandler.php
new file mode 100644 (file)
index 0000000..9ffc269
--- /dev/null
@@ -0,0 +1,99 @@
+<?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 Facebook\WebDriver\Remote\RemoteWebElement;
+
+/**
+ * Helper to interact with formhandler fields
+ */
+class Formhandler
+{
+    /**
+     * Selector to select one formengine section
+     * @var string
+     */
+    public static $selectorFormSection = '.form-section';
+
+    /**
+     * @var \AcceptanceTester
+     */
+    protected $tester;
+
+    /**
+     * @param \AcceptanceTester $I
+     */
+    public function __construct(\AcceptanceTester $I)
+    {
+        $this->tester = $I;
+    }
+
+    /**
+     * @param string $fieldName
+     * @return RemoteWebElement
+     */
+    public function getContextForFormhandlerField(string $fieldName)
+    {
+        $I = $this->tester;
+        $I->comment('Get context for field "' . $fieldName . '"');
+
+        return $I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) use ($fieldName) {
+            // TODO FIX THAT! MUST JUST BE ONE XPATH (and maybe it should work)
+            return $webdriver->findElement(\WebDriverBy::xpath('//label[contains(text(),"' . $fieldName . '")]'))->findElement(
+                \WebDriverBy::xpath('ancestor::fieldset[@class="form-section"][1]')
+            );
+        });
+    }
+
+    /**
+     * @param RemoteWebElement $fieldContext
+     * @param array $testValues An array of arrays that contains the values to validate.
+     *  * First value is the input value
+     *  * second value is the value that is expected after the validation
+     *  * optional third value is the "internal" value like required for date fields (value is internally
+     *      represented by a timestamp). If this value is not defined the second value will be used.
+     *  Example for field with alpha validation: [['foo', 'foo'], ['bar1'], ['bar']]
+     *  Example for field with date validation: [['29-01-2016', '29-01-2016', '1454025600']]
+     */
+    public function fillSeeDeleteInputField(RemoteWebElement $fieldContext, array $testValues)
+    {
+        $I = $this->tester;
+        $I->wantTo('Fill field, check the fieldvalue after evaluation and delete the value.');
+
+        $inputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@data-formengine-input-name]'));
+        $internalInputField = $fieldContext->findElement(\WebDriverBy::xpath('.//*/input[@name="' . $inputField->getAttribute('data-formengine-input-name') . '"]'));
+
+        foreach ($testValues as $comment => $testValue) {
+            if (!empty($comment)) {
+                $I->comment($comment);
+            }
+            $I->comment('Fill the field and switch focus to trigger validation.');
+            $I->fillField($inputField, $testValue[0]);
+            // change the focus to trigger validation
+            $fieldContext->sendKeys("\n");
+
+            $I->comment('Test value of "visible" field');
+            $I->canSeeInField($inputField, $testValue[1]);
+            $I->comment('Test value of the internal field');
+            $I->canSeeInField($internalInputField, (isset($testValue[2]) ? $testValue[2] : $testValue[1]));
+        }
+
+        $inputField->findElement(\WebDriverBy::xpath('parent::*/button[@class="close"]'))->click();
+        // change the context from the field
+        $fieldContext->sendKeys("\n");
+        $I->canSeeInField($inputField, '');
+        $I->canSeeInField($internalInputField, '');
+    }
+}