Skip to content

Commit

Permalink
updated unit tests to match with the latest changes in AclCore
Browse files Browse the repository at this point in the history
  • Loading branch information
esokullu committed May 3, 2017
1 parent 267f745 commit 10df190
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/Pho/Framework/AclCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ class AclCore {
*/
protected $context;

/**
* A reference to the node itself
*
* @var ParticleInterface
*/
protected $node;

/**
* Constructor.
*
* @param Actor $creator The creator of this node.
* @param ContextInterface $context The context in which this node is created and will exist
*/
public function __construct(Actor $creator, ContextInterface $context) {
public function __construct(ParticleInterface $node, Actor $creator, ContextInterface $context) {
$this->node = $node;
$this->creator = $creator;
$this->context = $context;
}
Expand All @@ -69,6 +77,16 @@ public function context(): ContextInterface
return $this->context;
}

/**
* Getter for the node object.
*
* @return ParticleInterface
*/
public function node(): ParticleInterface
{
return $this->node;
}

/**
* Converts the object into a portable PHP array
*
Expand All @@ -80,6 +98,7 @@ public function toArray(): array
{
//eval(\Psy\sh());
return [
"node" => (string) $this->node->id(),
"creator" => (string) $this->creator->id(),
"context" => ($this->context instanceof Graph) ? Graph::class : (string) $this->context->id()
];
Expand Down
2 changes: 1 addition & 1 deletion src/Pho/Framework/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface {

public function __construct(ContextInterface $context) {
parent::__construct($context);
$this->acl = new AclCore($this, $context);
$this->acl = new AclCore($this, $this, $context);
$this->enter($context);
$this->setupEdges();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pho/Framework/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Frame extends \Pho\Lib\Graph\SubGraph implements ParticleInterface, Contex

public function __construct(Actor $creator, ContextInterface $context) {
parent::__construct($context);
$this->acl = new AclCore($creator, $context);
$this->acl = new AclCore($this, $creator, $context);
$this->setupEdges();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Pho/Framework/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Object extends \Pho\Lib\Graph\Node implements ParticleInterface {

public function __construct(Actor $creator, ContextInterface $context) {
parent::__construct($context);
$this->acl = new AclCore($creator, $context);
$this->acl = new AclCore($this, $creator, $context);
$this->setupEdges();
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Pho/Framework/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ public function testActorToArray() {
$this->assertCount(1, $actor->toArray()["attributes"]);
$this->assertArrayHasKey("edge_list", $array);
$this->assertArrayHasKey("acl", $array);
$this->assertCount(2, $array["acl"]);
$this->assertCount(3, $array["acl"]);
$this->assertArrayHasKey("context", $array["acl"]);
$this->assertArrayHasKey("creator", $array["acl"]);
$this->assertArrayHasKey("node", $array["acl"]);
}

public function testFrameToArray() {
Expand All @@ -122,9 +123,10 @@ public function testFrameToArray() {
$this->assertCount(1, $actor->toArray()["attributes"]);
$this->assertArrayHasKey("edge_list", $array);
$this->assertArrayHasKey("acl", $array);
$this->assertCount(2, $array["acl"]);
$this->assertCount(3, $array["acl"]);
$this->assertArrayHasKey("context", $array["acl"]);
$this->assertArrayHasKey("creator", $array["acl"]);
$this->assertArrayHasKey("node", $array["acl"]);
$this->assertEquals($actor->id(), $array["acl"]["creator"]);
}

Expand Down

0 comments on commit 10df190

Please sign in to comment.