FieldGroupTest.php 24 KB

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