/ieducar/modules/Avaliacao/_tests/Service/NotaRecuperacaoTest.php

https://github.com/gtinfo/ieducar · PHP · 250 lines · 172 code · 36 blank · 42 comment · 0 complexity · a410cffe1e5ce2b110320767ec3e180f MD5 · raw file

  1. <?php
  2. /**
  3. * i-Educar - Sistema de gestão escolar
  4. *
  5. * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  6. * <ctima@itajai.sc.gov.br>
  7. *
  8. * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  9. * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  10. * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  11. * qualquer versão posterior.
  12. *
  13. * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  14. * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  15. * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  16. * do GNU para mais detalhes.
  17. *
  18. * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  19. * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  20. * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br>
  23. * @category i-Educar
  24. * @license @@license@@
  25. * @package Avaliacao
  26. * @subpackage UnitTests
  27. * @since Arquivo disponível desde a versão 1.1.0
  28. * @version $Id$
  29. */
  30. require_once 'Avaliacao/_tests/Service/TestCommon.php';
  31. /**
  32. * Avaliacao_Service_NotaRecuperacaoTest class.
  33. *
  34. * @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br>
  35. * @category i-Educar
  36. * @license @@license@@
  37. * @package Avaliacao
  38. * @subpackage UnitTests
  39. * @since Classe disponível desde a versão 1.1.0
  40. * @version @@package_version@@
  41. */
  42. class Avaliacao_Service_NotaRecuperacaoTest extends Avaliacao_Service_TestCommon
  43. {
  44. public function testSalvarNotasDeUmComponenteCurricularNoBoletimEmRecuperacao()
  45. {
  46. $notaAluno = $this->_getConfigOption('notaAluno', 'instance');
  47. $notas = array(
  48. new Avaliacao_Model_NotaComponente(array(
  49. 'componenteCurricular' => 1,
  50. 'nota' => 5,
  51. 'etapa' => 1
  52. )),
  53. new Avaliacao_Model_NotaComponente(array(
  54. 'componenteCurricular' => 1,
  55. 'nota' => 5,
  56. 'etapa' => 2
  57. )),
  58. new Avaliacao_Model_NotaComponente(array(
  59. 'componenteCurricular' => 1,
  60. 'nota' => 6,
  61. 'etapa' => 3
  62. )),
  63. new Avaliacao_Model_NotaComponente(array(
  64. 'componenteCurricular' => 1,
  65. 'nota' => 6,
  66. 'etapa' => 4
  67. )),
  68. new Avaliacao_Model_NotaComponente(array(
  69. 'componenteCurricular' => 1,
  70. 'nota' => 6,
  71. 'etapa' => 'Rc'
  72. )),
  73. );
  74. $media = new Avaliacao_Model_NotaComponenteMedia(array(
  75. 'notaAluno' => $notaAluno->id,
  76. 'componenteCurricular' => 1,
  77. 'media' => 5.7,
  78. 'mediaArredondada' => 5,
  79. 'etapa' => 'Rc'
  80. ));
  81. $media->markOld();
  82. // Configura mock para Avaliacao_Model_NotaComponenteDataMapper
  83. $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteDataMapper');
  84. $mock->expects($this->at(0))
  85. ->method('findAll')
  86. ->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))
  87. ->will($this->returnValue(array()));
  88. $mock->expects($this->at(1))
  89. ->method('save')
  90. ->with($notas[0])
  91. ->will($this->returnValue(TRUE));
  92. $mock->expects($this->at(2))
  93. ->method('save')
  94. ->with($notas[1])
  95. ->will($this->returnValue(TRUE));
  96. $mock->expects($this->at(3))
  97. ->method('save')
  98. ->with($notas[2])
  99. ->will($this->returnValue(TRUE));
  100. $mock->expects($this->at(4))
  101. ->method('save')
  102. ->with($notas[3])
  103. ->will($this->returnValue(TRUE));
  104. $mock->expects($this->at(5))
  105. ->method('save')
  106. ->with($notas[4])
  107. ->will($this->returnValue(TRUE));
  108. $mock->expects($this->at(6))
  109. ->method('findAll')
  110. ->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))
  111. ->will($this->returnValue($notas));
  112. $this->_setNotaComponenteDataMapperMock($mock);
  113. // Configura mock para Avaliacao_Model_NotaComponenteMediaDataMapper
  114. $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteMediaDataMapper');
  115. $mock->expects($this->at(0))
  116. ->method('findAll')
  117. ->with(array(), array('notaAluno' => $notaAluno->id))
  118. ->will($this->returnValue(array()));
  119. $mock->expects($this->at(1))
  120. ->method('find')
  121. ->with(array($notaAluno->id, $this->_getConfigOption('matricula', 'cod_matricula')))
  122. ->will($this->returnValue(array()));
  123. $mock->expects($this->at(2))
  124. ->method('save')
  125. ->with($media)
  126. ->will($this->returnValue(TRUE));
  127. $this->_setNotaComponenteMediaDataMapperMock($mock);
  128. $service = $this->_getServiceInstance();
  129. $service->addNotas($notas);
  130. $service->saveNotas();
  131. $notasSalvas = $service->getNotas();
  132. $etapas = array_merge(
  133. range(1, count($this->_getConfigOptions('anoLetivoModulo'))),
  134. array('Rc')
  135. );
  136. foreach ($notasSalvas as $notaSalva) {
  137. $key = array_search($notaSalva->etapa, $etapas, FALSE);
  138. $this->assertTrue($key !== FALSE);
  139. unset($etapas[$key]);
  140. }
  141. }
  142. public function testSalvarNotasDeUmComponenteCurricularNoBoletimEmRecuperacaoComNotasLancadas()
  143. {
  144. $notaAluno = $this->_getConfigOption('notaAluno', 'instance');
  145. $notas = array(
  146. new Avaliacao_Model_NotaComponente(array(
  147. 'componenteCurricular' => 1,
  148. 'nota' => 5,
  149. ))
  150. );
  151. $notasPersistidas = array(
  152. new Avaliacao_Model_NotaComponente(array(
  153. 'id' => 1,
  154. 'notaAluno' => $notaAluno->id,
  155. 'componenteCurricular' => 1,
  156. 'nota' => 6,
  157. 'notaArredondada' => 6,
  158. 'etapa' => 1
  159. )),
  160. new Avaliacao_Model_NotaComponente(array(
  161. 'id' => 2,
  162. 'notaAluno' => $notaAluno->id,
  163. 'componenteCurricular' => 1,
  164. 'nota' => 6,
  165. 'notaArredondada' => 6,
  166. 'etapa' => 2
  167. )),
  168. new Avaliacao_Model_NotaComponente(array(
  169. 'id' => 3,
  170. 'notaAluno' => $notaAluno->id,
  171. 'componenteCurricular' => 1,
  172. 'nota' => 6,
  173. 'notaArredondada' => 6,
  174. 'etapa' => 3
  175. )),
  176. new Avaliacao_Model_NotaComponente(array(
  177. 'id' => 4,
  178. 'notaAluno' => $notaAluno->id,
  179. 'componenteCurricular' => 1,
  180. 'nota' => 6,
  181. 'notaArredondada' => 6,
  182. 'etapa' => 4
  183. ))
  184. );
  185. // Configura mock para Avaliacao_Model_NotaComponenteDataMapper
  186. $mock = $this->getCleanMock('Avaliacao_Model_NotaComponenteDataMapper');
  187. $mock->expects($this->at(0))
  188. ->method('findAll')
  189. ->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))
  190. ->will($this->returnValue($notasPersistidas));
  191. $mock->expects($this->at(1))
  192. ->method('save')
  193. ->with($notas[0])
  194. ->will($this->returnValue(TRUE));
  195. $notasSalvas = array_merge($notasPersistidas, $notas);
  196. $mock->expects($this->at(2))
  197. ->method('findAll')
  198. ->with(array(), array('notaAluno' => $notaAluno->id), array('etapa' => 'ASC'))
  199. ->will($this->returnValue($notasSalvas));
  200. $this->_setNotaComponenteDataMapperMock($mock);
  201. $service = $this->_getServiceInstance();
  202. $service->addNotas($notas);
  203. $service->saveNotas();
  204. $etapas = array_merge(
  205. range(1, count($this->_getConfigOptions('anoLetivoModulo'))),
  206. array('Rc')
  207. );
  208. foreach ($notasSalvas as $notaSalva) {
  209. $key = array_search($notaSalva->etapa, $etapas, FALSE);
  210. $this->assertTrue($key !== FALSE);
  211. unset($etapas[$key]);
  212. }
  213. }
  214. }