We need to convert the tests to Drupal 8 according to the instructions in Converting D7 SimpleTests to Drupal 8. The goal of this issue is to be able to run them. It's OK if they fail, we will get them green in follow-up issues.

The status of tests as at 9th March is:

Summary

Test classes: 31 total, 31 pass, 0 fail = 100%
Assertions: 508 total, 508 passes, 0 fails = 100%

Detail

  • SchedulerFunctionalTest
    59 passes, 0 fails
  • SchedulerPastDatesTest
    43 passes, 0 fails
  • SchedulerDefaultTimeTest
    44 passes, 0 fails
  • SchedulerRevisioningTest
    11 passes, 0 fails
  • SchedulerFieldsDisplayTest
    33 passes, 0 fails
  • SchedulerRequiredTest
    65 passes, 0 fails
  • SchedulerValidationTest
    20 passes, 0 fails
  • SchedulerDeleteNodeTest
    18 passes, 0 fails
  • SchedulerPermissionsTest
    22 passes, 0 fails
  • SchedulerNonEnabledTypeTest
    62 passes, 6 fails
  • SchedulerApiTest
    26 passes, 0 fails
  • SchedulerLightweightCronTest
    45 passes, 0 fails
  • SchedulerTokenReplaceTest
    40 passes, 0 fails
  • SchedulerMetaInformationTest
    20 passes, 0 fails

Comments

pfrenssen created an issue. See original summary.

  • pfrenssen committed de14fa4 on 2594615
    Issue #2594615: Move test related files to their new location.
    
  • pfrenssen committed 8a026f4 on 2594615
    Issue #2594615: Split test classes in separate files.
    
  • pfrenssen committed ed7fb8d on 2594615
    Issue #2594615: Convert ::getInfo() to annotations.
    
  • pfrenssen committed 98431bb on 2594615
    Issue #2594615: Fix syntax error.
    
pfrenssen’s picture

Assigned: Unassigned » pfrenssen
pfrenssen’s picture

Got them to show up in the Simpletest UI, but when I try to run them the test runner hangs.

jonathan1055’s picture

Hi Pieter,
You probably know this already, but it looks like we need to convert scheduler_test.info to scheduler_test.info.yml. The test log appears ok down to a point

04:31:04 cd /var/www/html && sudo -u www-data php /var/www/html/core/scripts/run-tests.sh  --url http://localhost/checkout --dburl mysql://drupaltestbot:drupaltestbotpw@drupaltestbot-db-mysql-5-5/jenkins_default_29129  --color --keep-results --color --concurrency 31 --sqlite /var/www/html/results/simpletest.sqlite --php /opt/phpenv/shims/php --directory modules/scheduler
04:31:04 Command created as exec id 1969e93f
*** all seems to match OK above here ***

04:31:04   ERROR: No valid tests were specified.
04:31:05 HTTP/1.1 200 OK
04:31:05 Content-Type: application/vnd.docker.raw-stream

I've only just now taken my first look at D8 code and testing, so please excuse me while I learn and catch up, and apologies if I say things you are already aware of.

Jonathan

jonathan1055’s picture

Now, I think I am wrong. We only need a .info.yml file if the tests are contained in a separate 'testing' module. I will keep investigating.

jonathan1055’s picture

Pieter,
Are your commits above included in the latest -dev release from 14th Oct. I started looking at the test files but it seems not all of the changes are there, for example splitting the classes into different files.

No hurry for a reply as I won't be able to work on this over the weekend.

Jonathan

jonathan1055’s picture

Ah, I see that you made the commits in #2 on 16th October but the latest 8.x dev release on our project page is 14th October. I have not been keeping up with how you are running things - is there more than one branch on 8.x and your test changes are not available for download yet?

pfrenssen’s picture

@jonathan1055 since I was working mostly alone on these issues I have been committing work in progress in feature branches. This code can be found in branch 2594615, so if you just check that out you should see it. The feature branch workflow works pretty good I found, one thing to keep in mind is to start each commit message with "Issue #123456: ..." so that the commits are included as comments in the issue.

If you prefer to post patches that perfectly fine too of course, the patch based workflow and feature branch workflow can work together.

hugronaphor’s picture

Just wanted to point to you guys that this test is blocking any other ticket as the tests are failing and the issue status is automatically changed to "Needs review" (as commits in drupal 7 are going after checking through 8.x version).
e.g: https://www.drupal.org/node/2597233

jonathan1055’s picture

Assigned: pfrenssen » jonathan1055

Thanks hugronaphor. Yes, this is now a high priority I think.
By the way, did you know that you can refer to an issue using [# 2597233] to give #2597233: The FALSE value for #group FAPI property does not have expected behaviour which shows the title and status.

Pieter, you have plenty to do, and I am just starting on the 8.x issues, so I have assigned this to me. I need to work out how to work on that branch, not the head, but that's all part of the great git learning.

jonathan1055’s picture

I've applied the patches to remove variable_set and variable_get from the new test files in branch 2594615. The test show up in the Simpletest list and they start running. However, I get a fatal error:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "node_type" entity type does not exist. in Drupal\Core\Entity\EntityManager->getDefinition() (line 261 of /Library/WebServer/Documents/drupal8/core/lib/Drupal/Core/Entity/EntityManager.php). 

The above is for SchedulerDateCombinedFunctionalTest.php in line 56, but I also get the same error in SchedulerFunctionalTest.php.

Any suggestions or ideas would be welcome. I may commit the changes I've made so far, on this branch, as they are definitely required, even though the tests don't work yet. Is that OK?

joshi.rohit100’s picture

@jonathan1055 - It seems like you are not enabling the node module, that's why this error is showing up.

jonathan1055’s picture

Thanks Joshi. Actually, it appears that I was not enabling any modules :-) I've just taken over this task from Pieter and I had not checked in detail how far he'd got on https://www.drupal.org/node/2166895 The files have been moved, split up and renamed, but the modules are no longer enabled by

  public function setUp() {
    parent::setUp('scheduler');

but it is now

  public static $modules = array('scheduler');

In D7 we did not explicitly enable the node module, but enabling 'node' in this way does remove the error. Thanks!
Attempting to enable scheduler gives errors in views.view.scheduled_content:display but atleast we are now making progress.

jonathan1055’s picture

I had managed finally to remove all the fatal errors which prevented the tests from running, and got the tests to finish! (not all passes, but that's a separate issue). It involved:

  • Repeating the $config changes from #2418527: Replace variable_set() with config
  • adding definition of $config in the various test functions and replacing variable_set
  • some $config->set calls fail with fatal error 'cannot set immutable' when using $config = \Drupal::config('scheduler.settings') but seems to be OK using $config = $this->config('scheduler.settings')
  • adding public static $modules = array('node', 'scheduler')
  • removing getInfo() and replacing the data with phpDoc-style lines
  • the files need to be unix LF, not windows CRLF, for the correct parsing of phpDoc data https://www.drupal.org/node/2301125
  • There is a fatal error processing config/install/views.view.scheduler_scheduled_content.yml so I commented out all the lines, to allow the tests to run. I will follow up this on issue #2423449: Convert the overview of scheduled nodes into a view
  • function ->randomName() no longer exists, replaced calls with ->randomString(15)
  • tidied up the @file info, which did have all three classes in each file.

I had wondered if the views problem was because I was on D8 beta-11 so decided to update to the latest rc-3. I did not know that this would require updating my PHP from 5.4 to 5.5, so that add a bit of delay. Then the issue of !message placeholders being invalid caused more trouble. At the moment I cannot run tests because the existing devel quite has ! errors, but the latest devel causes WSOD. I have never had a smooth D8 upgrade, it is always heart-bleedingly tedious with poor messages (or none) and lots of effort expended. I hope that now we are on RC3 it will be slightly more stable.

I am considering merging this work into the main 8.x so that we can see how D.O. tests cope with the changes. Many other issues will be easier to follow when we get testing running, so I do not think it need to be in a separate branch anymore, particularly as that involves re-applying patches and commits that have been done to master.

What does everyone else think about this?

pfrenssen’s picture

I'm not sure if the DrupalCI test bots already test D8 code for contrib projects at the moment.

I've been following D8 development for a while now and I have very little problems. I seem to have settled in a good workflow, I guess it just takes a bit of time to get used to it. I'm not using devel a lot lately so I'm not aware of any issues with that. I tend to do a lot of reinstalls, and I make sure that my drush is updated weekly. Also make sure you put your installation into "development mode", by commenting out the file_exists(__DIR__ . '/settings.local.php')) part in settings.php, and copying the example.settings.local.php file over.

BTW I'm really interested to see the code! Could you for the moment push your work to the 2594615 branch so I can take a look before merging it into 8.x?

jonathan1055’s picture

I've now realised I do not need to use Devel for testing (of course it is in core). I think I forgot because I saw that 'Testing' is in the 'Development' block on the main configuration page. Thanks for the hint about development mode, although I think I had many of those settings set anyway.

With my code changes so far:

  • SchedulerFunctionalTest runs (but takes a long time, 3 minutes mostly) and we have 121 passes, 89 fails, 23 exceptions, 33 debug messages.
  • SchedulerDateCombinedFunctionalTest starts but seems to get into a loop. If you refresh the 'running tests' page after a few minutes you get a link to the results, and it has attempted the tests many times over. On doing 'clean environment' you have thousands of tests and hundreds of tables cleaned up
  • SchedulerApiTestCase fails immediately because scheduler_test module does not exist (we have not converted it yet)

I wil push the work to this branch, and try to do it in several commits, so that the changes can be noted. Some will be repeats of fixes done on the master branch, but I guess we can sort that out when we come to merge the branches.

I'm not sure if the DrupalCI test bots already test D8 code for contrib projects at the moment.

I think they do, as I have seen it for other modules, but probably not for branches, only for the master. That's why it would be nice to get this branch merged in sometime soon.

jonathan1055’s picture

ArgHHHH!!! I tried to push my commits to this branch, but I think I have succeeded only in deleting the branch.
I used

git push -u origin :2594615

which is wrong (I now know) and has deleted the branch. I don't know if it had deleted it on my copy only (I hope) or the remote one aswell.

jonathan1055’s picture

I think I have deleted the remote branch, as trying to view the commit links by Pieter in #2 above give a blank. But my local files and changes are all intact, and it seems I still have branch 2594615 in my local repository. So the work is not lost. I added and committed changes to four files out of the nine, and I'm not sure where those changes have been stored. Any help would be very much appreciated in working out what to do next. Can we re-create the branch in remote repository, then I push these changes to it? (properly this time) and also re-do the changes made in #2.

  • pfrenssen committed de14fa4 on 2594615
    Issue #2594615: Move test related files to their new location.
    
  • pfrenssen committed 8a026f4 on 2594615
    Issue #2594615: Split test classes in separate files.
    
  • pfrenssen committed ed7fb8d on 2594615
    Issue #2594615: Convert ::getInfo() to annotations.
    
  • pfrenssen committed 98431bb on 2594615
    Issue #2594615: Fix syntax error.
    
  • jonathan1055 committed 11cdae1 on 2594615
    Issue #2594615 by jonathan1055: Changes to four test files for config,...
jonathan1055’s picture

Phew! Git is great. I've recovered the branch and it is showing on http://cgit.drupalcode.org/scheduler and the earlier commits have reappeared above, plus my new one. There will be a few more to follow.

pfrenssen’s picture

Well done on recovering the branch!

Am looking at the work now. Amazing that they are running. If I run them through the CLI tool (run-tests.sh) I can get a full test run without any hangs. Everything fails though, but we get good reasons why. Check the help on how to run them:

$ php ./core/scripts/run-tests.sh --help

If you run Debian or Ubuntu you can run them like this:

$ sudo -u www-data php ./core/scripts/run-tests.sh --url http://my-local-drupal-base-url --verbose scheduler

Going to hack on the branch for half an hour.

jonathan1055’s picture

Hi Pieter,
Good that they run for you now. Pleased I have finally made a contribution to 8.x development :-)

I made a couple of commits on my branch this morning, but had no internet connection (train wifi was not running). Are you ok if I push them to the remote branch? I don't want to clash with any progress you have made. They are needed to get the tests running via the actual D8 core testing interface.

I have not tried the script version yet.

  • jonathan1055 committed 00805f0 on 2594615
    Issue #2594615 by jonathan1055: Temporarily remove view to avoid fatal...
  • jonathan1055 committed 0c420c4 on 2594615
    Issue #2594615 by jonathan1055: Add langcode and use_vertical_tabs to...
  • jonathan1055 committed 7ed3369 on 2594615
    Issue #2594615 by jonathan1055: remove variable_get/set in admin form to...
  • jonathan1055 committed b32461b on 2594615
    Issue #2594615 by jonathan1055: Change invalid ! placeholder to @
    
jonathan1055’s picture

I figured the above would be ok to push, so you can see what I needed to change. If you don't like any of it, that's fine, we can modify or fix it.

I also have the same fix which is needed in #2612326: Change ! placeholders in formatted messages. When we come to merge this branch into Master branch, I presume it wont make it harder if some of the changes are already done? I need the ! change to allow the tests to be run from within the site.

I have tried your tip about running via the script, but I get syntax errors, and I think that when I initiate php via the command line I am getting php 5.4 not 5.5 which my site is using. I'm not sure how to get them aligned.

pfrenssen’s picture

I wanted to work on this yesterday during my lunch break but I didn't get around to it. So don't hesitate to pick this up if 30 minutes have passed, since my lunch break will be over and I will be doing my day job again :)

Going to have a look at the changes now.

joshi.rohit100’s picture

It seems like that this issue is kind of blocker with very high priority. It also seems like that tests are now running but failing. So only needs to fix the failing tests. So i think it will be great if we go for this issue same as we go for others (mean patches) so that we have more eyes. It is because most of the time when people thinking to review something, they don't like cloning repo and then see the code.

  • pfrenssen committed 24def61 on 2594615
    Issue #2594615: In most tests the module's machine name is used for the...
  • pfrenssen committed 279f5a6 on 2594615
    Issue #2594615: The langcode parameter is now required in config, but it...
  • pfrenssen committed 36ab331 on 2594615
    Issue #2594615: The getInfo() method is no longer needed in Drupal 8....
  • pfrenssen committed 4cc8165 on 2594615
    Issue #2594615: The 'use_vertical_tabs' parameter is legitimate.
    
  • pfrenssen committed 7ba6902 on 2594615
    Issue #2594615: Fix coding standards.
    
pfrenssen’s picture

@joshi.rohit100, this is at the moment the most important issue for me. If we can get the tests working then we can prove that the base functionality of Scheduler works and we can make an alpha release. I also keep an eye on the other issues but they seem to be progressing really well. All of the important issues are currently being worked on.

I had a look at the tests. Made some minor adjustments (coding standards + capitalization of the test group). I looked into the mystery of the langcode being required suddenly. The root of this failure lies in SchemaCheckTrait::checkConfigSchema(). It adds the 'langcode' parameter to every config object before checking it. This causes the following failure:

Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for scheduler.settings with the following errors: scheduler.settings:langcode missing schema in Drupal\Core\Config\Testing\ConfigSchemaChecker->onConfigSave() (line 98 of core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php).

I dug a bit deeper and the langcode is actually required, regardless whether or not the config is actually language dependent. For more information see this change record: New config_object base type added, use for simple configuration.

@jonathan1055, I'm done working on it, it's all yours :D

jonathan1055’s picture

Great work Pieter, and thanks for the explanations.
I think what joshi.rohit100 was implying was that if this branch was merged back into the master branch, then (a) we could all see the current state of the tests without using the branch (b) we could see the results on D.O. (c) more eyes would be able to contribute to fixing the tests.

I have only just learned about branching and stashing and I find it very easy to work with, and quite like it. However, for this most important issue we are starting to get duplicates fixes e.g. #2418527: Replace variable_set() with config #2418523: Replace variable_get() with config and #2612326: Change ! placeholders in formatted messages which have to be fixed in both branches. I'm OK with doing that, but if others would see benefit in merging this branch in now, than that's ok too.

What do you think?

  • jonathan1055 committed 206662a on 2594615
    Issue #2594615 by jonathan1055: Fix ! placeholders in testing branch
    
  • jonathan1055 committed 34d3e7b on 2594615
    Issue #2594615 by jonathan1055: randomString in date test
    
pfrenssen’s picture

OK Jonathan, I agree. We can safely merge this, except for the removal of the Views config. I will rebase the branch to remove the commit that commented out the view now. This will cause all commits to reappear underneath this comment.

pfrenssen’s picture

@jonathan1055 it seems like you are still working on this. When you are done, please assign it to me so I can rebase and merge without interfering with your work.

jonathan1055’s picture

I am done now, just did those two small commits, and wanted to say I'd finished, but the train wifi stopped working again. Yes, OK you can reverse the view, and then we can work out why it causes the fatal error. Just for the record, here are the results so far:

SchedulerFunctionalTest

Back at #23 we had:

100 passes, 19 fails, 64 exceptions, 17 debug messages

Now that form posting is fixed we have many more attempts, and hence more fails:

121 passes, 89 fails, 16 exceptions, 33 debug messages

but when I run via the run-tests.script I get slightly different numbers - two passes are now fails and there is a huge increase in exceptions:

119 passes  91 fails 1091 exceptions

SchedulerApiTestCase

Because the module .info is not yet converted to .yml the tests do not get started:

0 passes, 2 fails, 1 exception via site
0 passes, 1 fails, 1 exceptions via script

SchedulerDateCombinedFunctionalTest

19 passes, 7 fails, 19 exceptions, 2 debug messages via site
19 passes, 7 fails, 232 exceptions via script

The full test run takes 4+ minutes which seems slower than expected, compared to D7.

jonathan1055’s picture

Assigned: jonathan1055 » pfrenssen

Reassigned as requested.
I have found some more places that need simple changes for D8 syntax, and these mean more tests run and we get more passes. I don't have the precise code details with me at the moment but from memory:

  • In the date tests several drupalPost() calls now need to be drupalPostForm()
  • When calling the admin config form, the keys of the settings parameters array should not have 'scheduler_' at the start. This removes the 'cannot find field' errors
  • The node/add form 'save' button is not working because the text has changed. It is now a selection, and the text of the default choice is 'save and publish'

I suggest we wait until you have done the rebasing and merging, before making any more patches/commits.

pfrenssen’s picture

OK going to do the rebase and merge now. This will make all commits reappear below this comment, that is normal, drupal.org interprets these as new commits.

After merging I'll work on it during my lunch break. Will reassign when I'm done.

@jonathan1055, if you are working on a particular test and want quick feedback, then a good trick is to rename the tests you're not working on. Only test methods that start with 'test...' will actually be executed. I always rename all others to '_test...' so they are skipped by the test runner.

  • pfrenssen committed 0f2404f on 8.x-1.x
    Issue #2594615: Fix coding standards.
    
  • pfrenssen committed 185ec6d on 8.x-1.x
    Issue #2594615: The 'use_vertical_tabs' parameter is legitimate.
    
  • pfrenssen committed 36dea28 on 8.x-1.x
    Issue #2594615: Convert ::getInfo() to annotations.
    
  • pfrenssen committed 51068ab on 8.x-1.x authored by jonathan1055
    Issue #2594615 by jonathan1055: Add langcode and use_vertical_tabs to...
  • pfrenssen committed 58b835e on 8.x-1.x
    Issue #2594615: Move test related files to their new location.
    
  • pfrenssen committed 626b1c4 on 8.x-1.x
    Issue #2594615: Fix syntax error.
    
  • pfrenssen committed 9d71ab0 on 8.x-1.x authored by jonathan1055
    Issue #2594615 by jonathan1055: randomString in date test
    
  • pfrenssen committed bf81ce8 on 8.x-1.x
    Issue #2594615: The langcode parameter is now required in config, but it...
  • pfrenssen committed c847f3b on 8.x-1.x authored by jonathan1055
    Issue #2594615 by jonathan1055: Change invalid ! placeholder to @
    
  • pfrenssen committed deba452 on 8.x-1.x
    Issue #2594615: Split test classes in separate files.
    
  • pfrenssen committed e50f162 on 8.x-1.x authored by jonathan1055
    Issue #2594615 by jonathan1055: Fix ! placeholders in testing branch
    
  • pfrenssen committed e9e8787 on 8.x-1.x
    Issue #2594615: In most tests the module's machine name is used for the...
  • pfrenssen committed f831cce on 8.x-1.x
    Issue #2594615: The getInfo() method is no longer needed in Drupal 8....
  • pfrenssen committed f9da27a on 8.x-1.x authored by jonathan1055
    Issue #2594615 by jonathan1055: Changes to four test files for config,...

  • pfrenssen committed 58b835e on 2594615
    Issue #2594615: Move test related files to their new location.
    
  • pfrenssen committed deba452 on 2594615
    Issue #2594615: Split test classes in separate files.
    
  • pfrenssen committed 36dea28 on 2594615
    Issue #2594615: Convert ::getInfo() to annotations.
    
  • pfrenssen committed 626b1c4 on 2594615
    Issue #2594615: Fix syntax error.
    
  • pfrenssen committed f9da27a on 2594615 authored by jonathan1055
    Issue #2594615 by jonathan1055: Changes to four test files for config,...
  • pfrenssen committed 51068ab on 2594615 authored by jonathan1055
    Issue #2594615 by jonathan1055: Add langcode and use_vertical_tabs to...
  • pfrenssen committed c847f3b on 2594615 authored by jonathan1055
    Issue #2594615 by jonathan1055: Change invalid ! placeholder to @
    
  • pfrenssen committed 185ec6d on 2594615
    Issue #2594615: The 'use_vertical_tabs' parameter is legitimate.
    
  • pfrenssen committed e9e8787 on 2594615
    Issue #2594615: In most tests the module's machine name is used for the...
  • pfrenssen committed 0f2404f on 2594615
    Issue #2594615: Fix coding standards.
    
  • pfrenssen committed f831cce on 2594615
    Issue #2594615: The getInfo() method is no longer needed in Drupal 8....
  • pfrenssen committed bf81ce8 on 2594615
    Issue #2594615: The langcode parameter is now required in config, but it...
  • pfrenssen committed e50f162 on 2594615 authored by jonathan1055
    Issue #2594615 by jonathan1055: Fix ! placeholders in testing branch
    
  • pfrenssen committed 9d71ab0 on 2594615 authored by jonathan1055
    Issue #2594615 by jonathan1055: randomString in date test
    

  • pfrenssen committed 5b385c7 on 2594615
    Issue #2594615: drupalPost() is now drupalPostForm().
    
  • pfrenssen committed 70296c3 on 2594615
    Issue #2594615: The language code is no longer used in field names.
    
  • pfrenssen committed 7ef99f2 on 2594615
    Issue #2594615: Update form data to how it now looks in Drupal 8.
    
pfrenssen’s picture

Assigned: pfrenssen » jonathan1055

Worked a bit on SchedulerFunctionalTest::testScheduler(). The test gets past the first form submission now, but the node doesn't seem to get published after cron is run. That might be quite a critical bug if this is true :)

@jonathan1055, since I have rebase the branch you might get some warnings from git that the upstream has changed. The easiest way to be 100% sure that you have the latest code exactly like it is on the git server is to do a hard reset of your branch:

$ git reset --hard origin/2594615
jonathan1055’s picture

This is starting to look good. We now get tests running on D.O. (even though there are many failures).

Did you intend to make your three new commits to the branch? I thought that after you had merged we would be dropping the branch and then continue making the next changes directly in master, so that everyone gets the improvements immediately. Or maybe you had an alternative plan?

I can progress my next fixes locally anyway, and they can be applied later depending on your response to the above.

pfrenssen’s picture

We're not done converting the tests, so I figured to just continue here until we're done :)

Making changes directly on master is not really advisable, if we accidentally break something then it will directly affect people that are downloading the latest dev version.

jonathan1055’s picture

OK. that's fine. I will push a few more commits to this branch - I am finding lots of things to fix, and the failure numbers are coming down :-)

jonathan1055’s picture

One the fails is

    // Verify that the scheduler table is not empty.
    $this->assertTrue(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is not empty');

The scheduler table does not exist in D8. Should we go to the node_field_data table instead? Then check for any publish_on values, or specifically for a value for the node just created. Is that worth a test? It's kind of double checking that the core field functionality has worked, but I'm ok with doing that, providing it will give a consistent useful result.

pfrenssen’s picture

I don't think it is strictly necessary to test the entity storage. Before when we were maintaining our own tables it made sense to test this, but entity storage is already tested adequately in core :)

  • jonathan1055 committed 1baefee on 2594615 authored by joekers
    Issue #2594615 by joekers, jazio.net: Replace variable_get() with config
    
jonathan1055’s picture

The commit in #46 matches the main branch commit in #2418523: Replace variable_get() with config #30 which is needed for the tests to run.

  • jonathan1055 committed f6a4db3 on 2594615
    Issue #2594615 by jonathan1055: Fix typo in config-get() patch
    

  • jonathan1055 committed 3def715 on 2594615 authored by joekers
    Issue #2594615 by joekers, jonathan1055: Use ->value for $node->...
jonathan1055’s picture

Commit in #49 matches #2621122: Use ->value for $node->unpublish_on which is vital for the tests to run without fatal errors.

  • jonathan1055 committed d24274d on 2594615
    Issue #2594615 by jonathan1055: Removed all fatal errors in...
jonathan1055’s picture

I've been working on SchedulerFunctionalTest.php and schedulerTestBase.php, and have now got all the tests to run without any fatal errors. The breakdown of results at the moment is:

  1. testScheduler() 42 passes, 5 fails, 9 exceptions
  2. testSchedulerPastDates() 30 passes, 2 fails, 1 exception
  3. testRevisioning() 7 passes, 4 fails, 0 exceptions
  4. testExtraFields() 18 passes, 3 fails, 1 exception
  5. testRequiredScheduling() 53 passes, 7 fails, 1 exception
  6. testValidationDuringEdit() 14 passes, 1 fail, 1 exception
  7. testScheduledNodeDelete() 16 passes, 4 fails, 1 exception
  8. testScheduledNodeDelete() 16 passes, 0 fails, 1 exception

Overall 180 passes (up from 121 from last update), 22 fails (down from 89)
Total of 202 tests and 14 exceptions

Quick summary of changes to schedulerTestBase.php

  • Fixed D8 date array keys
  • removed select of scheduler table
  • changed update to use node_field_data
  • change node_revision field from log to revision_log

Changes to SchedulerFunctionalTest.php

  • use Drupal\node\Entity\NodeType
  • change lots of incorrect config->set to setThirdPartySetting
  • Randomstring instead of fixed title text
  • change many publish_on and unpublish_on to use new split date and time values
  • Change 'save' key in edit form to 'save and publish', 'save and keep published' etc.

I have pushed the two changed files to this branch. The code includes several @TODO with questions, remarks and debug messages on the parts which still need attention.

  • jonathan1055 committed db8120e on 2594615
    Issue #2594615 by jonathan1055: Change randomString to randomMachineName...
jonathan1055’s picture

One of the problems hindering progress is the default timezone warning which also stops some of the pages being rendered. The warning was

Exception: DateTime::__construct():
It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspeled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in DateTime->__construct()
(line 215 of core/lib/Drupal/Core/Datetime/DateFormatter.php). 

Using date_default_timezone_set() did not remove the message, so I have now added a date.timezone setting to my php.ini file. This removed the warnings and allows the pages to be rendered properly.

Then the assertText checks had a chance of matching and I could see that the nodes were published and unpublished correctly but the randomString text used for detection was causing the jQuery not to match. Changing this to the more simpler randomMachineName() allowed the text to be found. We now have a full set of passes in the first test testScheduler() which is the first time we get all green.

Overall we now have results of
185 passes, 17 fails, 0 exceptions

  • jonathan1055 committed cc6a64d on 2594615
    Issue #2594615 by jonathan1055: Added new testNonEnabledNodeType() as...
jonathan1055’s picture

Added tests to cover #2625572: Admin setting 'Enable content type for scheduler' is ignored

Overall for SchedulerFunctionalTest.php we now have:

total 214 passes, 24 fails, 0 exceptions
pfrenssen’s picture

Assigned: jonathan1055 » pfrenssen

Going to work on the tests during my lunch break.

jonathan1055’s picture

OK. I've been doing some investigation into testRevisioning and am part way through, so maybe if you want to start on any of the others, but not that one. I wouldn't want you to use your time repeating what I've done. I have not made any changes to any other tests since the push at #55.

  • pfrenssen committed 0074cf5 on 2594615
    Issue #2594615: Use shorthand array syntax.
    
  • pfrenssen committed 42ffc3c on 2594615
    Issue #2594615: Update documentation.
    
  • pfrenssen committed cbdd050 on 2594615
    Issue #2594615: The node storage is actually retrieved from...
  • pfrenssen committed cd809ff on 2594615
    Issue #2594615: Add hints to assist IDEs in recognizing the variable...
  • pfrenssen committed e5d6a1e on 2594615
    Issue #2594615: Replace deprecated format_date() with...
  • pfrenssen committed ea026d4 on 2594615
    Issue #2594615: Add some TODOs to clean up unused variables.
    
pfrenssen’s picture

Have worked a bit on testSchedulerPastDates(). The test is correctly failing, the functionality is not there yet. From a quick scan of the issue queue it seems like we need #2490574: Validate that the publication date is in the future to fix this.

I did some test-wide cleanups and improvements.

pfrenssen’s picture

Assigned: pfrenssen » jonathan1055

Assigning back to Jonathan to continue his amazing work :)

jonathan1055’s picture

Hey, I consider that you are doing all the clever work!

Thanks for the pushes. I was going to update this issue summary with the current state of tests and link to the separate issues that will fix them. Although in my work in testRevisioning it seems like it might be the fault of the test files not the main functions. I think I may need your expert assistance on object-oriented code and namespaces, entities, etc. I'll get some details up here tomorrow.

  • jonathan1055 committed 138da83 on 2594615
    Issue #2594615 by jonathan1055: change scheduler_test.info to .yml
    
jonathan1055’s picture

Basic conversion of scheduler_test module .info to .info.yml
Just wanted to get this change out of the way, but I am not working on those tests yet.

  • jonathan1055 committed 37c6542 on 2594615
    Issue #2594615 by jonathan1055: Remove unnecessary field from db_select...
  • jonathan1055 committed 56ca486 on 2594615
    Issue #2594615 by jonathan1055: Add node_type->save() for third party,...
  • jonathan1055 committed 5d63f34 on 2594615
    Issue #2594615 by jonathan1055: Change to node.type.* add labels to main...
jonathan1055’s picture

When working on testRevisioning I realised that revisions during cron work ok for real, but not in the tests.
Within testRevisioning() we have:

    // Enable revisioning.
    $entity = $node->type->entity;
    $entity->setThirdPartySetting('scheduler', 'publish_revision', TRUE);
    $entity->setThirdPartySetting('scheduler', 'unpublish_revision', TRUE);

and this works OK, at least within this function. The value is set to TRUE if retrieved immediately here. But in _scheduler_publish() the retreived config value for 'publish_revision' is FALSE. If the value is forced to TRUE then a revision is created during the tests, so that part is working correctly. It is just the setting and retrieval of the thirdPartySetting which is not working. In fact none of the third party settings that are applied in the test files are available in the main functions. The values applied in setUp were not even available in the test cases

$entity in testRevisioning():
Drupal\node\Entity\NodeType Object
(
    [type:protected] => page
    [name:protected] => Basic page
    [description:protected] => 
    [help:protected] => 
    [new_revision:protected] => 
    [preview_mode:protected] => 1
    [display_submitted:protected] => 1
    [originalId:protected] => page
    [pluginConfigKey:protected] => 
    [status:protected] => 1
    [uuid:protected] => f16a3398-6fd5-481f-8a09-9c5d0f697806
    [isSyncing:Drupal\Core\Config\Entity\ConfigEntityBase:private] => 
    [isUninstalling:Drupal\Core\Config\Entity\ConfigEntityBase:private] => 
    [langcode:protected] => en
    [third_party_settings:protected] => Array
        (
            [scheduler] => Array
                (
                    [publish_revision] => 1
                    [unpublish_revision] => 1
                )

        )

    [trustedData:protected] => 
    [entityTypeId:protected] => node_type
    [enforceIsNew:protected] => 

The array for [third_party_settings:protected] should have more here. Then I discovered it is not sufficient just to call ->setThirdPartySetting, you also need ->save() for the values to be stored permanently. After I added the ->save() it produced lots of schema errors in the tests, which halt the test run:

Drupal\Core\Config\Schema\SchemaIncompleteException:
Schema errors for node.type.page with the following errors:
  node.type.page:third_party_settings.scheduler.publish_revision missing schema,
in Drupal\Core\Config\Testing\ConfigSchemaChecker->onConfigSave()
(line 98 of /Library/WebServer/Documents/drupal8/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php).

I tried several variations within scheduler.schema.yml and eventually discovered that instead of
node_type.third_party.scheduler:
it should be
node.type.*.third_party.scheduler:

I found that the config inspector module is extremely helpful https://www.drupal.org/project/config_inspector

Summary of changes in the three commits above:

SchedulerFunctionalTest.php

added node_type->save() or equivalent, in 10 places.
fixed one button text 'save and keep published'
added positive text assertion as well as negative assertion in testScheduledNodeDelete()
tidied up some of my comments and debug

scheduler.schema.yml

changed to node.type.*.third_party.scheduler
added labels for all Scheduler main settings
added missing 'expand_fieldset' content-type setting

SchedulerTestBase.php

Remove debug
Remove unnecessary field from db_select
No material differences.

We should test the schema changes in the main branch and get that change applied there too. It seems that previously the settings were being stored from the content type form, even though the schema was not structured correctly. The testing checks the schema whereas using the real site does not.

Total 221 passes, 19 fails, 0 exceptions

All of the above gave us 5 more passes! (plus 2 new tests which pass). Yes, only 5 were fixed (4 in revisioning and 1 in pastDates) but it means that the settings are now being stored and made available in the real code, and without that we'd have no hope of correcting the remaining tests. I may change the summary of this issue to give a list of the tests status and links to the issues where the code can be corrected.

jonathan1055’s picture

StatusFileSize
new1.25 KB

Here's the patch from the schema.yml changes if anyone would like to apply it and do further testing. The content-type specific settings seem to be working fine. If you use the Config Inspector module, you will probably see duplicate items, but after a clear cache and resave of the settings it seems to get sorted out. I noticed a problem with the content-type form (before this change) where the boolean values of TRUE get the correct radio button lit and showing, but if the stored setting is FALSE we get neither radio button lit. This needs a separate issue though.

For now we just need to check that my schema changes are OK. Certainly they are fine with all the automated tests so far, but I am aware that we need to do real testing too.

  • jonathan1055 committed 1b35437 on 2594615
    Issue #2594615 by jonathan1055: Fix TestExtraFields xpath (all pass now)
    
jonathan1055’s picture

Issue summary: View changes

#68 fixes testExtraFields() and this test is all green now. Needed slight changes to the xpath values, as classes and ids are different. Also the class 'collapsed' is no longer used, but a new value 'open' is present.

Out of the eight test classes we have four which fully pass.

  • jonathan1055 committed 965b752 on 2594615
    Issue #2594615 by jonathan1055: Fix testRequiredScheduling (all now pass...
jonathan1055’s picture

Issue summary: View changes

I have fixed testRequiredScheduling(), which involved (a) correcting the array key names to get the intended values into nodes before testing the editing, (b) changing the value of publish_on to a timestamp number not formatted text, and (c) a change to the text of the validation message to check for. The rest of the changes are with debug calls.

All of the 60 tests in the class now pass. However there is still work to do because I do not know how to change the default status of a content type before the /node/add/page is called. This affects tests 1/2 and 6/7 so currently 1 & 2 are testing the same situation, as are 6 & 7. I've searched the API pages but so far have not found out how to set the default status before a node is added. I've added an assert(FALSE) which displays a TODO message to make sure we do not forget and let this go by unfixed.

  • jonathan1055 committed b6da257 on 2594615
    Issue #2594615 by jonathan1055: Date tests - syntax, thirdPartySetting,...
jonathan1055’s picture

Issue summary: View changes

As the main SchedulerFunctionalTest is progressing nicely I thought I would do some work on SchedulerDateCombinedFunctionalTest.php. Here is a summary of the changes in #72:

  • use Drupal\node\Entity\NodeType
  • change to use setThirdPartySetting()
  • use shorthand array notation to match Pieter's changes
  • $this->drupalPost to $this->drupalPostForm
  • $edit array key names
  • form button text

Previously: 19 passes, 7 fails, 19 exceptions
Now: 37 passes, 6 fails and 0 exceptions

  • jonathan1055 committed cf53f69 on 2594615 authored by joekers
    Issue #2594615 by joekers, jonathan1055: Validate that unpublish date is...
jonathan1055’s picture

Issue summary: View changes

The commit in #74 repliactes the commit in #2490584: Validate that unpublish date is entered if publish date is entered
This fixes the one failing test in testValidationDuringEdit. Thanks Joekers.

jonathan1055’s picture

Issue summary: View changes
pfrenssen’s picture

Assigned: jonathan1055 » pfrenssen

Going to work on this branch for a bit. I made some changes to files outside of the tests when I converted some deprecated functions to the new D8 counterparts. These are potentially conflicting with patches that are in the queue. I will see if there are any merge conflicts with the 8.x-1.x branch and solve them, so we can merge back the progress that has been made here to the main branch. We can then continue the work here.

I'll make sure to create separate issues whenever a change needs to be made to non-test code, so that these branches won't interfere with eachother.

pfrenssen’s picture

Assigned: pfrenssen » jonathan1055

The merge went without problems. This is ready to be merged back to 8.x-1.x if @jonathan1055 agrees to do this.

I also reviewed the last commits by Jonathan, they all look good. I only saw a few small typos and a leftover debug statement. We can clean this up in a final stage once everything is green.

+    ### @TODO the string 'page' is hard-coded eleven times in this file (so far)
+    ### @TODO Could make it a variable, which would allow future testing of other entity types?

Let's make this a property on the base class, that's the cleanest solution. So we can address the bundle as $this->testBundle and we can simply instantiate it like this:

  /**
   * Node bundle to use in tests.
   *
   * @var string $testBundle
   */
  protected $testBundle = 'page';

I personally don't think we need to test if Scheduling works on multiple entity types, we should trust in the API's provided for entities and fields in core. I'm pretty sure this is already tested in core :)

+    $edit = [
+      'publish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', REQUEST_TIME)), ### @TODO should we get the default format? not hard-code.
+      'publish_on[0][value][time]' => date('H:i:s', strtotime('+1 day', REQUEST_TIME)),
+    ];

I personally prefer to use hard coded values in tests, since this will make it 100% certain that the test will fail. Imagine that some bug causes the default format to become empty, or "0", or defaulting to the wrong timezone, and then the test will not detect it because it will pass through the wrong data and everything will appear fine. Hard coding avoids this.

+    ### @TODO Delete was a button in 7.x but a separate link node//delete in 8.x
+    ### Is the previous validation (that we had to avoid on delete) still done now in D8, given that there is no form?

The confirmation form with the delete button still exists, it will be behind the link. This is done to be compliant with usability guidelines. So we need to click on the link to get the form.

+    ### Maybe this test is not actually checking anything useful? Can it be altered to do something testable?
+    $this->drupalGet('node/' . $published_node->id() . '/delete');
+    // Note that the text 'error message' is used in a header h2 html tag which
+    // is normally made hidden from browsers but will be in the page source.
+    // It is also good when testing for the absense of somthing to also test
+    // for the presence of text, hence the second assertion for each check.

There is indeed a better way to test this in Drupal 8. In Drupal 7 validation handlers only run on form submission, but in Drupal 8 they should run always when an entity is created or updated. So we can test this a lot smarter in D8. We can create a KernelTest (or hopefully even a unit test) with a dataprovider that provides a whole array of combinations of incorrect as well as correct data, and then check whether the validation handlers fire correctly. Let's keep this out of scope for this issue though. I'll create a new issue for this. Once we have this we can remove these unreliable "error message is absent" tests.

+    // Create an administrator user.
+    ### @TODO There should be a way to add the new permissions to the existing
+    ### adminUser instead of creating a new user?
+    $this->adminUser2 = $this->drupalCreateUser([
+      // ...
+    ]);

Yeah, just take this out of the SchedulerFunctionalTestCase and put it in a separate class. You can then provide your own ::setUp() method that creates the $this->adminUser with the correct permissions.

pfrenssen’s picture

I tried several variations within scheduler.schema.yml and eventually discovered that instead of
node_type.third_party.scheduler:
it should be
node.type.*.third_party.scheduler:

Very good find!!

jonathan1055’s picture

The merge went without problems. This is ready to be merged back to 8.x-1.x if @jonathan1055 agrees to do this.

That's good news. I thought it would be a good time to try this, as at the moment it is clean. I had to adjust the last commit from the master branch to get it in to this branch, and there are plenty more waiting. Yes it will be good to merge it all back. I've not actually done a full branch merge, and I will not be able to make any changes for another 5 hours. So if you want to do this now, please go ahead. If you do, let me know what git commands you use, and I will do the next one. Or let me know what commands you used last time, and will do this merge tonight.

Thanks for all the great feedback and ideas in #78. I agree with all you've said. Now that you have checked, lets merge before we implement any of these tidy-ups and enhancements. Then I will address those points back on this branch after the merge.

pfrenssen’s picture

I'll do the merge now. The command sequence for this, starting from the 2594615 branch is very easy:

$ git checkout 8.x-1.x
$ git merge 2594615
$ git push
$ git checkout -

The last line is to switch back to the 2594615 branch, the '-' indicates the 'previous branch'.

  • pfrenssen committed 0074cf5 on 8.x-1.x
    Issue #2594615: Use shorthand array syntax.
    
  • jonathan1055 committed 138da83 on 8.x-1.x
    Issue #2594615 by jonathan1055: change scheduler_test.info to .yml
    
  • jonathan1055 committed 1b35437 on 8.x-1.x
    Issue #2594615 by jonathan1055: Fix TestExtraFields xpath (all pass now)
    
  • jonathan1055 committed 1baefee on 8.x-1.x authored by joekers
    Issue #2594615 by joekers, jazio.net: Replace variable_get() with config
    
  • jonathan1055 committed 37c6542 on 8.x-1.x
    Issue #2594615 by jonathan1055: Remove unnecessary field from db_select...
  • jonathan1055 committed 3def715 on 8.x-1.x authored by joekers
    Issue #2594615 by joekers, jonathan1055: Use ->value for $node->...
  • pfrenssen committed 42ffc3c on 8.x-1.x
    Issue #2594615: Update documentation.
    
  • jonathan1055 committed 56ca486 on 8.x-1.x
    Issue #2594615 by jonathan1055: Add node_type->save() for third party,...
  • pfrenssen committed 5b385c7 on 8.x-1.x
    Issue #2594615: drupalPost() is now drupalPostForm().
    
  • jonathan1055 committed 5d63f34 on 8.x-1.x
    Issue #2594615 by jonathan1055: Change to node.type.* add labels to main...
  • pfrenssen committed 70296c3 on 8.x-1.x
    Issue #2594615: The language code is no longer used in field names.
    
  • pfrenssen committed 7ef99f2 on 8.x-1.x
    Issue #2594615: Update form data to how it now looks in Drupal 8.
    
  • jonathan1055 committed 965b752 on 8.x-1.x
    Issue #2594615 by jonathan1055: Fix testRequiredScheduling (all now pass...
  • jonathan1055 committed b6da257 on 8.x-1.x
    Issue #2594615 by jonathan1055: Date tests - syntax, thirdPartySetting,...
  • pfrenssen committed cbdd050 on 8.x-1.x
    Issue #2594615: The node storage is actually retrieved from...
  • jonathan1055 committed cc6a64d on 8.x-1.x
    Issue #2594615 by jonathan1055: Added new testNonEnabledNodeType() as...
  • pfrenssen committed cd809ff on 8.x-1.x
    Issue #2594615: Add hints to assist IDEs in recognizing the variable...
  • jonathan1055 committed cf53f69 on 8.x-1.x authored by joekers
    Issue #2594615 by joekers, jonathan1055: Validate that unpublish date is...
  • jonathan1055 committed d24274d on 8.x-1.x
    Issue #2594615 by jonathan1055: Removed all fatal errors in...
  • jonathan1055 committed db8120e on 8.x-1.x
    Issue #2594615 by jonathan1055: Change randomString to randomMachineName...
  • pfrenssen committed e5d6a1e on 8.x-1.x
    Issue #2594615: Replace deprecated format_date() with...
  • pfrenssen committed ea026d4 on 8.x-1.x
    Issue #2594615: Add some TODOs to clean up unused variables.
    
  • jonathan1055 committed f6a4db3 on 8.x-1.x
    Issue #2594615 by jonathan1055: Fix typo in config-get() patch
    
pfrenssen’s picture

Merge is done and pushed.

jonathan1055’s picture

Excellent. Thanks for doing that. Thanks also for the git commands, I will try the next one.

  • jonathan1055 committed 01fa5fb on 2594615
    Issue #2594615 by jonathan1055: Avoid crash in helpTestScheduler if node...
jonathan1055’s picture

Added the check on $node in helpTestScheduler to avoid a fatal error which stops the tests running. in #2490574: Validate that the publication date is in the future see comment #22 for details.

  • jonathan1055 committed dbe57e7 on 2594615
    Issue #2594615 by jonathan1055: Added test for unpublish date in the...

  • jonathan1055 committed 1b0465b on
    Issue #2594615: by jonathan1055: Expanded testValidationDuringEdit to...

  • jonathan1055 committed 2d9afb5 on 2594615
    Issue #2594615: by jonathan1055: Remove debug from test
    

  • jonathan1055 committed 01fa5fb on 8.x-1.x
    Issue #2594615 by jonathan1055: Avoid crash in helpTestScheduler if node...
  • jonathan1055 committed 1b0465b on 8.x-1.x
    Issue #2594615: by jonathan1055: Expanded testValidationDuringEdit to...
  • jonathan1055 committed 2d9afb5 on 8.x-1.x
    Issue #2594615: by jonathan1055: Remove debug from test
    
  • jonathan1055 committed dbe57e7 on 8.x-1.x
    Issue #2594615 by jonathan1055: Added test for unpublish date in the...
jonathan1055’s picture

Issue summary: View changes

Update test results after adding the two new tests.
Added links to the corresponding issues.

  • jonathan1055 committed d4ce663 on 2594615
    Issue #2594615: by jonathan1055: Correct timezone error by logging in...

  • jonathan1055 committed d4ce663 on 8.x-1.x
    Issue #2594615: by jonathan1055: Correct timezone error by logging in...
jonathan1055’s picture

  • jonathan1055 committed 5fe414f on 2594615
    Issue #2594615 by jonathan1055, joekers: (test branch) Validate that the...
jonathan1055’s picture

Issue summary: View changes

In #95 commited constraints from #2490576: Validate that the unpublish date is in the future to the testing branch, to keep things in line and allow the use of this branch when doing further work on tests. Updated the summary with new totals.

  • jonathan1055 committed d1e5751 on 2594615
    Issue #2594615: by jonathan1055: Merge recent validation patches into...
jonathan1055’s picture

Issue summary: View changes
jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new4.34 KB

I've been working on the problem of setting the default node status, which is needed in testRequiredScheduling. With the help of examples in core node/src/Tests/NodeFormButtonsTest.php it is now done. When checking the verbose page output you can tell the default node status has been changed because the default button text changes.

I am attaching the patch here, but I think the tests will actually run against 8.x-1.x master. At this time it is fine because the test branch does not have anything extra.

Status: Needs review » Needs work

The last submitted patch, 99: 2594615-99-set-default-node-status.patch, failed testing.

jonathan1055’s picture

Things are getting better.
✓ - testRequiredScheduling
Overall 253 passes and 7 fails.
11 class passes and 5 fails.

  • jonathan1055 committed be22603 on 2594615
    Issue #2594615: by jonathan1055: Set default node status to fix...

  • jonathan1055 committed 5fe414f on 8.x-1.x
    Issue #2594615 by jonathan1055, joekers: (test branch) Validate that the...
  • jonathan1055 committed be22603 on 8.x-1.x
    Issue #2594615: by jonathan1055: Set default node status to fix...
  • jonathan1055 committed d1e5751 on 8.x-1.x
    Issue #2594615: by jonathan1055: Merge recent validation patches into...
jonathan1055’s picture

Issue summary: View changes

The commit in 102 fixes the problem from #71 above.
Merged into master branch too.

pfrenssen’s picture

Assigned: jonathan1055 » pfrenssen
  public function testNonEnabledNodeType() {
    // ...

    // Create an administrator user.
    ### @TODO There should be a way to add the new permissions to the existing
    ### adminUser instead of creating a new user?
    $this->adminUser2 = $this->drupalCreateUser([

I think in this case it would be better to put the test in a separate class. We are not using the node type nor the user that are created in the setup.

Assigning to me, feeling like working on this for a bit this evening :)

jonathan1055’s picture

Yes, OK. I agree about the class change.
But I have actually been working on testNonEnabledNodeType() this evening too. [just got back to Drupal after being away over the holidays]. That is the only test which fails in that file, and the test needs a slight change in conjunction with the possible fix in scheduler_form_node_form_alter. Yes, please make the class change, but I don't want you to waste your time duplicating the fixes to the actual assertions that I have got in the pipeline.
Or if you'd like to start on the API tests (I think you wrote them in the first place in 7.x) that would be great too.

jonathan1055’s picture

or I can just post here the changes to the actual assertions and you can incorporate them when you make the class changes, that would be fine too.

pfrenssen’s picture

Assigned: pfrenssen » jonathan1055

No go ahead, I'll leave you to that. I hadn't yet started working on the test. I will instead work on getting #2597233: The FALSE value for #group FAPI property does not have expected behaviour in so we can see it turn green.

See also my comment #2625572-6: Admin setting 'Enable content type for scheduler' is ignored, the second part of the test now fails because the publishing fields are missing.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new13.21 KB

I have moved the tests for non-enabled content type to a new class, as you suggested, in SchedulerNonEnabledTypeTest.php. The fix in #2597233: The FALSE value for #group FAPI property does not have expected behaviour does indeed correct the error of showing the date fields for non-enabled types. However, I have spotted another error with non-enabled types, which I have now added tests for. Because the base fields exist for all content types we should still check in scheduler.cron.inc that the node being processed is actually enabled for scheduler. We allow third-party modules to alter the list of nodes, and anything could set a publish_on date in the db table. We should prevent our cron processing from acting on any nodes which are not enabled.

The attached patch removes the old test from SchedulerFunctionalTest.php and also makes one safety-check in scheduler.cron.inc to prevent cron failures. The new test class should pass for the form field checks but fail on allowing non-enabled types to be processed. Then I'll add a fix and post a second patch.

I noticed that the fieldset tests may not pass anymore, so we might not get a full set of greens for the main test class. See #2645818: Date input fieldset expand/collapse is not working for details.

Status: Needs review » Needs work

The last submitted patch, 109: 2594615-109-non-enabled-content-type.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new14.24 KB
new1.09 KB

As expected in #109 we get 6 fails on checkNonEnabledTypes.

Here is a patch which includes a check in scheduler.cron.inc to avoid processing non-enabled types.

Status: Needs review » Needs work

The last submitted patch, 111: 2594615-111-non-enabled-content-type.patch, failed testing.

jonathan1055’s picture

StatusFileSize
new64 KB

That's good, we have one extra class passing now.

✓		- checkNonEnabledTypes

We also now have our first green row in the console output. I think the fix to cron.inc should be committed against #2625572: Admin setting 'Enable content type for scheduler' is ignored as it is a correction to the main code base not the test. The new test class needs tidying up and debug removed, which I will do, then I would appreciate someones OO knowledge for a review, as there may be some things I could do differently.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new177 bytes
new4.92 KB

edit: removed the text from this comment as it now has a separate issue #2655666: API Testing module - conversion to 8.x and it would be confusing to get replies relating to the test module here.
joshi.rohit100’s picture

Status: Needs review » Needs work
  1. +++ b/src/Tests/SchedulerNonEnabledTypeTest.php
    @@ -0,0 +1,193 @@
    +
    +use Drupal\Component\Utility\SafeMarkup;
    +use Drupal\Core\Entity\EntityStorageInterface;
    +use Drupal\node\Entity\Node;
    +use Drupal\node\Entity\NodeType;
    +use Drupal\node\NodeInterface;
    +use Drupal\node\NodeTypeInterface;
    +use Drupal\simpletest\WebTestBase;
    +
    

    Some unused / un-required use statments.

  2. +++ b/src/Tests/SchedulerNonEnabledTypeTest.php
    @@ -0,0 +1,193 @@
    +    $this->content_name = 'not_for_scheduler';
    +    $this->drupalCreateContentType(['type' => $this->content_name, 'name' => t('Not for Scheduler')]);
    

    You can assign it to property so that it can be later used in testNonEnabledContentType, instead of loading there.

  3. +++ b/src/Tests/SchedulerNonEnabledTypeTest.php
    @@ -0,0 +1,193 @@
    +    $body = $this->randomMachineName(30);
    +    $edit = [
    +      'title' => $title,
    +      'promote' => 1,
    +      'status' => 0,
    +      'body' => $body,
    +      'type' => $this->content_name,
    +    ];
    +    $node = $this->drupalCreateNode($edit);
    +    db_update('node_field_data')->fields(array('publish_on' => REQUEST_TIME - 2))->condition('nid', $node->id())->execute();
    

    same as above.

  4. +++ b/src/Tests/SchedulerNonEnabledTypeTest.php
    @@ -0,0 +1,193 @@
    +    $edit = [
    +      'title' => $title,
    +      'promote' => 1,
    +      'status' => 1,
    +      'body' => $body,
    +      'type' => $this->content_name,
    +    ];
    +    $node = $this->drupalCreateNode($edit);
    +    db_update('node_field_data')->fields(array('unpublish_on' => REQUEST_TIME - 1))->condition('nid', $node->id())->execute();
    

    You can create these two nodes (published / unpublished) in setup so you don't have to create these nodes multiple times in test method as currently.

jonathan1055’s picture

Hi Joshi,
Thank you for the review of SchedulerNonEnabledTypeTest.php

  1. Some unused / un-required use statments.

    I'm not surprised as I was adding many statements in order to try out and develop the code. Which ones are not required?

  2. Do you mean the node type property? i.e store the result of drupalCreateContentType. I will try that, thanks
  3. same as above.

    what exactly?

  4. Not sure that would be any help, as I want clean created nodes, so that the dates can be set fresh. If I was to re-use nodes I'd have to clear the dates via edit or db_update. Is that better than creating them fresh?

Thanks again. I will be good to get this test moved, and also the minor fixes to scheduler.cron.inc then we will have more green test passes.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new10.53 KB
new7.03 KB

Here's a re-roll for SchedulerNonEnabledTypeTest. Changes since #111:

  1. removed debug
  2. removed unnecessary use statements
  3. store the result of creating the content type, instead of re-loading it
  4. Added sequence number to the text, for easier following of the processing
  5. improved comments and tidied up the code

I've attached an interdiff so you can see exactly what is changed. I am going to commit this, but I'm ok if it needs minor tweaks later. There are several more test changes in the pipeline, and getting this done and merged into the main 8.x branch will be good progress.

Status: Needs review » Needs work

The last submitted patch, 117: 2594615-117-non-enabled-content-type.patch, failed testing.

  • jonathan1055 committed 4180632 on 2594615
    Issue #2594615 by jonathan1055: Move NonEnabledTypeTest to a separate...

  • jonathan1055 committed 4180632 on 8.x-1.x
    Issue #2594615 by jonathan1055: Move NonEnabledTypeTest to a separate...
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new5.55 KB

I've added checks to the 'extraFields' test to check that the fieldset is expanded when publish-on or unpublish-on dates exist in the node being editted. These tests currently fail as the code for this was dropped (probably by accident) on converting from 7.x. See #2645818-8: Date input fieldset expand/collapse is not working for details.

Status: Needs review » Needs work

The last submitted patch, 121: 2594615-121-expanded-fieldsets.patch, failed testing.

  • jonathan1055 committed 54d3793 on 2594615
    Issue #2594615: by jonathan1055: Check that fieldset is expanded if...

  • jonathan1055 committed 54d3793 on 8.x-1.x
    Issue #2594615: by jonathan1055: Check that fieldset is expanded if...

  • jonathan1055 committed 00d1135 on 2594615
    Issue #2594615: by jonathan1055: Test for users without permission to...

  • jonathan1055 committed 00d1135 on 8.x-1.x
    Issue #2594615: by jonathan1055: Test for users without permission to...
jonathan1055’s picture

Issue summary: View changes
jonathan1055’s picture

Issue summary: View changes
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new6.96 KB

I've been working on the default date processing, and this allowed me to fix the date tests. The changes in this patch are:

  1. Remove 'node' and 'datetime' from modules required. Both of these are automatically added by 'scheduler' pre-requisites
  2. Use $this->seconds = 23400 instead of repeating the hard-coded number
  3. Correct the text of the validation messages to search for, as these are slightly different as now produced by Datetime::validateDatetime not by scheduler_node_validate()
  4. Change $this->assertRaw to $this->assertText because the messages now contain markup and assertText strips this out
  5. Change $this->clickLink(t('Edit')); to $this->drupalGet('node/x/edit'); because the edit link is not necessarily found, and the url is more robust
  6. Added @todo about switching to date.formatter
  7. Added @todo regarding no longer needing this file as separate, now that datetime functionality is in core not contrib
  8. Comment improvements and code tidy-up

This patch may remove one failed test, but the default time functionality is not added yet. I will add that patch to #2644690: Include default time processing in datetime widget for 8.x when these test changes are committed.

joshi.rohit100’s picture

+++ b/src/Tests/SchedulerDateCombinedFunctionalTest.php
@@ -102,26 +107,32 @@ class SchedulerDateCombinedFunctionalTest extends SchedulerTestBase {
+    $this->drupalGet('node/' . $node->id() . '/edit');
+    $time_text = format_date(strtotime('tomorrow', REQUEST_TIME) + $this->seconds, 'custom', 'H:i:s');
+    $this->assertFieldByName('publish_on[0][value][time]', $time_text, 'The default time offset has been added to the date field when scheduling content for publication.');

use service (or todo for this)

jonathan1055’s picture

use service (or todo for this)

Hi Joshi,
Thanks for the feedback but can you be a bit more specific? Instead of pasting chunks of the patch if you put just the actual line of code it would be more obvious. If you mean the date, I already have @todo Use \Drupal::service('date.formatter').

Jonathan

[Also, something must be going on with the test servers, as this patch has been queued for four hours and not started yet.]

joshi.rohit100’s picture

My point is that date formatter service should be used for format_date() or there should be a todo for this (I am guessing todo that you have mentioned is only for date() ?)

jonathan1055’s picture

Yes, I meant it as a generic todo for the whole file, but I note your point, thanks. I will address those things when the tests run cleanly.

Status: Needs review » Needs work

The last submitted patch, 129: 2594615-129-date-test-form-and-message-corrections.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new7.16 KB

Test failed to complete due to calling $node->id() when the node had not saved properly. This is easily avoided:

    // Check that the default time has been added to the scheduler form on edit.
    // Protect in case the node was not created. The tests will fail anyway.
    if ($node = $this->drupalGetNodeByTitle($edit['title[0][value]'])) {
      $this->drupalGet('node/' . $node->id() . '/edit');
    }

I also added 'and format_date()' on the @todo ;-)

Status: Needs review » Needs work

The last submitted patch, 135: 2594615-135-date-test-form-and-message-corrections.patch, failed testing.

  • jonathan1055 committed d8ae803 on 2594615
    Issue #2594615 by jonathan1055: Date tests - fix message assertions and...

  • jonathan1055 committed d8ae803 on 8.x-1.x
    Issue #2594615 by jonathan1055: Date tests - fix message assertions and...
jonathan1055’s picture

Issue summary: View changes

Good. As expected we get one fewer fail because the 'edit' link is fixed - internally it is 37 passes and 5 fails. Commited this to testing branch and merged to main 8.x to allow testing on #2644690: Include default time processing in datetime widget for 8.x

  • jonathan1055 committed ae78f5e on 8.x-1.x
    Issue #2594615: by jonathan1055: Created this->nodetype property and add...

  • jonathan1055 committed b11ee08 on 8.x-1.x
    Issue #2594615, #2651448: by jonathan1055: Strengthened user-permission...

  • jonathan1055 committed 69a5580 on 2594615
    Issue #2594615: by jonathan1055: Strengthened user-permission tests by...
  • jonathan1055 committed ae78f5e on 2594615
    Issue #2594615: by jonathan1055: Created this->nodetype property and add...

  • jonathan1055 committed 98b44cf on 2594615
    Issue #2594615, #2651448: by jonathan1055: Removed accidental _ from...

  • jonathan1055 committed 69a5580 on 8.x-1.x
    Issue #2594615: by jonathan1055: Strengthened user-permission tests by...
  • jonathan1055 committed 98b44cf on 8.x-1.x
    Issue #2594615, #2651448: by jonathan1055: Removed accidental _ from...

  • jonathan1055 committed b11ee08 on 2594615
    Issue #2594615, #2651448: by jonathan1055: Strengthened user-permission...

  • jonathan1055 committed 8a3f665 on 8.x-1.x
    Issue #2594615: by jonathan1055: First part of work converting...

  • jonathan1055 committed 8a3f665 on 2594615
    Issue #2594615: by jonathan1055: First part of work converting...
jonathan1055’s picture

Issue summary: View changes

Updated results after fixing a problem in the date test, adding more assertions to the permissions test and starting work on API testing module conversion
#2655666: API Testing module - conversion to 8.x

pfrenssen’s picture

Nice to see the progress!

  • jonathan1055 committed fe9b63e on
    Issue #2594615, #2625572: by jonathan1055: Amended tests for non-enabled...

  • jonathan1055 committed fe9b63e on 8.x-1.x
    Issue #2594615, #2625572: by jonathan1055: Amended tests for non-enabled...
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new2.8 KB

Here are some tests for the lightweight cron. This is just the test part of the patch in #2626480-15: scheduler/cron needs a route controller by polynya. Need to check these tests and commit separately first, so that we see the difference when the route is fixed.

Status: Needs review » Needs work
joshi.rohit100’s picture

+++ b/src/Tests/SchedulerLightweightCronTest.php
@@ -0,0 +1,82 @@
+   * The modules to be loaded for these tests.
+   */
+  public static $modules = ['scheduler', 'locale'];
+

I noticed that every test class is extending schedulertestbase and also defining scheduler module to be enabled. shouldn't scheduler module to be enabled in parent so no need to rewrite again ?

jonathan1055’s picture

Hi Joshi,
Yes I noticed that too. Currently schedulerTestBase does not have public static $modules = ['scheduler']; but if that is added and the others are removed it all works just fine. Thanks for the prompt, I will make that commit now, before we introduce any more new test files. The patch in #152 needs to be worked on anyway.
Jonathan

  • jonathan1055 committed 407e743 on
    Issue #2594615: by jonathan1055: Moved $modules to schedulerTestBase
    

  • jonathan1055 committed 407e743 on
    Issue #2594615: by jonathan1055: Moved $modules to schedulerTestBase
    
joshi.rohit100’s picture

I don't see use of enabling locale in #152. Is any ?

jonathan1055’s picture

No it is not needed - see my comment on #2626480-18: scheduler/cron needs a route controller
I am going to use that issue for refining this new test file, given that that is where polynya first created the file.

Thanks for the hint about $modules in schedulerTestBase, that's worked nicely :-)

jonathan1055’s picture

Title: Convert tests » Automated testing in 8.x
Status: Needs work » Needs review
StatusFileSize
new6.14 KB

During work on #2625572: Admin setting 'Enable content type for scheduler' is ignored I realised that in SchedulerNonEnabledTypeTest we should delete each node after using it, otherwise the cron processing/exceptions affect the results of subsequent assertions. I also display the dblog after each cron to show what has happened and tidied up the comments.

Status: Needs review » Needs work

The last submitted patch, 162: 2594615-161-non-enabled-content-type-tests.patch, failed testing.

  • jonathan1055 committed a31b243 on
    Issue #2594615: by jonathan1055: Delete test nodes in NonEnabledTypeTest
    

  • jonathan1055 committed a31b243 on
    Issue #2594615: by jonathan1055: Delete test nodes in NonEnabledTypeTest
    
jonathan1055’s picture

Issue summary: View changes

Updated summary and added details for LightweightCron tests.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new19.43 KB

I am going to split out the test in the large SchedulerFunctionalTests.php file into separate test files. Now that we have a few new test files, such as the lightweightCron and non-enabled nodetypes tests, it will make it consistent to have the others split. Smaller files in this instance are easier to maintain, and changes to one test patch will be less likely to clash with another. It makes re-testing easier (and hence quicker) when working on one part of the functionality. We will soon be expanding the test coverage so I want to get these files split now, to make that easier.

Also we have the setup function in SchedulerTestBase which was not used, and we had common code repeated in the other classes. This is now all in the testbase setup function.

I've only split out two test functions in this patch, just to see how it goes.

Status: Needs review » Needs work

The last submitted patch, 167: 2594615-167-split-tests-into-separate-files.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new19.86 KB

Neede to change API setup from protected to public to match ShedulerTestBase

Status: Needs review » Needs work

The last submitted patch, 169: 2594615-169-split-tests-into-separate-files.patch, failed testing.

  • jonathan1055 committed 7e9d53f on 8.x-1.x
    Issue #2594615: by jonathan1055: Separate files for PastDates and...

  • jonathan1055 committed 7e9d53f on 2594615
    Issue #2594615: by jonathan1055: Separate files for PastDates and...

  • jonathan1055 committed 0673e05 on 2594615
    Issue #2594615: by jonathan1055: Separate files for Validation and...

  • jonathan1055 committed 0673e05 on 8.x-1.x
    Issue #2594615: by jonathan1055: Separate files for Validation and...
jonathan1055’s picture

Last of these commits coming up, then we should have a consistent set of twelve test classes.

The four helper functions in SchedulerTestBase were not actually common functions - each is only used in one test class, so I have moved them into the files that need them - keeping code only where it is needed instead of loading it unnecessarily. (1 into FunctionalTest and 3 into RevisioningTest)

  • jonathan1055 committed 89b9a09 on 8.x-1.x
    Issue #2594615: by jonathan1055: Separate files for FieldsDisplay,...

  • jonathan1055 committed 89b9a09 on 2594615
    Issue #2594615: by jonathan1055: Separate files for FieldsDisplay,...
jonathan1055’s picture

Issue summary: View changes

Updated summary to reflect new test cases.

  • jonathan1055 committed 4e3f118 on 2594615
    Issue #2666832, #2594615 by jonathan1055: Check for NULL date in...

  • jonathan1055 committed 4e3f118 on 8.x-1.x
    Issue #2666832, #2594615 by jonathan1055: Check for NULL date in...
jonathan1055’s picture

Issue summary: View changes

  • jonathan1055 committed 816915c on 8.x-1.x
    Issue #2594615: by jonathan1055: Remove unnecessary createUser from...

  • jonathan1055 committed 816915c on 2594615
    Issue #2594615: by jonathan1055: Remove unnecessary createUser from...
jonathan1055’s picture

Title: Automated testing in 8.x » Automated testing in 8.x [meta]
Issue summary: View changes
Status: Needs work » Active
jonathan1055’s picture

Issue summary: View changes

Now that #2644690: Include default time processing in datetime widget for 8.x and #2651448: Publish and Unpublish fields are shown for users who do not have the permission have been committed we only have one failing test - the patch is on #2625572: Admin setting 'Enable content type for scheduler' is ignored for review.

I have also deleted the testing branch 2594615 as it has served it's purpose. All the tests have been running for several months now, and it was just an unnecessary overhead to keep both branhces in line, continually merging every commit from one branch into the other.

jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new18.22 KB

I have made some minor improvements to the test files, mainly in response to my testing of #2633870: Revisit defaults for third party settings which allowed me to see where the tests were passing due to luck and assumption, instead of testing the actual piece of code in question. Only minor changes, here is a summary:

  1. FieldsDisplayTest - one extra assertion to split the check that a fieldset is shown and then that it is open.
  2. FunctionalTest - exit earlier if the node was not created, to avoid showing confusing successes and failures.
  3. NonEnabledTest - variable name changes for consistency, message text improvements when checking default values.
  4. PastDatesTest - set 'required' to false so that tests do not give confusing results. Extra assertion to check default values, then check 'error' value explicitly not implicitly.
  5. RequiredTest - extra test case to check default values, not make assumptions.
  6. RevisioningTest - make sure value for publish_past_date does not skew the results. Clarified text of messages.
  7. Some classes had redundant setUp() which just called parent::setUp() others had none. Removed the empty ones.

Does not need a review, I am going to commit now, but for the record here is a patch, to show the test results.

Status: Needs review » Needs work

The last submitted patch, 186: 2594615-186-improved-tests-for-default-values.patch, failed testing.

  • jonathan1055 committed 1228ba2 on 8.x-1.x
    Issue #2594615 by jonathan1055: Improved test messages and checks for...

  • jonathan1055 committed 7c336ad on 8.x-1.x
    Issue #2594615 by jonathan1055: Remove empty setUp()
    
jonathan1055’s picture

Issue summary: View changes
Status: Needs work » Active

#2625572: Admin setting 'Enable content type for scheduler' is ignored is fixed.

Added new tests SchedulerTokenReplaceTest and SchedulerMetaInformationTest

All tests pass :-)

jonathan1055’s picture

Status: Active » Fixed

All tests have been passing since 9th March https://www.drupal.org/pift-ci-job/206819
Closing this issue now. Good work.


Alongside the 8.x work, I am also going through old issues and either responding or closing, as appropriate. My aim in the short term is to get the queue down to 50 or fewer, so that all issue are shown on one page. Currenlty we have 63 open issues, down from 67 yesterday. The project block is still a few days behind in the totals it shows, even though #2686419: Wrong count for 'open' issues in block on project page and #2394175: Remove or emphasise need to log in for search are closed.
pfrenssen’s picture

Thanks for your dedication and hard work!

joshi.rohit100’s picture

Good to see this meta closed :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned

Unassigning.