/** * Check right on Recursive object */ public function testPrinter() { global $DB; $DB->connect(); $ent0 = $this->sharedFixture['entity'][0]; $ent1 = $this->sharedFixture['entity'][1]; $ent2 = $this->sharedFixture['entity'][2]; $printer = new Printer(); $id[0] = $printer->add(array('name' => "Printer 1", 'entities_id' => $ent0, 'is_recursive' => 0)); $this->assertGreaterThan(0, $id[0], "Fail to create Printer 1"); $id[1] = $printer->add(array('name' => "Printer 2", 'entities_id' => $ent0, 'is_recursive' => 1)); $this->assertGreaterThan(0, $id[1], "Fail to create Printer 2"); $id[2] = $printer->add(array('name' => "Printer 3", 'entities_id' => $ent1, 'is_recursive' => 1)); $this->assertGreaterThan(0, $id[2], "Fail to create Ptiner 3"); $id[3] = $printer->add(array('name' => "Printer 4", 'entities_id' => $ent2)); $this->assertGreaterThan(0, $id[3], "Fail to create Printer 4"); // Super admin Session::changeProfile(4); $this->assertEquals(4, $_SESSION['glpiactiveprofile']['id']); $this->assertEquals(31, $_SESSION['glpiactiveprofile']['printer']); // See all $this->assertTrue(Session::changeActiveEntities("all")); $this->assertTrue($printer->can($id[0], READ), "Fail can read Printer 1"); $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2"); $this->assertTrue($printer->can($id[2], READ), "Fail can read Printer 3"); $this->assertTrue($printer->can($id[3], READ), "Fail can read Printer 4"); $this->assertTrue($printer->canEdit($id[0]), "Fail can write Printer 1"); $this->assertTrue($printer->canEdit($id[1]), "Fail can write Printer 2"); $this->assertTrue($printer->canEdit($id[2]), "Fail can write Printer 3"); $this->assertTrue($printer->canEdit($id[3]), "Fail can write Printer 4"); // See only in main entity $this->assertTrue(Session::changeActiveEntities($ent0)); $this->assertTrue($printer->can($id[0], READ), "Fail can read Printer 1"); $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2"); $this->assertFalse($printer->can($id[2], READ), "Fail can't read Printer 3"); $this->assertFalse($printer->can($id[3], READ), "Fail can't read Printer 1"); $this->assertTrue($printer->canEdit($id[0]), "Fail can write Printer 1"); $this->assertTrue($printer->canEdit($id[1]), "Fail can write Printer 2"); $this->assertFalse($printer->canEdit($id[2]), "Fail can't write Printer 1"); $this->assertFalse($printer->canEdit($id[3]), "Fail can't write Printer 1"); // See only in child entity 1 + parent if recursive $this->assertTrue(Session::changeActiveEntities($ent1)); $this->assertFalse($printer->can($id[0], READ), "Fail can't read Printer 1"); $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2"); $this->assertTrue($printer->can($id[2], READ), "Fail can read Printer 3"); $this->assertFalse($printer->can($id[3], READ), "Fail can't read Printer 4"); $this->assertFalse($printer->canEdit($id[0]), "Fail can't write Printer 1"); $this->assertFalse($printer->canEdit($id[1]), "Fail can't write Printer 2"); $this->assertTrue($printer->canEdit($id[2]), "Fail can write Printer 2"); $this->assertFalse($printer->canEdit($id[3]), "Fail can't write Printer 2"); // See only in child entity 2 + parent if recursive $this->assertTrue(Session::changeActiveEntities($ent2)); $this->assertFalse($printer->can($id[0], READ), "Fail can't read Printer 1"); $this->assertTrue($printer->can($id[1], READ), "Fail can read Printer 2"); $this->assertFalse($printer->can($id[2], READ), "Fail can't read Printer 3"); $this->assertTrue($printer->can($id[3], READ), "Fail can read Printer 4"); $this->assertFalse($printer->canEdit($id[0]), "Fail can't write Printer 1"); $this->assertFalse($printer->canEdit($id[1]), "Fail can't write Printer 2"); $this->assertFalse($printer->canEdit($id[2]), "Fail can't write Printer 3"); $this->assertTrue($printer->canEdit($id[3]), "Fail can write Printer 4"); }