public function testDoesOwnerHaveAccessToInstance() { $oi_data = array('owner_id' => 2, 'instance_id' => 20); $oinstances_builder = FixtureBuilder::build(self::TEST_TABLE_OI, $oi_data); $i_data = array('network_username' => 'mojojojo', 'id' => 20, 'network_user_id' => 'filler_data'); $instances_builder = FixtureBuilder::build(self::TEST_TABLE_I, $i_data); $dao = new OwnerInstanceMySQLDAO(); // no owner id or instance id try { $dao->doesOwnerHaveAccessToInstance(new Owner(), new Instance()); $this->fail("should throw BadArgumentException"); } catch (BadArgumentException $e) { $this->assertPattern('/requires an/', $e->getMessage()); } // no owner id try { $dao->doesOwnerHaveAccessToInstance(new Owner(), new Instance()); $this->fail("should throw BadArgumentException"); } catch (BadArgumentException $e) { $this->assertPattern('/requires an/', $e->getMessage()); } // no match $owner = new Owner(); $owner->id = 1; // no instance id try { $dao->doesOwnerHaveAccessToInstance($owner, new Instance()); $this->fail("should throw BadArgumentException"); } catch (BadArgumentException $e) { $this->assertPattern('/requires an/', $e->getMessage()); } $instance = new Instance(); $instance->id = 1; $this->assertFalse($dao->doesOwnerHaveAccessToInstance($owner, $instance), 'no access'); $owner->id = 2; $this->assertFalse($dao->doesOwnerHaveAccessToInstance($owner, $instance), 'no access'); // valid match $instance->id = 20; $this->assertTrue($dao->doesOwnerHaveAccessToInstance($owner, $instance), 'has access'); }