/**
  * @depends testGetByBoxAndTypeForNotificationsBox
  */
 public function testSetAndGetFolder()
 {
     $billy = User::getByUsername('billy');
     Yii::app()->user->userModel = $billy;
     $folders = EmailFolder::getAll();
     $this->assertEquals(8, count($folders));
     $box = new EmailBox();
     $box->name = 'Some new mailbox';
     $saved = $box->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, $box->folders->count());
     $folder = new EmailFolder();
     $folder->name = 'Billy\'s Inbox';
     $folder->type = EmailFolder::TYPE_INBOX;
     $saved = $folder->save();
     //Missing 'box', so it should not save
     $this->assertFalse($saved);
     $folder->emailBox = $box;
     $saved = $folder->save();
     $this->assertTrue($saved);
     $folderId = $folder->id;
     $folder->forget();
     unset($folder);
     $folder = EmailFolder::getById($folderId);
     $this->assertEquals($box->id, $folder->emailBox->id);
     //Now check the box has the correct folder related to it
     $boxId = $box->id;
     $box->forget();
     unset($box);
     $box = EmailBox::getById($boxId);
     $this->assertEquals(1, $box->folders->count());
     $this->assertEquals('Billy\'s Inbox', $box->folders[0]->name);
     $this->assertEquals(EmailFolder::TYPE_INBOX, $box->folders[0]->type);
     $folders = EmailFolder::getAll();
     $this->assertEquals(9, count($folders));
     //Now delete billy's inbox
     $folder->delete();
     $folders = EmailFolder::getAll();
     $this->assertEquals(8, count($folders));
     $box->forget();
     unset($box);
     $box = EmailBox::getById($boxId);
     $this->assertEquals(0, $box->folders->count());
 }