Closed (fixed)
Project:
Scheduler
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
24 Jan 2016 at 10:31 UTC
Updated:
9 Oct 2016 at 14:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #4
jonathan1055 commentedIn the commit in #2 I have renamed the module from scheduler_test to scheduler_api_test, so that it is clear and more specific what the module is for.
The commit in #3 works on hook_install(). Progress so far: determine if the custom node type exists, create it if not, adding a body field as before. Lists the fields that exist, and create the custom field 'approved' if it is not found. However, I have not managed to save the field definition permanently, it is only 'in code'.
Comment #5
jonathan1055 commentedI found that to do the conversion you need to be able to enable and run the test module. To avoid duplicating code, a simple solution is to create a folder
scheduler_api_testin the main /modules directory, copy scheduler_api_test.info.yml to that folder as this file is relatively static, but instead of duplicating .install and .module, create two files which just include the actual source file. So modules/scheduler_api_test.install just contains:Likewise for .module. Then you can test the module interactively and via simpletest using exactly the same source code.
To show the latest state of the conversion, after enabling the module interactively, and hook_install() has run if you go to the status report page /admin/reports/status, you get a message:
I tracked this down to \Drupal\Core\Entity\EntityDefinitionUpdateManager and it seems that because the field is not saved in storage but is defined in code then the implication is that an admin user has deleted the fields manually, and that is what the message above is trying to say. Executing
\Drupal::service('entity.definition_update_manager')->applyUpdates();removes the status warning, but that is no help, because we need to actually get the field saved in storage. That is where I am at currently, and would welcome any ideas on how to progress.The code is very much work-in-progress, with plenty of devel module dd() calls and commented-out lines. I have not started working on the .module file yet, as that will depend on how the .install process is done.
Comment #7
pfrenssenAssigning for review. Working from the global sprint weekend in Sofia :)
Comment #8
jonathan1055 commentedGreat, thanks.
My final explanation in #5 is a bit muddled, I think. The new fields seem to be stored in the entity storage (wherever that is) but the actual field names have not been added as columns to the db table
node_field_data. This is how the status message gets triggered, I think. I have uploaded my rough notes in case they help.Comment #9
pfrenssenReview:
Instead of creating the node type programmatically we can export it as configuration. So the node type can be exported to
config/install/node.type.scheduler_api_test.yml, the body field can be exported toconfig/install/field.field.node.scheduler_api_test.body.ymland the "field_scheduler_test_approved" field can become something likeconfig/install/field.field.node.scheduler_api_test.approved.yml. For examples of this in core take a look atcore/profiles/standard.It actually looks like the entire
hook_install()can be replaced by exported config. Hopefully this will fix the "mismatched entity and/or field definition" error you're seeing.The easiest way of doing this by the way is to click together the content type and use the Config Devel module to export the configuration. If you use the machine name 'scheduler_api_test' for the node type you can find all relevant config items with
drush cli | grep scheduler_api_test.Do we actually need the body field for the test? Haven't looked at them in detail yet.
sites/example.settings.local.php. This has an option to allow test modules and themes to be installed.Comment #10
jonathan1055 commentedYes, I was coming to the conclusion that I could make better progress using the config .yml files, but was trying my best to make it by programming. Got quite a way there but not quite! No, we do not need the body field, it works fine without. Here's a patch which uses exported config files plus the necessary changes to .install, .module and SchedulerApiTestCase.php: Here's a summary of what I have done:
I my local simpletest SchedulerApiTestCase is now fully green with no fails.
Comment #12
jonathan1055 commentedPatch was duff. Somehow my new files were empty. Here's a better one.
Comment #14
jonathan1055 commentedThat's nice, we have 22 passes and no fails :-) and the overall class is green.
This test module could be expanded to cover our other hooks, but that's for later. As of now we have a clean set of passes. Setting back to 'needs review' as I'd apreciate any feedback.
Comment #15
jonathan1055 commentedNew patch with a few minor changes:
Comment #17
jonathan1055 commentedApiTest still all green with 22 passes.
Setting back to 'needs review'.
Comment #18
jonathan1055 commentedNow that work on #2651338: Create a service for the Scheduler API has started we need this testing module active and running, so the hooks can be tested. As it is only testing code I am going to commit the changes in #15 now. Happy to make further adjustments if anyone wants to do a review later.
Comment #20
jonathan1055 commentedGood.
Overall we have 24 classes pass, 3 fails.
Leaving this issue open for now, as we should expand the API test module to cover more hooks than than just hook_scheduler_allow()
Comment #21
jonathan1055 commentedAdded new field to test approved unpublishing (and in doing so, renamed the existing field for clarity). Added test coverage for hook_scheduler_allow_unpublishing(), and added dummy functions for the remainder of the hooks, to be completed in subsequent patches (this one is big enough already)
Comment #23
jonathan1055 commentedI have now added test coverage for all the other API hooks: hook_scheduler_api(), hook_scheduler_nid_list() and hook_scheduler_nid_list_alter()
The changes at the top of the patch are just to rename two variables, as I realised they clashed with
$this->nodetypewhich was needed in the new tests.Comment #25
jonathan1055 commentedWe now have three extra test classes and all the API hooks are covered. There is one scenario (enter past date, 'publish immediately') which is not tested yet, but the other four $actions are covered.
Good to get this in so that work on #2651338: Create a service for the Scheduler API can progress.
Comment #26
pfrenssenYou can use an assert instead of doing an if statement here. You can do for example:
@covers is a tag that is used by code coverage checks by PHPUnit. I don't think this works for procedural code, and it's not used in tests that extend WebTestBase since they based on Simpletest rather than PHPUnit. Simpletest doesn't read these annotations.
I don't mind keeping it though since the intention is clear for human readers.
Do an assert here if you need to test that the node type exists.
It's a bit strange to start the test immediately with an assert. Usually you start by performing an action, and then check if the expected result has been achieved. Is there any reason why you think this node type wouldn't be created? Or is this perhaps to help debugging while developing this?
We should use camelCase for $this->custom_nodetype.
Comment #27
jonathan1055 commentedThanks for the review
Patch 27 attached to address all these issues. I have also completed the final piece of the test to cover 'publish immediately' but will keep that for a separate patch not to get mixed in with these review fixes.
Comment #28
jonathan1055 commentedJust for information sharing, I found an even better way to allow the test module to be used as a real module which can be manually enabled and run during development, but without duplicating any code files. In a unix-based environment I created a symbolic link called scheduler_api_test in the real modules folder, which points to the source test file folder.
This means you can enable the module for manual testing and development, make code changes to the files and not have any duplication and/or copying of code.
Comment #29
jonathan1055 commentedHere are the final changes to cover hook_scheduler_api when publishing immediately. This patch is in addition to #27, but they are independent and do not clash, so can be applied in either order.
Comment #30
jonathan1055 commentedGood. For SchedulerApiTestCase before we had 93 passes, now we get 96 passes.
Pieter, when you are happy with my changes from the review I will commit these two, and then this issue can be closed. One more blocker complete.
Comment #34
jonathan1055 commentedI have committed the changes following review in #26/#27, the final test coverage as per #29, and also a strengthening of a couple of the assertions in
testAllowedPublishingAndUnpublishing()which were giving mis-leading positive results if a previous assertion failed.This is now fully completed (as far as I know) and I am marking it fixed :-)
Comment #36
jonathan1055 commentedSmall change to insulate non-test content for unwanted changes when then API Test module is enabled interactively (as described in #28). The text 'API TEST' is added to the node title, and checked in the api module. Ordinary nodes without this are therefore unaffected during interactive development.
Comment #38
jonathan1055 commentedComment #40
jonathan1055 commentedWe now have a second test module, which I put in a new folder
tests/modules/scheduler_access_test/- see #2700209: Disable node access checks during cron publish/unpublishSo for consistency I have moved the API test module files from
tests/modules/into the properly segregatedtests/modules/scheduler_api_test/folder. The automatic commit comment did not get written (maybe because this issue was closed?) so here is the linkhttp://cgit.drupalcode.org/scheduler/commit/?id=369b0d6
Comment #41
jonathan1055 commentedCommted some changes to make it cleaner to delete all config items automatically on uninstalling this module.