Example #1
0
 public function testDelete()
 {
     $this->given($this->newTestedInstance())->if($this->testedInstance->login = self::login())->if($this->testedInstance->password = self::DEFAULT_PASSWORD)->if($this->testedInstance->role = self::STUDENT_ROLE)->if($this->testedInstance->first_name = self::DEFAULT_FIRST_NAME)->if($this->testedInstance->last_name = self::DEFAULT_LAST_NAME)->if($this->testedInstance->date_of_birth = self::DEFAULT_DATE)->if($this->testedInstance->address = self::DEFAULT_ADDRESS)->if($this->testedInstance->phone = self::DEFAULT_PHONE_NUMBER)->if($this->testedInstance->email = $this->mailAddress())->if($this->testedInstance->valid = true)->then->boolean($this->testedInstance->save())->isTrue()->given($notif = new Notification())->if($notif->message = "hey")->if($notif->read = 1)->if($notif->creation_date = date('Y-m-d H:i:s'))->if($notif->target_user_id = $this->testedInstance->getId())->then->boolean($notif->save())->isTrue()->given(\website\model\User::delete($this->testedInstance->getId()))->then->variable(\website\model\User::findOneWhere(['id' => $this->testedInstance->getId()]))->isNull()->variable(Notification::findOneWhere(['id' => $notif->getId()]))->isNull();
     //TODO test with module subscription
 }
Example #2
0
 public static function delete($id)
 {
     $transactStarted = false;
     if (!self::db()->inTransaction()) {
         $transactStarted = true;
         self::db()->beginTransaction();
     }
     $queries = array();
     $queries[] = "DELETE FROM " . Notification::tableName() . " WHERE target_user_id = :id";
     $queries[] = "DELETE FROM " . StudentModuleSubscription::tableName() . " WHERE user_id = :id";
     $queries[] = "DELETE FROM " . TeacherModuleSubscription::tableName() . " WHERE user_id = :id";
     $queries[] = "DELETE FROM " . self::tableName() . " WHERE id = :id";
     foreach ($queries as &$query) {
         $st = self::db()->prepare($query);
         $st->execute(['id' => $id]);
     }
     if ($transactStarted && self::db()->inTransaction()) {
         self::db()->commit();
     }
 }