Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Nov 2016 at 15:57 UTC
Updated:
31 Dec 2016 at 21:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jonathan1055 commentedWe can do the same thing in 7.x to keep all test-related files under one top-level directory.
Move
scheduler.testintotests/scheduler.testand update the line in .info to sayfiles[] = tests/scheduler.test. The three files .info, .install and .module for thescheduler_testmodule should be moved down totests/modulesI have checked this and it works fine.
Edit: the 7.x changes are now on a separate issue #2837008: Move scheduler.test into /tests and move three test module into /tests/modules
Comment #3
jonathan1055 commentedIn moving to tests/src we also need to start using the
BrowserTestBaseclass becauseWebTestBasewill be discontinued as per #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase)This patch creates two files: tests/src/Functional/SchedulerBrowserTestBase.php is just a copy of SchedulerTestBase.php with three changes:
use Drupal\simpletest\WebTestBase<code> becomes <code>use Drupal\Tests\BrowserTestBaseDrupal\scheduler\TeststoDrupal\Tests\scheduler\FunctionalSchedulerTestBase extends WebTestBasebecomesSchedulerBrowserTestBase extends BrowserTestBaseThe second file tests/src/Functional/SchedulerDefaultTimeTest.php is a trial conversion of the existing defaultTime test with changes similar to above:
Drupal\scheduler\TeststoDrupal\Tests\scheduler\Functionalscheduler btbthis is a temporary change to assist testing, ultimately it will remain asschedulerextends SchedulerTestBasebecomesextends SchedulerBrowserTestBaseThere are improvements and changes we can do regarding assertion methods but currently all the existing assertions run the same as they do in SimpleTest. So the first exercise is just to move the files and use the new class.
It is not currently possible to execute cron runs in PHPunit tests due to #2795037: BTB: Add cronRun function so only a subset of our tests can be converted at this time.
Comment #5
jonathan1055 commentedFour more test files moved.
APITest and DeleteNodeTest required no changes apart from the namespace and base class as above.
FieldsDisplayTest showed up a failing in WebTestBase where
assertFieldByName()ignores the field value to check. BrowserTestBase does the check more thoroughly and hence showed up where we had previously put the wrong value in. I have also improved these checks by changing it from the 'weight' field to the 'type' field, as the weight can be shown or hidden depending on whether tabledrag is working. Using a field which is always displayed is clearer to understand and debug.MetaInformation required a minor change from using
assertHeader()to usingassertSession()->responseHeaderEquals()instead. See #2795611: Provide a assertHeader legacy assertionComment #7
jonathan1055 commentedThe FieldsDisplay test passes OK locally using run-tests.sh and using PHPunit, and also via the web UI. However, all of this was at Drupal 8.2. However, in Drupal 8.3 the field
edit-fields-scheduler-settings-typedoes not exist and is replaced byedit-fields-scheduler-settings-regionhence the test failures.The weight field is actually common to both 8.2 and 8.3 and is still used even if tabledrag is in operation. So it is safe to use that field and the tests should pass at both 8.2 and 8.3
Comment #9
jonathan1055 commentedThis patch deals with another eight test files. The only code change required (apart from use and class name) is in the permissions test, where we had the same problem as before when using
assertNoFieldByName()with a second parameter (field value). The WebTestBase version treats the empty string as "do not check the field value" but in BrowserTestBase an empty string is a valid field value, and for "do not test the value" the parameter needs to be NULL.Comment #11
jonathan1055 commentedHere's a patch for the last two tests that can be converted for now. RulesActions did not need any changes, but RulesConditions required the caches to be cleared so that the status messages were shown when the different conditions were triggered.
The remaining five tests (FunctionalTest, LightweightCronTest, NodeAccessTest, NonEnabledTypeTest and RulesEventsTest) all use
$this->cronRun()so will have to wait for #2795037: BTB: Add cronRun functionComment #13
jonathan1055 commentedI decided that it was better to get the remaining five tests converted and complete this issue, so I have added
function cronRun()to SchedulerBrowserTestBase, as a direct copy from the function in patch #31 in #2795037: BTB: Add cronRun function. When that issue lands we can remove our own version.There were two ammendments to the test code which ran OK in WTB but failed in BTB:
(string)$key_xpath[0]has to be changed to$key_xpath[0]->getText()assertFieldByName()has to be changed from empty string''toNULLComment #15
jonathan1055 commentedTo avoid confusion now that we have functional tests in the /Functional folder, I have renamed the original test file called
SchedulerFunctionalTest.phpto beSchedulerBasicTest.phpComment #17
jonathan1055 commentedAll 8.x test files have now been moved and all pass when using BrowserTestBase. Separate issues can be raised to convert the various assertions which are being removed but that will not be a problem until 9.x development starts.
The 7.x follow-up is on #2837008: Move scheduler.test into /tests and move three test module into /tests/modules