New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2317193 | Port "Add an item to a list" action to D8 #102
#2317193 | Port "Add an item to a list" action to D8 #102
Conversation
public function testActionExecution() { | ||
|
||
// Test adding to array of string values | ||
$list = array('One','Two','Three'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misse spaces between the items; ie.after the comma
Sorted (I think!) the spacing issue, having issues working out the git branch/merging thing hence the references to temp branch etc. Looking into context value issue next. |
Do you want to continue working on this, Steve? Any help needed? |
hmm I'd completely forgotten about this, sorry! Sure, I think it may just need squashing but will check |
Oh hang on, forgot about the unit test changes. brb |
Oh, OK, it's a bit further behind than I thought - pointers welcome if you have time and I'm not slowing the process down too much. I've got to figure out how to set up a test for a list, code doesn't seem to be there at the moment (my understanding has increased in the last 22 days!). Will take a look over the weekend, and I'll be in Amsterdam this time next week so around for the first lot of extended sprints but then flying back the next friday - no doubt say hi if you're going too - not long now yay! |
* Contains \Drupal\rules\Tests\Action\ListAddItemTest. | ||
*/ | ||
|
||
namespace Drupal\rules\Tests\Action; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespace should be moved to the "Unit" subfolder, please rebase your work on the 8.x-3.x branch and move the test.
Managed a bit of time on it, now stuck at "PHP Fatal error: Call to a member function get() on a non-object in /Users/steve/Sites/d8dev/core/lib/Drupal.php on line 428" when I run the tests locally :( Will continue |
|
||
// Test that the list contains 'Four'. | ||
$this->action | ||
->setContextValue('list', $list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to use $this->getMockTypedData($list) here, take a look at the other unit tests. Maybe also $this->action->setTypedDataManager($this->getMockTypedDataManager()); in setUp().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, let's use RulesIntegrationTestBase now and the real typed data manager. So we can save converting this test later on :)
Hi - am stuck on two issue on this one, just spoke to fago who didn't know what the issue is either so posting here whilst trying to debug too, although may move to something else whilst I'm stuck! I'm setting a provided value but it says the context is not valid. Also I'm having to force values for 'unique' and 'pos' even though I say they're not required. Here's the output of my test: There was 1 error:
/Users/steve/Sites/d8dev/modules/rules/src/Context/RulesContextTrait.php:61 There was 1 failure:
/Users/steve/Sites/d8dev/modules/rules/tests/src/Unit/Condition/UserHasEntityFieldAccessTest.php:123 FAILURES! |
The UserHasEntityFieldAccessTest.php should be fixed in 8.x-3.x, please merge your branch. |
$this->action = new ListAddItem([], '', ['context' => [ | ||
'list' => new ContextDefinition('list'), | ||
'item' => new ContextDefinition('string') | ||
]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outputlist provided context is missing here? Same for the other contexts in the annotation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UserHasEntityFieldAccessTest.php should be fixed in 8.x-3.x, please merge your branch.
Ah - I think the issue here is I fetched the upstream and rebased to my local 8.x-3.x but of course this is a branch so I'll need to now rebase that branch on the latest 8.x-3.x.
The outputlist provided context is missing here? Same for the other contexts in the annotation?
The 'pos' and 'unique' contexts aren't required - I take it then I still have to declare them here. Thanks for the pointer.
So I've updated my branch, added values for 'unique' and 'pos', but still getting provided context is not valid :( |
I'm just print_r'ing out the input and output to ensure they are arrays, seems to be all ok in that respect: ..............EinputArray Time: 664 ms, Memory: 21.00Mb |
So through debugging I can see it's just not returning a definition of the context 'provides' in the getProvidedDefinition function, it's just blank. My declaration seems ok so not sure what the issue is, keeping hunting... |
'item' => new ContextDefinition('string'), | ||
'unique' => new ContextDefinition('boolean'), | ||
'pos' => new ContextDefinition('string') | ||
]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'provides' is missing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok cool thx
Hmmm... OK so I fixed that last issue and managed to make it pass the tests but only by returning a value as well as setting the provided value:
|
...which makes me think I don't need the setProvidedValue line then, I'll take that out & resubmit |
OK, so that worked ;) |
Forgot to remove my forcing values test code, removed now. |
Added two more tests, one to check 'position' option works, one to check 'unique' option works. |
I put all three tests in testActionExecution - not sure if they should be split up to a function for each? I see it kinda auto-finds tests as long as I have the @Covers::execute there so presume I can do things like testActionExecutionWithPosition, testActionExecutionUnique, etc.? |
Oh hang on, wrote a test for unique but not not checking unique. On way back to hotel so will write it there. There's always something... ;) |
Non-unique test added. |
* Provides an 'Add a list item' action. | ||
* | ||
* @Action( | ||
* id = "rules_action_data_list_add", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be rules_list_add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing to rules_list_item_add to keep in toe with rules_list_item_remove which has already been committed to 8.x-3.x
Wondering if this is still wanted to be done:
|
array_unshift($list, $item); | ||
break; | ||
|
||
case 'end': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the default branch and the "end" branch do the same? Then we can just use "default" alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to an if..else
…17193 Issue #2317193 by stevepurkiss: Port "Add an item to a list" action to D8
Initial port