FieldGroupTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. namespace Symfony\Tests\Component\Form;
  3. require_once __DIR__ . '/Fixtures/Author.php';
  4. require_once __DIR__ . '/Fixtures/TestField.php';
  5. require_once __DIR__ . '/Fixtures/TestFieldGroup.php';
  6. use Symfony\Component\Form\Field;
  7. use Symfony\Component\Form\FieldError;
  8. use Symfony\Component\Form\FieldInterface;
  9. use Symfony\Component\Form\FieldGroup;
  10. use Symfony\Component\Form\PropertyPath;
  11. use Symfony\Tests\Component\Form\Fixtures\Author;
  12. use Symfony\Tests\Component\Form\Fixtures\TestField;
  13. use Symfony\Tests\Component\Form\Fixtures\TestFieldGroup;
  14. abstract class FieldGroupTest_Field extends TestField
  15. {
  16. public $locales = array();
  17. public function setLocale($locale)
  18. {
  19. $this->locales[] = $locale;
  20. }
  21. }
  22. class FieldGroupTest extends \PHPUnit_Framework_TestCase
  23. {
  24. public function testSupportsArrayAccess()
  25. {
  26. $group = new TestFieldGroup('author');
  27. $group->add($this->createMockField('firstName'));
  28. $this->assertEquals($group->get('firstName'), $group['firstName']);
  29. $this->assertTrue(isset($group['firstName']));
  30. }
  31. public function testSupportsUnset()
  32. {
  33. $group = new TestFieldGroup('author');
  34. $group->add($this->createMockField('firstName'));
  35. unset($group['firstName']);
  36. $this->assertFalse(isset($group['firstName']));
  37. }
  38. public function testDoesNotSupportAddingFields()
  39. {
  40. $group = new TestFieldGroup('author');
  41. $this->setExpectedException('LogicException');
  42. $group[] = $this->createMockField('lastName');
  43. }
  44. public function testSupportsCountable()
  45. {
  46. $group = new TestFieldGroup('group');
  47. $group->add($this->createMockField('firstName'));
  48. $group->add($this->createMockField('lastName'));
  49. $this->assertEquals(2, count($group));
  50. $group->add($this->createMockField('australian'));
  51. $this->assertEquals(3, count($group));
  52. }
  53. public function testSupportsIterable()
  54. {
  55. $group = new TestFieldGroup('group');
  56. $group->add($field1 = $this->createMockField('field1'));
  57. $group->add($field2 = $this->createMockField('field2'));
  58. $group->add($field3 = $this->createMockField('field3'));
  59. $expected = array(
  60. 'field1' => $field1,
  61. 'field2' => $field2,
  62. 'field3' => $field3,
  63. );
  64. $this->assertEquals($expected, iterator_to_array($group));
  65. }
  66. public function testIsBound()
  67. {
  68. $group = new TestFieldGroup('author');
  69. $this->assertFalse($group->isBound());
  70. $group->bind(array('firstName' => 'Bernhard'));
  71. $this->assertTrue($group->isBound());
  72. }
  73. public function testValidIfAllFieldsAreValid()
  74. {
  75. $group = new TestFieldGroup('author');
  76. $group->add($this->createValidMockField('firstName'));
  77. $group->add($this->createValidMockField('lastName'));
  78. $group->bind(array('firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  79. $this->assertTrue($group->isValid());
  80. }
  81. public function testInvalidIfFieldIsInvalid()
  82. {
  83. $group = new TestFieldGroup('author');
  84. $group->add($this->createInvalidMockField('firstName'));
  85. $group->add($this->createValidMockField('lastName'));
  86. $group->bind(array('firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  87. $this->assertFalse($group->isValid());
  88. }
  89. public function testInvalidIfBoundWithExtraFields()
  90. {
  91. $group = new TestFieldGroup('author');
  92. $group->add($this->createValidMockField('firstName'));
  93. $group->add($this->createValidMockField('lastName'));
  94. $group->bind(array('foo' => 'bar', 'firstName' => 'Bernhard', 'lastName' => 'Potencier'));
  95. $this->assertTrue($group->isBoundWithExtraFields());
  96. }
  97. public function testHasNoErrorsIfOnlyFieldHasErrors()
  98. {
  99. $group = new TestFieldGroup('author');
  100. $group->add($this->createInvalidMockField('firstName'));
  101. $group->bind(array('firstName' => 'Bernhard'));
  102. $this->assertFalse($group->hasErrors());
  103. }
  104. public function testBindForwardsPreprocessedData()
  105. {
  106. $field = $this->createMockField('firstName');
  107. $group = $this->getMock(
  108. 'Symfony\Tests\Component\Form\Fixtures\TestFieldGroup',
  109. array('preprocessData'), // only mock preprocessData()
  110. array('author')
  111. );
  112. // The data array is prepared directly after binding
  113. $group->expects($this->once())
  114. ->method('preprocessData')
  115. ->with($this->equalTo(array('firstName' => 'Bernhard')))
  116. ->will($this->returnValue(array('firstName' => 'preprocessed[Bernhard]')));
  117. $group->add($field);
  118. // The preprocessed data is then forwarded to the fields
  119. $field->expects($this->once())
  120. ->method('bind')
  121. ->with($this->equalTo('preprocessed[Bernhard]'));
  122. $group->bind(array('firstName' => 'Bernhard'));
  123. }
  124. public function testBindForwardsNullIfValueIsMissing()
  125. {
  126. $field = $this->createMockField('firstName');
  127. $field->expects($this->once())
  128. ->method('bind')
  129. ->with($this->equalTo(null));
  130. $group = new TestFieldGroup('author');
  131. $group->add($field);
  132. $group->bind(array());
  133. }
  134. public function testAddErrorMapsFieldValidationErrorsOntoFields()
  135. {
  136. $error = new FieldError('Message');
  137. $field = $this->createMockField('firstName');
  138. $field->expects($this->once())
  139. ->method('addError')
  140. ->with($this->equalTo($error));
  141. $group = new TestFieldGroup('author');
  142. $group->add($field);
  143. $path = new PropertyPath('fields[firstName].data');
  144. $group->addError($error, $path->getIterator(), FieldGroup::FIELD_ERROR);
  145. }
  146. public function testAddErrorMapsFieldValidationErrorsOntoFieldsWithinNestedFieldGroups()
  147. {
  148. $error = new FieldError('Message');
  149. $field = $this->createMockField('firstName');
  150. $field->expects($this->once())
  151. ->method('addError')
  152. ->with($this->equalTo($error));
  153. $group = new TestFieldGroup('author');
  154. $innerGroup = new TestFieldGroup('names');
  155. $innerGroup->add($field);
  156. $group->add($innerGroup);
  157. $path = new PropertyPath('fields[names].fields[firstName].data');
  158. $group->addError($error, $path->getIterator(), FieldGroup::FIELD_ERROR);
  159. }
  160. public function testAddErrorKeepsFieldValidationErrorsIfFieldNotFound()
  161. {
  162. $error = new FieldError('Message');
  163. $field = $this->createMockField('foo');
  164. $field->expects($this->never())
  165. ->method('addError');
  166. $group = new TestFieldGroup('author');
  167. $group->add($field);
  168. $path = new PropertyPath('fields[bar].data');
  169. $group->addError($error, $path->getIterator(), FieldGroup::FIELD_ERROR);
  170. $this->assertEquals(array($error), $group->getErrors());
  171. }
  172. public function testAddErrorKeepsFieldValidationErrorsIfFieldIsHidden()
  173. {
  174. $error = new FieldError('Message');
  175. $field = $this->createMockField('firstName');
  176. $field->expects($this->any())
  177. ->method('isHidden')
  178. ->will($this->returnValue(true));
  179. $field->expects($this->never())
  180. ->method('addError');
  181. $group = new TestFieldGroup('author');
  182. $group->add($field);
  183. $path = new PropertyPath('fields[firstName].data');
  184. $group->addError($error, $path->getIterator(), FieldGroup::FIELD_ERROR);
  185. $this->assertEquals(array($error), $group->getErrors());
  186. }
  187. public function testAddErrorMapsDataValidationErrorsOntoFields()
  188. {
  189. $error = new FieldError('Message');
  190. // path is expected to point at "firstName"
  191. $expectedPath = new PropertyPath('firstName');
  192. $expectedPathIterator = $expectedPath->getIterator();
  193. $field = $this->createMockField('firstName');
  194. $field->expects($this->any())
  195. ->method('getPropertyPath')
  196. ->will($this->returnValue(new PropertyPath('firstName')));
  197. $field->expects($this->once())
  198. ->method('addError')
  199. ->with($this->equalTo($error), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  200. $group = new TestFieldGroup('author');
  201. $group->add($field);
  202. $path = new PropertyPath('firstName');
  203. $group->addError($error, $path->getIterator(), FieldGroup::DATA_ERROR);
  204. }
  205. public function testAddErrorKeepsDataValidationErrorsIfFieldNotFound()
  206. {
  207. $error = new FieldError('Message');
  208. $field = $this->createMockField('foo');
  209. $field->expects($this->any())
  210. ->method('getPropertyPath')
  211. ->will($this->returnValue(new PropertyPath('foo')));
  212. $field->expects($this->never())
  213. ->method('addError');
  214. $group = new TestFieldGroup('author');
  215. $group->add($field);
  216. $path = new PropertyPath('bar');
  217. $group->addError($error, $path->getIterator(), FieldGroup::DATA_ERROR);
  218. }
  219. public function testAddErrorKeepsDataValidationErrorsIfFieldIsHidden()
  220. {
  221. $error = new FieldError('Message');
  222. $field = $this->createMockField('firstName');
  223. $field->expects($this->any())
  224. ->method('isHidden')
  225. ->will($this->returnValue(true));
  226. $field->expects($this->any())
  227. ->method('getPropertyPath')
  228. ->will($this->returnValue(new PropertyPath('firstName')));
  229. $field->expects($this->never())
  230. ->method('addError');
  231. $group = new TestFieldGroup('author');
  232. $group->add($field);
  233. $path = new PropertyPath('firstName');
  234. $group->addError($error, $path->getIterator(), FieldGroup::DATA_ERROR);
  235. }
  236. public function testAddErrorMapsDataValidationErrorsOntoNestedFields()
  237. {
  238. $error = new FieldError('Message');
  239. // path is expected to point at "street"
  240. $expectedPath = new PropertyPath('address.street');
  241. $expectedPathIterator = $expectedPath->getIterator();
  242. $expectedPathIterator->next();
  243. $field = $this->createMockField('address');
  244. $field->expects($this->any())
  245. ->method('getPropertyPath')
  246. ->will($this->returnValue(new PropertyPath('address')));
  247. $field->expects($this->once())
  248. ->method('addError')
  249. ->with($this->equalTo($error), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  250. $group = new TestFieldGroup('author');
  251. $group->add($field);
  252. $path = new PropertyPath('address.street');
  253. $group->addError($error, $path->getIterator(), FieldGroup::DATA_ERROR);
  254. }
  255. public function testAddErrorMapsErrorsOntoFieldsInAnonymousGroups()
  256. {
  257. $error = new FieldError('Message');
  258. // path is expected to point at "address"
  259. $expectedPath = new PropertyPath('address');
  260. $expectedPathIterator = $expectedPath->getIterator();
  261. $field = $this->createMockField('address');
  262. $field->expects($this->any())
  263. ->method('getPropertyPath')
  264. ->will($this->returnValue(new PropertyPath('address')));
  265. $field->expects($this->once())
  266. ->method('addError')
  267. ->with($this->equalTo($error), $this->equalTo($expectedPathIterator), $this->equalTo(FieldGroup::DATA_ERROR));
  268. $group = new TestFieldGroup('author');
  269. $group2 = new TestFieldGroup('anonymous', array('property_path' => null));
  270. $group2->add($field);
  271. $group->add($group2);
  272. $path = new PropertyPath('address');
  273. $group->addError($error, $path->getIterator(), FieldGroup::DATA_ERROR);
  274. }
  275. public function testAddThrowsExceptionIfAlreadyBound()
  276. {
  277. $group = new TestFieldGroup('author');
  278. $group->add($this->createMockField('firstName'));
  279. $group->bind(array('firstName' => 'Bernhard'));
  280. $this->setExpectedException('Symfony\Component\Form\Exception\AlreadyBoundException');
  281. $group->add($this->createMockField('lastName'));
  282. }
  283. public function testAddSetsFieldParent()
  284. {
  285. $group = new TestFieldGroup('author');
  286. $field = $this->createMockField('firstName');
  287. $field->expects($this->once())
  288. ->method('setParent');
  289. // PHPUnit fails to compare infinitely recursive objects
  290. //->with($this->equalTo($group));
  291. $group->add($field);
  292. }
  293. public function testRemoveUnsetsFieldParent()
  294. {
  295. $group = new TestFieldGroup('author');
  296. $field = $this->createMockField('firstName');
  297. $field->expects($this->exactly(2))
  298. ->method('setParent');
  299. // PHPUnit fails to compare subsequent method calls with different arguments
  300. $group->add($field);
  301. $group->remove('firstName');
  302. }
  303. public function testAddUpdatesFieldFromTransformedData()
  304. {
  305. $originalAuthor = new Author();
  306. $transformedAuthor = new Author();
  307. // the authors should differ to make sure the test works
  308. $transformedAuthor->firstName = 'Foo';
  309. $group = new TestFieldGroup('author');
  310. $transformer = $this->createMockTransformer();
  311. $transformer->expects($this->once())
  312. ->method('transform')
  313. ->with($this->equalTo($originalAuthor))
  314. ->will($this->returnValue($transformedAuthor));
  315. $group->setValueTransformer($transformer);
  316. $group->setData($originalAuthor);
  317. $field = $this->createMockField('firstName');
  318. $field->expects($this->any())
  319. ->method('getPropertyPath')
  320. ->will($this->returnValue(new PropertyPath('firstName')));
  321. $field->expects($this->once())
  322. ->method('updateFromProperty')
  323. ->with($this->equalTo($transformedAuthor));
  324. $group->add($field);
  325. }
  326. public function testAddDoesNotUpdateFieldIfTransformedDataIsEmpty()
  327. {
  328. $originalAuthor = new Author();
  329. $group = new TestFieldGroup('author');
  330. $transformer = $this->createMockTransformer();
  331. $transformer->expects($this->once())
  332. ->method('transform')
  333. ->with($this->equalTo($originalAuthor))
  334. ->will($this->returnValue(''));
  335. $group->setValueTransformer($transformer);
  336. $group->setData($originalAuthor);
  337. $field = $this->createMockField('firstName');
  338. $field->expects($this->never())
  339. ->method('updateFromProperty');
  340. $group->add($field);
  341. }
  342. public function testSetDataUpdatesAllFieldsFromTransformedData()
  343. {
  344. $originalAuthor = new Author();
  345. $transformedAuthor = new Author();
  346. // the authors should differ to make sure the test works
  347. $transformedAuthor->firstName = 'Foo';
  348. $group = new TestFieldGroup('author');
  349. $transformer = $this->createMockTransformer();
  350. $transformer->expects($this->once())
  351. ->method('transform')
  352. ->with($this->equalTo($originalAuthor))
  353. ->will($this->returnValue($transformedAuthor));
  354. $group->setValueTransformer($transformer);
  355. $field = $this->createMockField('firstName');
  356. $field->expects($this->once())
  357. ->method('updateFromProperty')
  358. ->with($this->equalTo($transformedAuthor));
  359. $group->add($field);
  360. $field = $this->createMockField('lastName');
  361. $field->expects($this->once())
  362. ->method('updateFromProperty')
  363. ->with($this->equalTo($transformedAuthor));
  364. $group->add($field);
  365. $group->setData($originalAuthor);
  366. }
  367. public function testSetDataThrowsAnExceptionIfArgumentIsNotObjectOrArray()
  368. {
  369. $group = new TestFieldGroup('author');
  370. $this->setExpectedException('InvalidArgumentException');
  371. $group->setData('foobar');
  372. }
  373. public function testBindUpdatesTransformedDataFromAllFields()
  374. {
  375. $originalAuthor = new Author();
  376. $transformedAuthor = new Author();
  377. // the authors should differ to make sure the test works
  378. $transformedAuthor->firstName = 'Foo';
  379. $group = new TestFieldGroup('author');
  380. $transformer = $this->createMockTransformer();
  381. $transformer->expects($this->exactly(2))
  382. ->method('transform')
  383. // the method is first called with NULL, then
  384. // with $originalAuthor -> not testable by PHPUnit
  385. // ->with($this->equalTo(null))
  386. // ->with($this->equalTo($originalAuthor))
  387. ->will($this->returnValue($transformedAuthor));
  388. $group->setValueTransformer($transformer);
  389. $group->setData($originalAuthor);
  390. $field = $this->createMockField('firstName');
  391. $field->expects($this->once())
  392. ->method('updateProperty')
  393. ->with($this->equalTo($transformedAuthor));
  394. $group->add($field);
  395. $field = $this->createMockField('lastName');
  396. $field->expects($this->once())
  397. ->method('updateProperty')
  398. ->with($this->equalTo($transformedAuthor));
  399. $group->add($field);
  400. $group->bind(array()); // irrelevant
  401. }
  402. public function testGetDataReturnsObject()
  403. {
  404. $group = new TestFieldGroup('author');
  405. $object = new \stdClass();
  406. $group->setData($object);
  407. $this->assertEquals($object, $group->getData());
  408. }
  409. public function testGetDisplayedDataForwardsCall()
  410. {
  411. $field = $this->createValidMockField('firstName');
  412. $field->expects($this->atLeastOnce())
  413. ->method('getDisplayedData')
  414. ->will($this->returnValue('Bernhard'));
  415. $group = new TestFieldGroup('author');
  416. $group->add($field);
  417. $this->assertEquals(array('firstName' => 'Bernhard'), $group->getDisplayedData());
  418. }
  419. public function testIsMultipartIfAnyFieldIsMultipart()
  420. {
  421. $group = new TestFieldGroup('author');
  422. $group->add($this->createMultipartMockField('firstName'));
  423. $group->add($this->createNonMultipartMockField('lastName'));
  424. $this->assertTrue($group->isMultipart());
  425. }
  426. public function testIsNotMultipartIfNoFieldIsMultipart()
  427. {
  428. $group = new TestFieldGroup('author');
  429. $group->add($this->createNonMultipartMockField('firstName'));
  430. $group->add($this->createNonMultipartMockField('lastName'));
  431. $this->assertFalse($group->isMultipart());
  432. }
  433. public function testLocaleIsPassedToField_SetBeforeAddingTheField()
  434. {
  435. $field = $this->getMock('Symfony\Component\Form\Field', array(), array(), '', false, false);
  436. $field->expects($this->any())
  437. ->method('getKey')
  438. ->will($this->returnValue('firstName'));
  439. $field->expects($this->once())
  440. ->method('setLocale')
  441. ->with($this->equalTo('de_DE'));
  442. $group = new TestFieldGroup('author');
  443. $group->setLocale('de_DE');
  444. $group->add($field);
  445. }
  446. public function testLocaleIsPassedToField_SetAfterAddingTheField()
  447. {
  448. $field = $this->getMockForAbstractClass(__NAMESPACE__ . '\FieldGroupTest_Field', array(), '', false, false);
  449. $field->expects($this->any())
  450. ->method('getKey')
  451. ->will($this->returnValue('firstName'));
  452. // DOESN'T WORK!
  453. // $field = $this->getMock(__NAMESPACE__ . '\Fixtures\Field', array(), array(), '', false, false);
  454. // $field->expects($this->once())
  455. // ->method('setLocale')
  456. // ->with($this->equalTo('de_AT'));
  457. // $field->expects($this->once())
  458. // ->method('setLocale')
  459. // ->with($this->equalTo('de_DE'));
  460. $group = new TestFieldGroup('author');
  461. $group->add($field);
  462. $group->setLocale('de_DE');
  463. $this->assertEquals(array(class_exists('\Locale', false) ? \Locale::getDefault() : 'en', 'de_DE'), $field->locales);
  464. }
  465. public function testSupportsClone()
  466. {
  467. $group = new TestFieldGroup('author');
  468. $group->add($this->createMockField('firstName'));
  469. $clone = clone $group;
  470. $this->assertNotSame($clone['firstName'], $group['firstName']);
  471. }
  472. public function testBindWithoutPriorSetData()
  473. {
  474. return; // TODO
  475. $field = $this->createMockField('firstName');
  476. $field->expects($this->any())
  477. ->method('getData')
  478. ->will($this->returnValue('Bernhard'));
  479. $group = new TestFieldGroup('author');
  480. $group->add($field);
  481. $group->bind(array('firstName' => 'Bernhard'));
  482. $this->assertEquals(array('firstName' => 'Bernhard'), $group->getData());
  483. }
  484. public function testGetHiddenFieldsReturnsOnlyHiddenFields()
  485. {
  486. $group = $this->getGroupWithBothVisibleAndHiddenField();
  487. $hiddenFields = $group->getHiddenFields(true, false);
  488. $this->assertSame(array($group['hiddenField']), $hiddenFields);
  489. }
  490. public function testGetVisibleFieldsReturnsOnlyVisibleFields()
  491. {
  492. $group = $this->getGroupWithBothVisibleAndHiddenField();
  493. $visibleFields = $group->getVisibleFields(true, false);
  494. $this->assertSame(array($group['visibleField']), $visibleFields);
  495. }
  496. /**
  497. * Create a group containing two fields, "visibleField" and "hiddenField"
  498. *
  499. * @return FieldGroup
  500. */
  501. protected function getGroupWithBothVisibleAndHiddenField()
  502. {
  503. $group = new TestFieldGroup('testGroup');
  504. // add a visible field
  505. $visibleField = $this->createMockField('visibleField');
  506. $visibleField->expects($this->once())
  507. ->method('isHidden')
  508. ->will($this->returnValue(false));
  509. $group->add($visibleField);
  510. // add a hidden field
  511. $hiddenField = $this->createMockField('hiddenField');
  512. $hiddenField->expects($this->once())
  513. ->method('isHidden')
  514. ->will($this->returnValue(true));
  515. $group->add($hiddenField);
  516. return $group;
  517. }
  518. protected function createMockField($key)
  519. {
  520. $field = $this->getMock(
  521. 'Symfony\Component\Form\FieldInterface',
  522. array(),
  523. array(),
  524. '',
  525. false, // don't use constructor
  526. false // don't call parent::__clone
  527. );
  528. $field->expects($this->any())
  529. ->method('getKey')
  530. ->will($this->returnValue($key));
  531. return $field;
  532. }
  533. protected function createInvalidMockField($key)
  534. {
  535. $field = $this->createMockField($key);
  536. $field->expects($this->any())
  537. ->method('isValid')
  538. ->will($this->returnValue(false));
  539. return $field;
  540. }
  541. protected function createValidMockField($key)
  542. {
  543. $field = $this->createMockField($key);
  544. $field->expects($this->any())
  545. ->method('isValid')
  546. ->will($this->returnValue(true));
  547. return $field;
  548. }
  549. protected function createNonMultipartMockField($key)
  550. {
  551. $field = $this->createMockField($key);
  552. $field->expects($this->any())
  553. ->method('isMultipart')
  554. ->will($this->returnValue(false));
  555. return $field;
  556. }
  557. protected function createMultipartMockField($key)
  558. {
  559. $field = $this->createMockField($key);
  560. $field->expects($this->any())
  561. ->method('isMultipart')
  562. ->will($this->returnValue(true));
  563. return $field;
  564. }
  565. protected function createMockTransformer()
  566. {
  567. return $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface', array(), array(), '', false, false);
  568. }
  569. }