-
Notifications
You must be signed in to change notification settings - Fork 120
Added code for refining item context #184
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
Open
stephenpurkiss
wants to merge
6
commits into
fago:8.x-3.x
Choose a base branch
from
stephenpurkiss:refinecontext-port-list-contains-condition-to-8x-2281083
base: 8.x-3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d58b461
Added code for refining item context
stephenpurkiss e5491be
Updating as per Klausi's recommendations from https://github.com/fago…
stephenpurkiss 8541f44
renaming $item->$item_context_definition
stephenpurkiss 9e65b65
altering mocking functions from getDataTypeId->getDataType
stephenpurkiss 49570cb
testing refining context definitions
stephenpurkiss 7e7e124
trying setting up mock context definition and typed data manager in s…
stephenpurkiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,8 +47,8 @@ public function testSummary() { | |
| */ | ||
| public function testConditionEvaluation() { | ||
|
|
||
| // Test array of string values | ||
| $list = ['One','Two','Three']; | ||
| // Test array of string values. | ||
| $list = ['One', 'Two', 'Three']; | ||
|
|
||
| // Test that the list doesn't contain 'Zero'. | ||
| $this->condition | ||
|
|
@@ -80,7 +80,7 @@ public function testConditionEvaluation() { | |
| ->setContextValue('item', 'Four'); | ||
| $this->assertFalse($this->condition->evaluate()); | ||
|
|
||
| // Create array of mock entities | ||
| // Create array of mock entities. | ||
| $entity_zero = $this->getMock('Drupal\Core\Entity\EntityInterface'); | ||
| $entity_zero->expects($this->any()) | ||
| ->method('id') | ||
|
|
@@ -106,8 +106,8 @@ public function testConditionEvaluation() { | |
| ->method('id') | ||
| ->will($this->returnValue('entity_four_id')); | ||
|
|
||
| // Test array of entities | ||
| $entity_list = [$entity_one,$entity_two,$entity_three]; | ||
| // Test array of entities. | ||
| $entity_list = [$entity_one, $entity_two, $entity_three]; | ||
|
|
||
| // Test that the list of entities doesn't contain entity 'entity_zero'. | ||
| $this->condition | ||
|
|
@@ -139,4 +139,42 @@ public function testConditionEvaluation() { | |
| ->setContextValue('item', $entity_four); | ||
| $this->assertFalse($this->condition->evaluate()); | ||
| } | ||
|
|
||
| /** | ||
| * Test refining the context definitions. | ||
| * | ||
| * @covers ::refineContextDefinitions | ||
| */ | ||
| public function testRefiningContextDefinitions() { | ||
| // Create array of mock entities. | ||
| $entity_zero = $this->getMock('Drupal\Core\Entity\EntityInterface'); | ||
| $entity_zero->expects($this->any()) | ||
| ->method('id') | ||
| ->willReturn('entity_zero_id'); | ||
| $entity_zero->expects($this->any()) | ||
| ->method('getEntityTypeId') | ||
| ->willReturn('entity_zero_type_id'); | ||
|
|
||
| $entity_one = $this->getMock('Drupal\Core\Entity\EntityInterface'); | ||
| $entity_one->expects($this->any()) | ||
| ->method('id') | ||
| ->willReturn('entity_one_id'); | ||
| $entity_one->expects($this->any()) | ||
| ->method('getEntityTypeId') | ||
| ->willReturn('entity_one_type_id'); | ||
|
|
||
| // Test array of entities. | ||
| $entity_list = [$entity_zero, $entity_one]; | ||
|
|
||
| $this->condition | ||
| ->setContextValue('list', $entity_list) | ||
| ->setContextValue('item', $entity_zero); | ||
| $this->condition->refineContextdefinitions(); | ||
|
|
||
| // Get the context definition for the item | ||
| // and make sure that the type is now the entity type. | ||
| $item = $this->condition->getContextDefinition('item'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. item is a bad variable name here, since this is not the item but the context definition of item.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, well made ;) |
||
| $this->assertEquals($item->getDataType(), 'entity:entity_zero_type_id'); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why EntityInterface here? I think this should just be "$typed_data_item = $this->getContextData('item')" and then "$this->pluginDefinition['context']['item']->setDataType($typed_data_item->getDataDefinition()->getDataType());"
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.
"$typed_data_item = $this->getContextData('item')" created this error:
PHP Fatal error: Call to undefined method Drupal\rules\Plugin\Condition\DataListContains::getContextData() in /Users/steve/Sites/d8dev/modules/rules/src/Plugin/Condition/DataListContains.php on line 45
...so I copied the code from DataComparison.php:
$item = $this->condition->getContextDefinition('item');
Your suggested code failed my test though:
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'any'
+'entity:entity_zero_type_id'