silverstripe-australia /
advancedworkflow
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Tests for the workflow engine. |
||
| 4 | * |
||
| 5 | * @author [email protected] |
||
| 6 | * @license BSD License (http://silverstripe.org/bsd-license/) |
||
| 7 | * @package advancedworkflow |
||
| 8 | * @subpackage tests |
||
| 9 | */ |
||
| 10 | class WorkflowInstanceTest extends SapphireTest { |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | /** |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | public static $fixture_file = 'advancedworkflow/tests/useractioninstancehistory.yml'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * |
||
| 20 | * @var Member |
||
| 21 | */ |
||
| 22 | protected $currentMember; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * |
||
| 26 | */ |
||
| 27 | public function setUp() { |
||
| 28 | parent::setUp(); |
||
| 29 | $this->currentMember = $this->objFromFixture('Member', 'ApproverMember01'); |
||
|
0 ignored issues
–
show
It seems like
$this->objFromFixture('M...r', 'ApproverMember01') can also be of type object<DataObject>. However, the property $currentMember is declared as type object<Member>. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Tests WorkflowInstance#getMostRecentActionForUser() |
||
| 34 | */ |
||
| 35 | public function testGetMostRecentActionForUser() { |
||
| 36 | |||
| 37 | // Single, AssignUsersToWorkflowAction in "History" |
||
| 38 | $history01 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance01'); |
||
| 39 | $mostRecentActionForUser01 = $history01->getMostRecentActionForUser($this->currentMember); |
||
| 40 | $this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser01, 'Asserts the correct ClassName is retured #1'); |
||
|
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 41 | $this->assertEquals('Assign', $mostRecentActionForUser01->BaseAction()->Title, 'Asserts the correct BaseAction is retured #1'); |
||
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 42 | |||
| 43 | // No AssignUsersToWorkflowAction found with Member's related Group in "History" |
||
| 44 | $history02 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance02'); |
||
| 45 | $mostRecentActionForUser02 = $history02->getMostRecentActionForUser($this->currentMember); |
||
| 46 | $this->assertFalse($mostRecentActionForUser02, 'Asserts false is returned because no WorkflowActionInstance was found'); |
||
|
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 47 | |||
| 48 | // Multiple AssignUsersToWorkflowAction in "History", only one with Group relations |
||
| 49 | $history03 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance03'); |
||
| 50 | $mostRecentActionForUser03 = $history03->getMostRecentActionForUser($this->currentMember); |
||
| 51 | $this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser03, 'Asserts the correct ClassName is retured #2'); |
||
|
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 52 | $this->assertEquals('Assign', $mostRecentActionForUser03->BaseAction()->Title, 'Asserts the correct BaseAction is retured #2'); |
||
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 53 | |||
| 54 | // Multiple AssignUsersToWorkflowAction in "History", both with Group relations |
||
| 55 | $history04 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance04'); |
||
| 56 | $mostRecentActionForUser04 = $history04->getMostRecentActionForUser($this->currentMember); |
||
| 57 | $this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser04, 'Asserts the correct ClassName is retured #3'); |
||
|
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 58 | $this->assertEquals('Assigned Again', $mostRecentActionForUser04->BaseAction()->Title, 'Asserts the correct BaseAction is retured #3'); |
||
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 59 | |||
| 60 | // Multiple AssignUsersToWorkflowAction in "History", one with Group relations |
||
| 61 | $history05 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance05'); |
||
| 62 | $mostRecentActionForUser05 = $history05->getMostRecentActionForUser($this->currentMember); |
||
| 63 | $this->assertInstanceOf('WorkflowActionInstance', $mostRecentActionForUser05, 'Asserts the correct ClassName is retured #4'); |
||
|
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 64 | $this->assertEquals('Assigned Me', $mostRecentActionForUser05->BaseAction()->Title, 'Asserts the correct BaseAction is retured #4'); |
||
|
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Tests WorkflowInstance#canView() |
||
| 69 | */ |
||
| 70 | public function testCanView() { |
||
| 71 | // Single, AssignUsersToWorkflowAction in "History" |
||
| 72 | $history01 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance01'); |
||
| 73 | $this->assertTrue($history01->canView($this->currentMember)); |
||
|
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 74 | |||
| 75 | // No AssignUsersToWorkflowAction found with Member's related Group in "History" |
||
| 76 | $history02 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance02'); |
||
| 77 | $this->assertFalse($history02->canView($this->currentMember)); |
||
|
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 78 | |||
| 79 | // Multiple AssignUsersToWorkflowAction in "History", only one with Group relations |
||
| 80 | $history03 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance03'); |
||
| 81 | $this->assertTrue($history03->canView($this->currentMember)); |
||
|
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 82 | |||
| 83 | // Multiple AssignUsersToWorkflowAction in "History", both with Group relations |
||
| 84 | $history04 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance04'); |
||
| 85 | $this->assertTrue($history04->canView($this->currentMember)); |
||
|
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 86 | |||
| 87 | // Multiple AssignUsersToWorkflowAction in "History" |
||
| 88 | $history05 = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance05'); |
||
| 89 | $this->assertTrue($history05->canView($this->currentMember)); |
||
|
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<WorkflowInstanceTest>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 90 | } |
||
| 91 | |||
| 92 | public function testValidTransitions() { |
||
| 93 | $instance = $this->objFromFixture('WorkflowInstance', 'WorkflowInstance06'); |
||
| 94 | $transition1 = $this->objFromFixture('WorkflowTransition', 'Transition05'); |
||
| 95 | $transition2 = $this->objFromFixture('WorkflowTransition', 'Transition06'); |
||
| 96 | $member1 = $this->objFromFixture('Member', 'Transition05Member'); |
||
| 97 | $member2 = $this->objFromFixture('Member', 'Transition06Member'); |
||
| 98 | |||
| 99 | // Given logged in as admin, check that there are two actions |
||
| 100 | $this->logInWithPermission('ADMIN'); |
||
| 101 | $transitions = $instance->validTransitions()->column('ID'); |
||
| 102 | $this->assertContains($transition1->ID, $transitions); |
||
| 103 | $this->assertContains($transition2->ID, $transitions); |
||
| 104 | |||
| 105 | // Logged in as a member with permission on one transition, check that only this one is present |
||
| 106 | $member1->logIn(); |
||
| 107 | $transitions = $instance->validTransitions()->column('ID'); |
||
| 108 | $this->assertContains($transition1->ID, $transitions); |
||
| 109 | $this->assertNotContains($transition2->ID, $transitions); |
||
| 110 | |||
| 111 | // Logged in as a member with permissions via group |
||
| 112 | $member2->logIn(); |
||
| 113 | $transitions = $instance->validTransitions()->column('ID'); |
||
| 114 | $this->assertNotContains($transition1->ID, $transitions); |
||
| 115 | $this->assertContains($transition2->ID, $transitions); |
||
| 116 | } |
||
| 117 | |||
| 118 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.