Skip to content
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

Merged
merged 1 commit into from Oct 17, 2014
Merged

#2317193 | Port "Add an item to a list" action to D8 #102

merged 1 commit into from Oct 17, 2014

Conversation

stephenpurkiss
Copy link
Contributor

Initial port

public function testActionExecution() {

// Test adding to array of string values
$list = array('One','Two','Three');
Copy link
Owner

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

@stephenpurkiss
Copy link
Contributor Author

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.

@klausi
Copy link
Collaborator

klausi commented Sep 19, 2014

Do you want to continue working on this, Steve? Any help needed?

@stephenpurkiss
Copy link
Contributor Author

hmm I'd completely forgotten about this, sorry! Sure, I think it may just need squashing but will check

@stephenpurkiss
Copy link
Contributor Author

Oh hang on, forgot about the unit test changes. brb

@stephenpurkiss
Copy link
Contributor Author

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;
Copy link
Collaborator

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.

@stephenpurkiss
Copy link
Contributor Author

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)
Copy link
Collaborator

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().

Copy link
Owner

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 :)

@stephenpurkiss
Copy link
Contributor Author

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:

  1. Drupal\Tests\rules\Unit\Action\ListAddItemTest::testActionExecution
    Drupal\Component\Plugin\Exception\ContextException: The outputlist provided context is not valid.

/Users/steve/Sites/d8dev/modules/rules/src/Context/RulesContextTrait.php:61
/Users/steve/Sites/d8dev/modules/rules/src/Context/RulesContextTrait.php:50
/Users/steve/Sites/d8dev/modules/rules/src/Context/RulesContextTrait.php:40
/Users/steve/Sites/d8dev/modules/rules/src/Plugin/Action/ListAddItem.php:90
/Users/steve/Sites/d8dev/modules/rules/tests/src/Unit/Action/ListAddItemTest.php:66
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:179
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:132

There was 1 failure:

  1. Drupal\Tests\rules\Unit\Condition\UserHasEntityFieldAccessTest::testConditionEvaluation
    Failed asserting that false is true.

/Users/steve/Sites/d8dev/modules/rules/tests/src/Unit/Condition/UserHasEntityFieldAccessTest.php:123
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:179
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:132

FAILURES!

@klausi
Copy link
Collaborator

klausi commented Sep 27, 2014

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')
]]);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@stephenpurkiss
Copy link
Contributor Author

So I've updated my branch, added values for 'unique' and 'pos', but still getting provided context is not valid :(

@stephenpurkiss
Copy link
Contributor Author

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
(
[0] => One
[1] => Two
[2] => Three
)
resultArray
(
[0] => One
[1] => Two
[2] => Three
[3] => Four
)
.................................................. 65 / 92 ( 70%)
...........................

Time: 664 ms, Memory: 21.00Mb

@stephenpurkiss
Copy link
Contributor Author

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')
]]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'provides' is missing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok cool thx

@stephenpurkiss
Copy link
Contributor Author

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:

$this->setProvidedValue('outputlist', $list);
return array('list' => $list);

@stephenpurkiss
Copy link
Contributor Author

...which makes me think I don't need the setProvidedValue line then, I'll take that out & resubmit

@stephenpurkiss
Copy link
Contributor Author

OK, so that worked ;)

@stephenpurkiss
Copy link
Contributor Author

Forgot to remove my forcing values test code, removed now.

@stephenpurkiss
Copy link
Contributor Author

Added two more tests, one to check 'position' option works, one to check 'unique' option works.

@stephenpurkiss
Copy link
Contributor Author

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.?

@stephenpurkiss
Copy link
Contributor Author

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... ;)

@stephenpurkiss
Copy link
Contributor Author

Non-unique test added.

* Provides an 'Add a list item' action.
*
* @Action(
* id = "rules_action_data_list_add",
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

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

@stephenpurkiss
Copy link
Contributor Author

Wondering if this is still wanted to be done:

  • @todo: Replace in_array() with \Drupal\rules\Plugin\Condition\ListContains

array_unshift($list, $item);
break;

case 'end':
Copy link
Collaborator

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.

Copy link
Contributor Author

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

klausi added a commit that referenced this pull request Oct 17, 2014
…17193

Issue #2317193 by stevepurkiss: Port "Add an item to a list" action to D8
@klausi klausi merged commit 5217f8e into fago:8.x-3.x Oct 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants