Cake\Acl\Test\TestCase\Model\Behavior\AclBehaviorTest::testAfterDelete PHP Method

testAfterDelete() public method

Test After Delete
public testAfterDelete ( ) : void
return void
    public function testAfterDelete()
    {
        $Person = TableRegistry::get('AclPeople');
        $this->Aro->save(new Aro(['model' => $Person->alias(), 'foreign_key' => 2, 'parent_id' => null]));
        $this->Aco->save(new Aco(['model' => $Person->alias(), 'foreign_key' => 2, 'parent_id' => null]));
        $Person->deleteAll(['name' => 'person']);
        $person = $Person->save(new AclPerson(['name' => 'Trent', 'mother_id' => 2, 'father_id' => 3]));
        $node = $Person->node($person, 'Aro')->toArray();
        $this->assertEquals(2, count($node));
        $this->assertEquals(5, $node[0]->parent_id);
        $this->assertEquals(null, $node[1]->parent_id);
        $Person->delete($person);
        $result = $this->Aro->find('all', ['conditions' => ['model' => $Person->alias(), 'foreign_key' => $person->id]]);
        $this->assertTrue($result->count() === 0);
        $result = $this->Aro->find('all', ['conditions' => ['model' => $Person->alias(), 'foreign_key' => 2]]);
        $this->assertTrue($result->count() > 0);
        $person = $Person->save(new AclPerson(['name' => 'Trent', 'mother_id' => 2, 'father_id' => 3]));
        $person = new AclPerson(['id' => 2], ['source' => $Person->alias(), 'markNew' => false]);
        $Person->delete($person);
        $result = $this->Aro->find('all', ['conditions' => ['model' => $Person->alias(), 'foreign_key' => $person->id]]);
        $this->assertTrue($result->count() === 0);
        $result = $this->Aro->find('all', ['conditions' => ['model' => $Person->alias(), 'foreign_key' => 2]]);
        $this->assertTrue($result->count() === 0);
    }