Пример #1
0
 public function testOneToMany()
 {
     SolutionSchema::registerSchema("MySchema", "Rhubarb\\Stem\\Tests\\Fixtures\\UnitTestingSolutionSchema");
     $company = new Company();
     $company->getRepository()->clearObjectCache();
     $company->CompanyName = "Test Company";
     $company->save();
     $user = new User();
     $user->getRepository()->clearObjectCache();
     $user->Username = "******";
     $user->Password = "******";
     $user->Active = 1;
     $user->CompanyID = $company->CompanyID;
     $user->save();
     $user = new User();
     $user->Username = "******";
     $user->Password = "";
     $user->Active = 1;
     $user->CompanyID = $company->CompanyID;
     $user->save();
     $user = new User();
     $user->Username = "******";
     $user->Password = "";
     $user->Active = 0;
     $user->CompanyID = $company->CompanyID;
     $user->save();
     $oneToMany = new OneToMany("Unused", "Company", "CompanyID", "UnitTestUser");
     $list = $oneToMany->fetchFor($company);
     $this->assertCount(2, $list);
     $this->assertEquals("msmith", $list[1]->Username);
 }
 public function testRelationships()
 {
     SolutionSchema::clearSchemas();
     SolutionSchema::registerSchema("MySchema", "Rhubarb\\Stem\\Tests\\Fixtures\\UnitTestingSolutionSchema");
     error_reporting(E_ALL);
     ini_set("display_errors", "on");
     $schema = new UnitTestingSolutionSchema();
     $schema->defineRelationships();
     $relationship = $schema->getRelationship("UnitTestUser", "Company");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $relationship);
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToMany", $relationship->getOtherSide());
     $relationship = $schema->getRelationship("Company", "Users");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToMany", $relationship);
     $relationship = $schema->getRelationship("Company", "Unknown");
     $this->assertNull($relationship);
     $relationship = $schema->getRelationship("Example", "ExampleRelationshipName");
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $relationship);
     $columnRelationships = SolutionSchema::getAllOneToOneRelationshipsForModelBySourceColumnName("UnitTestUser");
     $this->assertArrayHasKey("CompanyID", $columnRelationships);
     $this->assertInstanceOf("Rhubarb\\Stem\\Schema\\Relationships\\OneToOne", $columnRelationships["CompanyID"]);
     $company = new Company();
     $company->CompanyName = "GCD";
     $company->save();
     $user = new User();
     $user->getRepository()->clearObjectCache();
     $user->Forename = "a";
     $user->save();
     $company->Users->Append($user);
     $b = $user = new User();
     $user->Forename = "b";
     $user->save();
     $company->Users->Append($user);
     // Just to make sure this doesn't get in our relationship!
     $user = new User();
     $user->Forename = "c";
     $user->save();
     $company = new Company($company->CompanyID);
     $this->assertCount(2, $company->Users);
     $this->assertEquals("a", $company->Users[0]->Forename);
     $this->assertEquals("b", $company->Users[1]->Forename);
     $company = $b->Company;
     $this->assertEquals("GCD", $company->CompanyName);
 }