| @@ 262-271 (lines=10) @@ | ||
| 259 | /** |
|
| 260 | * @depends testDaoGeneration |
|
| 261 | */ |
|
| 262 | public function testAssigningExistingRelationship() |
|
| 263 | { |
|
| 264 | $userDao = new UserDao($this->tdbmService); |
|
| 265 | $user = $userDao->getById(1); |
|
| 266 | $countryDao = new CountryDao($this->tdbmService); |
|
| 267 | $country = $countryDao->getById(2); |
|
| 268 | ||
| 269 | $user->setCountry($country); |
|
| 270 | $this->assertEquals(TDBMObjectStateEnum::STATE_DIRTY, $user->_getStatus()); |
|
| 271 | } |
|
| 272 | ||
| 273 | /** |
|
| 274 | * @depends testDaoGeneration |
|
| @@ 376-389 (lines=14) @@ | ||
| 373 | /** |
|
| 374 | * @depends testDaoGeneration |
|
| 375 | */ |
|
| 376 | public function testJointureDeleteBeforeGetters() |
|
| 377 | { |
|
| 378 | $roleDao = new RoleDao($this->tdbmService); |
|
| 379 | $userDao = new UserDao($this->tdbmService); |
|
| 380 | $role = $roleDao->getById(1); |
|
| 381 | $user = $userDao->getById(1); |
|
| 382 | ||
| 383 | // We call removeUser BEFORE calling getUsers |
|
| 384 | // This should work as expected. |
|
| 385 | $role->removeUser($user); |
|
| 386 | $users = $role->getUsers(); |
|
| 387 | ||
| 388 | $this->assertCount(1, $users); |
|
| 389 | } |
|
| 390 | ||
| 391 | /** |
|
| 392 | * @depends testDaoGeneration |
|
| @@ 470-478 (lines=9) @@ | ||
| 467 | * |
|
| 468 | * @depends testJointureSave3 |
|
| 469 | */ |
|
| 470 | public function testJointureSave4() |
|
| 471 | { |
|
| 472 | $roleDao = new RoleDao($this->tdbmService); |
|
| 473 | $role = $roleDao->getById(1); |
|
| 474 | $this->assertCount(1, $role->getUsers()); |
|
| 475 | $userDao = new UserDao($this->tdbmService); |
|
| 476 | $user = $userDao->getById(1); |
|
| 477 | $this->assertCount(0, $user->getRoles()); |
|
| 478 | } |
|
| 479 | ||
| 480 | /** |
|
| 481 | * Step 5: we add the role 1 from user 1 and save user 1. |
|
| @@ 486-496 (lines=11) @@ | ||
| 483 | * |
|
| 484 | * @depends testJointureSave4 |
|
| 485 | */ |
|
| 486 | public function testJointureSave5() |
|
| 487 | { |
|
| 488 | $roleDao = new RoleDao($this->tdbmService); |
|
| 489 | $role = $roleDao->getById(1); |
|
| 490 | $userDao = new UserDao($this->tdbmService); |
|
| 491 | $user = $userDao->getById(1); |
|
| 492 | ||
| 493 | $user->addRole($role); |
|
| 494 | $this->assertCount(1, $user->getRoles()); |
|
| 495 | $userDao->save($user); |
|
| 496 | } |
|
| 497 | ||
| 498 | /** |
|
| 499 | * Step 6: we check that save was done |
|
| @@ 504-512 (lines=9) @@ | ||
| 501 | * |
|
| 502 | * @depends testJointureSave5 |
|
| 503 | */ |
|
| 504 | public function testJointureSave6() |
|
| 505 | { |
|
| 506 | $roleDao = new RoleDao($this->tdbmService); |
|
| 507 | $role = $roleDao->getById(1); |
|
| 508 | $this->assertCount(2, $role->getUsers()); |
|
| 509 | $userDao = new UserDao($this->tdbmService); |
|
| 510 | $user = $userDao->getById(1); |
|
| 511 | $this->assertCount(1, $user->getRoles()); |
|
| 512 | } |
|
| 513 | ||
| 514 | /** |
|
| 515 | * Step 7: we add a new role to user 1 and save user 1. |
|