FormStateDecoratorBaseTest.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  1. <?php
  2. namespace Drupal\Tests\Core\Form;
  3. use Drupal\Core\Form\FormInterface;
  4. use Drupal\Core\Form\FormStateDecoratorBase;
  5. use Drupal\Core\Form\FormStateInterface;
  6. use Drupal\Core\Url;
  7. use Drupal\Tests\UnitTestCase;
  8. use Prophecy\Argument;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Response;
  11. /**
  12. * @coversDefaultClass \Drupal\Core\Form\FormStateDecoratorBase
  13. *
  14. * @group Form
  15. */
  16. class FormStateDecoratorBaseTest extends UnitTestCase {
  17. /**
  18. * The decorated form state.
  19. *
  20. * @var \Drupal\Core\Form\FormStateInterface|\Prophecy\Prophecy\ObjectProphecy
  21. */
  22. protected $decoratedFormState;
  23. /**
  24. * The form state decorator base under test.
  25. *
  26. * @var \Drupal\Core\Form\FormStateDecoratorBase
  27. */
  28. protected $formStateDecoratorBase;
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function setUp() {
  33. parent::setUp();
  34. $this->decoratedFormState = $this->prophesize(FormStateInterface::class);
  35. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($this->decoratedFormState->reveal());
  36. }
  37. /**
  38. * Provides data to test methods that take a single boolean argument.
  39. */
  40. public function providerSingleBooleanArgument() {
  41. return [
  42. [TRUE],
  43. [FALSE],
  44. ];
  45. }
  46. /**
  47. * @covers ::setFormState
  48. */
  49. public function testSetFormState() {
  50. $form_state_additions = [
  51. 'foo' => 'bar',
  52. ];
  53. $this->decoratedFormState->setFormState($form_state_additions)
  54. ->shouldBeCalled();
  55. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormState($form_state_additions));
  56. }
  57. /**
  58. * @covers ::setAlwaysProcess
  59. *
  60. * @dataProvider providerSingleBooleanArgument
  61. *
  62. * @param bool $always_process
  63. */
  64. public function testSetAlwaysProcess($always_process) {
  65. $this->decoratedFormState->setAlwaysProcess($always_process)
  66. ->shouldBeCalled();
  67. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setAlwaysProcess($always_process));
  68. }
  69. /**
  70. * @covers ::getAlwaysProcess
  71. *
  72. * @dataProvider providerSingleBooleanArgument
  73. *
  74. * @param bool $always_process
  75. */
  76. public function testGetAlwaysProcess($always_process) {
  77. $this->decoratedFormState->getAlwaysProcess()
  78. ->willReturn($always_process)
  79. ->shouldBeCalled();
  80. $this->assertSame($always_process, $this->formStateDecoratorBase->getAlwaysProcess());
  81. }
  82. /**
  83. * @covers ::setButtons
  84. */
  85. public function testSetButtons() {
  86. $buttons = [
  87. 'FOO' => 'BAR',
  88. ];
  89. $this->decoratedFormState->setButtons($buttons)
  90. ->shouldBeCalled();
  91. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setButtons($buttons));
  92. }
  93. /**
  94. * @covers ::getButtons
  95. */
  96. public function testGetButtons() {
  97. $buttons = [
  98. 'FOO' => 'BAR',
  99. ];
  100. $this->decoratedFormState->getButtons()
  101. ->willReturn($buttons)
  102. ->shouldBeCalled();
  103. $this->assertSame($buttons, $this->formStateDecoratorBase->getButtons());
  104. }
  105. /**
  106. * @covers ::setCached
  107. *
  108. * @dataProvider providerSingleBooleanArgument
  109. *
  110. * @param bool $cache
  111. */
  112. public function testSetCached($cache) {
  113. $this->decoratedFormState->setCached($cache)
  114. ->shouldBeCalled();
  115. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCached($cache));
  116. }
  117. /**
  118. * @covers ::isCached
  119. *
  120. * @dataProvider providerSingleBooleanArgument
  121. *
  122. * @param bool $cache
  123. */
  124. public function testIsCached($cache) {
  125. $this->decoratedFormState->isCached()
  126. ->willReturn($cache)
  127. ->shouldBeCalled();
  128. $this->assertSame($cache, $this->formStateDecoratorBase->isCached());
  129. }
  130. /**
  131. * @covers ::setCached
  132. *
  133. * @dataProvider providerSingleBooleanArgument
  134. *
  135. * @param bool $cache
  136. */
  137. public function testSetCachedWithLogicException($cache) {
  138. $this->decoratedFormState->setCached($cache)
  139. ->willThrow(\LogicException::class);
  140. $this->expectException(\LogicException::class);
  141. $this->formStateDecoratorBase->setCached($cache);
  142. }
  143. /**
  144. * @covers ::disableCache
  145. */
  146. public function testDisableCache() {
  147. $this->decoratedFormState->disableCache()
  148. ->shouldBeCalled();
  149. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->disableCache());
  150. }
  151. /**
  152. * @covers ::setExecuted
  153. */
  154. public function testSetExecuted() {
  155. $this->decoratedFormState->setExecuted()
  156. ->shouldBecalled();
  157. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setExecuted());
  158. }
  159. /**
  160. * @covers ::isExecuted
  161. *
  162. * @dataProvider providerSingleBooleanArgument
  163. *
  164. * @param bool $executed
  165. */
  166. public function testIsExecuted($executed) {
  167. $this->decoratedFormState->isExecuted()
  168. ->willReturn($executed)
  169. ->shouldBeCalled();
  170. $this->assertSame($executed, $this->formStateDecoratorBase->isExecuted());
  171. }
  172. /**
  173. * @covers ::setGroups
  174. */
  175. public function testSetGroups() {
  176. $groups = [
  177. 'FOO' => 'BAR',
  178. ];
  179. $this->decoratedFormState->setGroups($groups)
  180. ->shouldBeCalled();
  181. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setGroups($groups));
  182. }
  183. /**
  184. * @covers ::getGroups
  185. */
  186. public function testGetGroups() {
  187. $groups = [
  188. 'FOO' => 'BAR',
  189. ];
  190. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  191. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  192. $decorated_form_state = $this->createMock(FormStateInterface::class);
  193. $decorated_form_state->expects($this->once())
  194. ->method('getGroups')
  195. ->willReturn($groups);
  196. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  197. $this->assertSame($groups, $this->formStateDecoratorBase->getGroups());
  198. }
  199. /**
  200. * @covers ::setHasFileElement
  201. *
  202. * @dataProvider providerSingleBooleanArgument
  203. *
  204. * @param bool $has_file_element
  205. */
  206. public function testSetHasFileElement($has_file_element) {
  207. $this->decoratedFormState->setHasFileElement($has_file_element)
  208. ->shouldBeCalled();
  209. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setHasFileElement($has_file_element));
  210. }
  211. /**
  212. * @covers ::hasFileElement
  213. *
  214. * @dataProvider providerSingleBooleanArgument
  215. *
  216. * @param bool $has_file_element
  217. */
  218. public function testHasFileElement($has_file_element) {
  219. $this->decoratedFormState->hasFileElement()
  220. ->willReturn($has_file_element)
  221. ->shouldBeCalled();
  222. $this->assertSame($has_file_element, $this->formStateDecoratorBase->hasFileElement());
  223. }
  224. /**
  225. * @covers ::setLimitValidationErrors
  226. *
  227. * @dataProvider providerLimitValidationErrors
  228. *
  229. * @param array[]|null $limit_validation_errors
  230. * Any valid value for
  231. * \Drupal\Core\Form\FormStateInterface::setLimitValidationErrors()'s
  232. * $limit_validation_errors argument;
  233. */
  234. public function testSetLimitValidationErrors($limit_validation_errors) {
  235. $this->decoratedFormState->setLimitValidationErrors($limit_validation_errors)
  236. ->shouldBecalled();
  237. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setLimitValidationErrors($limit_validation_errors));
  238. }
  239. /**
  240. * @covers ::getLimitValidationErrors
  241. *
  242. * @dataProvider providerLimitValidationErrors
  243. *
  244. * @param array[]|null $limit_validation_errors
  245. * Any valid value for
  246. * \Drupal\Core\Form\FormStateInterface::getLimitValidationErrors()'s
  247. * return value;
  248. */
  249. public function testGetLimitValidationErrors($limit_validation_errors) {
  250. $this->decoratedFormState->getLimitValidationErrors()
  251. ->willReturn($limit_validation_errors)
  252. ->shouldBeCalled();
  253. $this->assertSame($limit_validation_errors, $this->formStateDecoratorBase->getLimitValidationErrors());
  254. }
  255. /**
  256. * Provides data to self::testGetLimitValidationErrors() and self::testGetLimitValidationErrors().
  257. */
  258. public function providerLimitValidationErrors() {
  259. return [
  260. [NULL],
  261. [
  262. [
  263. ['foo', 'bar', 'baz'],
  264. ],
  265. ],
  266. ];
  267. }
  268. /**
  269. * @covers ::setMethod
  270. *
  271. * @dataProvider providerSingleBooleanArgument
  272. *
  273. * @param bool $method
  274. */
  275. public function testSetMethod($method) {
  276. $this->decoratedFormState->setMethod($method)
  277. ->shouldBecalled();
  278. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setMethod($method));
  279. }
  280. /**
  281. * @covers ::isMethodType
  282. *
  283. * @dataProvider providerIsMethodType
  284. *
  285. * @param bool $expected_return_value
  286. * @param string $method_type
  287. * Either "GET" or "POST".
  288. */
  289. public function testIsMethodType($expected_return_value, $method_type) {
  290. $this->decoratedFormState->isMethodType($method_type)
  291. ->willReturn($expected_return_value)
  292. ->shouldBecalled();
  293. $this->assertSame($expected_return_value, $this->formStateDecoratorBase->isMethodType($method_type));
  294. }
  295. /**
  296. * Provides data to self::testIsMethodType().
  297. */
  298. public function providerIsMethodType() {
  299. return [
  300. [TRUE, 'GET'],
  301. [TRUE, 'POST'],
  302. [FALSE, 'GET'],
  303. [FALSE, 'POST'],
  304. ];
  305. }
  306. /**
  307. * @covers ::setRequestMethod
  308. *
  309. * @dataProvider providerSetRequestMethod
  310. *
  311. * @param bool $method
  312. */
  313. public function testSetRequestMethod($method) {
  314. $this->decoratedFormState->setRequestMethod($method)
  315. ->shouldBeCalled();
  316. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRequestMethod($method));
  317. }
  318. /**
  319. * Provides data to self::testSetMethod().
  320. */
  321. public function providerSetRequestMethod() {
  322. return [
  323. ['GET'],
  324. ['POST'],
  325. ];
  326. }
  327. /**
  328. * @covers ::setValidationEnforced
  329. *
  330. * @dataProvider providerSingleBooleanArgument
  331. *
  332. * @param bool $must_validate
  333. */
  334. public function testSetValidationEnforced($must_validate) {
  335. $this->decoratedFormState->setValidationEnforced($must_validate)
  336. ->shouldBeCalled();
  337. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidationEnforced($must_validate));
  338. }
  339. /**
  340. * @covers ::isValidationEnforced
  341. *
  342. * @dataProvider providerSingleBooleanArgument
  343. *
  344. * @param bool $must_validate
  345. */
  346. public function testIsValidationEnforced($must_validate) {
  347. $this->decoratedFormState->isValidationEnforced()
  348. ->willReturn($must_validate)
  349. ->shouldBecalled();
  350. $this->assertSame($must_validate, $this->formStateDecoratorBase->isValidationEnforced());
  351. }
  352. /**
  353. * @covers ::disableRedirect
  354. *
  355. * @dataProvider providerSingleBooleanArgument
  356. *
  357. * @param bool $no_redirect
  358. */
  359. public function testDisableRedirect($no_redirect) {
  360. $this->decoratedFormState->disableRedirect($no_redirect)
  361. ->shouldBeCalled();
  362. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->disableRedirect($no_redirect));
  363. }
  364. /**
  365. * @covers ::isRedirectDisabled
  366. *
  367. * @dataProvider providerSingleBooleanArgument
  368. *
  369. * @param bool $no_redirect
  370. */
  371. public function testIsRedirectDisabled($no_redirect) {
  372. $this->decoratedFormState->isRedirectDisabled()
  373. ->willReturn($no_redirect)
  374. ->shouldBeCalled();
  375. $this->assertSame($no_redirect, $this->formStateDecoratorBase->isRedirectDisabled());
  376. }
  377. /**
  378. * @covers ::setProcessInput
  379. *
  380. * @dataProvider providerSingleBooleanArgument
  381. *
  382. * @param bool $process_input
  383. */
  384. public function testSetProcessInput($process_input) {
  385. $this->decoratedFormState->setProcessInput($process_input)
  386. ->shouldBeCalled();
  387. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setProcessInput($process_input));
  388. }
  389. /**
  390. * @covers ::isProcessingInput
  391. *
  392. * @dataProvider providerSingleBooleanArgument
  393. *
  394. * @param bool $process_input
  395. */
  396. public function testIsProcessingInput($process_input) {
  397. $this->decoratedFormState->isProcessingInput()
  398. ->willReturn($process_input)
  399. ->shouldBecalled();
  400. $this->assertSame($process_input, $this->formStateDecoratorBase->isProcessingInput());
  401. }
  402. /**
  403. * @covers ::setProgrammed
  404. *
  405. * @dataProvider providerSingleBooleanArgument
  406. *
  407. * @param bool $programmed
  408. */
  409. public function testSetProgrammed($programmed) {
  410. $this->decoratedFormState->setProgrammed($programmed)
  411. ->shouldBecalled();
  412. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setProgrammed($programmed));
  413. }
  414. /**
  415. * @covers ::isProgrammed
  416. *
  417. * @dataProvider providerSingleBooleanArgument
  418. *
  419. * @param bool $programmed
  420. */
  421. public function testIsProgrammed($programmed) {
  422. $this->decoratedFormState->isProgrammed()
  423. ->willReturn($programmed)
  424. ->shouldBecalled();
  425. $this->assertSame($programmed, $this->formStateDecoratorBase->isProgrammed());
  426. }
  427. /**
  428. * @covers ::setProgrammedBypassAccessCheck
  429. *
  430. * @dataProvider providerSingleBooleanArgument
  431. *
  432. * @param bool $programmed_bypass_access_check
  433. */
  434. public function testSetProgrammedBypassAccessCheck($programmed_bypass_access_check) {
  435. $this->decoratedFormState->setProgrammedBypassAccessCheck($programmed_bypass_access_check)
  436. ->shouldBecalled();
  437. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setProgrammedBypassAccessCheck($programmed_bypass_access_check));
  438. }
  439. /**
  440. * @covers ::isBypassingProgrammedAccessChecks
  441. *
  442. * @dataProvider providerSingleBooleanArgument
  443. *
  444. * @param bool $programmed_bypass_access_check
  445. */
  446. public function testIsBypassingProgrammedAccessChecks($programmed_bypass_access_check) {
  447. $this->decoratedFormState->isBypassingProgrammedAccessChecks()
  448. ->willReturn($programmed_bypass_access_check)
  449. ->shouldBeCalled();
  450. $this->assertSame($programmed_bypass_access_check, $this->formStateDecoratorBase->isBypassingProgrammedAccessChecks());
  451. }
  452. /**
  453. * @covers ::setRebuildInfo
  454. */
  455. public function testSetRebuildInfo() {
  456. $rebuild_info = [
  457. 'FOO' => 'BAR',
  458. ];
  459. $this->decoratedFormState->setRebuildInfo($rebuild_info)
  460. ->shouldBeCalled();
  461. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRebuildInfo($rebuild_info));
  462. }
  463. /**
  464. * @covers ::getRebuildInfo
  465. */
  466. public function testGetRebuildInfo() {
  467. $rebuild_info = [
  468. 'FOO' => 'BAR',
  469. ];
  470. $this->decoratedFormState->getRebuildInfo()
  471. ->willReturn($rebuild_info)
  472. ->shouldBeCalled();
  473. $this->assertSame($rebuild_info, $this->formStateDecoratorBase->getRebuildInfo());
  474. }
  475. /**
  476. * @covers ::addRebuildInfo
  477. */
  478. public function testAddRebuildInfo() {
  479. $property = 'FOO';
  480. $value = 'BAR';
  481. $this->decoratedFormState->addRebuildInfo($property, $value);
  482. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->addRebuildInfo($property, $value));
  483. }
  484. /**
  485. * @covers ::setStorage
  486. */
  487. public function testSetStorage() {
  488. $storage = [
  489. 'FOO' => 'BAR',
  490. ];
  491. $this->decoratedFormState->setStorage($storage)
  492. ->shouldBeCalled();
  493. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setStorage($storage));
  494. }
  495. /**
  496. * @covers ::getStorage
  497. */
  498. public function testGetStorage() {
  499. $storage = [
  500. 'FOO' => 'BAR',
  501. ];
  502. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  503. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  504. $decorated_form_state = $this->createMock(FormStateInterface::class);
  505. $decorated_form_state->expects($this->once())
  506. ->method('getStorage')
  507. ->willReturn($storage);
  508. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  509. $this->assertSame($storage, $this->formStateDecoratorBase->getStorage());
  510. }
  511. /**
  512. * @covers ::setSubmitHandlers
  513. */
  514. public function testSetSubmitHandlers() {
  515. $submit_handlers = [
  516. 'FOO' => 'BAR',
  517. ];
  518. $this->decoratedFormState->setSubmitHandlers($submit_handlers)
  519. ->shouldBeCalled();
  520. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setSubmitHandlers($submit_handlers));
  521. }
  522. /**
  523. * @covers ::getSubmitHandlers
  524. */
  525. public function testGetSubmitHandlers() {
  526. $submit_handlers = [
  527. 'FOO' => 'BAR',
  528. ];
  529. $this->decoratedFormState->getSubmitHandlers()
  530. ->willReturn($submit_handlers)
  531. ->shouldBeCalled();
  532. $this->assertSame($submit_handlers, $this->formStateDecoratorBase->getSubmitHandlers());
  533. }
  534. /**
  535. * @covers ::setSubmitted
  536. */
  537. public function testSetSubmitted() {
  538. $this->decoratedFormState->setSubmitted()
  539. ->shouldBeCalled();
  540. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setSubmitted());
  541. }
  542. /**
  543. * @covers ::isSubmitted
  544. *
  545. * @dataProvider providerSingleBooleanArgument
  546. *
  547. * @param bool $submitted
  548. */
  549. public function testIsSubmitted($submitted) {
  550. $this->decoratedFormState->isSubmitted()
  551. ->willReturn($submitted);
  552. $this->assertSame($submitted, $this->formStateDecoratorBase->isSubmitted());
  553. }
  554. /**
  555. * @covers ::setTemporary
  556. */
  557. public function testSetTemporary() {
  558. $temporary = [
  559. 'FOO' => 'BAR',
  560. ];
  561. $this->decoratedFormState->setTemporary($temporary)
  562. ->shouldBeCalled();
  563. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setTemporary($temporary));
  564. }
  565. /**
  566. * @covers ::getTemporary
  567. */
  568. public function testGetTemporary() {
  569. $temporary = [
  570. 'FOO' => 'BAR',
  571. ];
  572. $this->decoratedFormState->getTemporary()
  573. ->willReturn($temporary)
  574. ->shouldBeCalled();
  575. $this->assertSame($temporary, $this->formStateDecoratorBase->getTemporary());
  576. }
  577. /**
  578. * @covers ::setTemporaryValue
  579. *
  580. * @dataProvider providerSetTemporaryValue
  581. *
  582. * @param string $key
  583. * @param mixed $value
  584. */
  585. public function testSetTemporaryValue($key, $value) {
  586. $this->decoratedFormState->setTemporaryValue($key, $value)
  587. ->shouldBeCalled();
  588. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setTemporaryValue($key, $value));
  589. }
  590. /**
  591. * Provides data to self::testSetTemporaryValue().
  592. */
  593. public function providerSetTemporaryValue() {
  594. return [
  595. ['FOO', 'BAR'],
  596. ['FOO', NULL],
  597. ];
  598. }
  599. /**
  600. * @covers ::getTemporaryValue
  601. *
  602. * @dataProvider providerGetTemporaryValue
  603. *
  604. * @param string $key
  605. * @param mixed $value
  606. */
  607. public function testGetTemporaryValue($key, $value = NULL) {
  608. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  609. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  610. $decorated_form_state = $this->createMock(FormStateInterface::class);
  611. $decorated_form_state->expects($this->once())
  612. ->method('getTemporaryValue')
  613. ->with($key)
  614. ->willReturn($value);
  615. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  616. $this->assertSame($value, $this->formStateDecoratorBase->getTemporaryValue($key));
  617. }
  618. /**
  619. * Provides data to self::testGetTemporaryValue().
  620. */
  621. public function providerGetTemporaryValue() {
  622. return [
  623. [TRUE, 'FOO', 'BAR'],
  624. [TRUE, 'FOO', NULL],
  625. ];
  626. }
  627. /**
  628. * @covers ::hasTemporaryValue
  629. *
  630. * @dataProvider providerHasTemporaryValue
  631. *
  632. * @param bool $exists
  633. * @param string $key
  634. */
  635. public function testHasTemporaryValue($exists, $key) {
  636. $this->decoratedFormState->hasTemporaryValue($key)
  637. ->willReturn($exists)
  638. ->shouldBeCalled();
  639. $this->assertSame($exists, $this->formStateDecoratorBase->hasTemporaryValue($key));
  640. }
  641. /**
  642. * Provides data to self::testHasTemporaryValue().
  643. */
  644. public function providerHasTemporaryValue() {
  645. return [
  646. [TRUE, 'FOO'],
  647. [FALSE, 'FOO'],
  648. ];
  649. }
  650. /**
  651. * @covers ::setTriggeringElement
  652. */
  653. public function testSetTriggeringElement() {
  654. $triggering_element = [
  655. 'FOO' => 'BAR',
  656. ];
  657. $this->decoratedFormState->setTriggeringElement($triggering_element)
  658. ->shouldBeCalled();
  659. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setTriggeringElement($triggering_element));
  660. }
  661. /**
  662. * @covers ::getTriggeringElement
  663. */
  664. public function testGetTriggeringElement() {
  665. $triggering_element = [
  666. 'FOO' => 'BAR',
  667. ];
  668. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  669. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  670. $decorated_form_state = $this->createMock(FormStateInterface::class);
  671. $decorated_form_state->expects($this->once())
  672. ->method('getTriggeringElement')
  673. ->willReturn($triggering_element);
  674. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  675. $this->assertSame($triggering_element, $this->formStateDecoratorBase->getTriggeringElement());
  676. }
  677. /**
  678. * @covers ::setValidateHandlers
  679. */
  680. public function testSetValidateHandlers() {
  681. $validate_handlers = [
  682. 'FOO' => 'BAR',
  683. ];
  684. $this->decoratedFormState->setValidateHandlers($validate_handlers)
  685. ->shouldBeCalled();
  686. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidateHandlers($validate_handlers));
  687. }
  688. /**
  689. * @covers ::getValidateHandlers
  690. */
  691. public function testGetValidateHandlers() {
  692. $validate_handlers = [
  693. 'FOO' => 'BAR',
  694. ];
  695. $this->decoratedFormState->getValidateHandlers()
  696. ->willReturn($validate_handlers)
  697. ->shouldBecalled();
  698. $this->assertSame($validate_handlers, $this->formStateDecoratorBase->getValidateHandlers());
  699. }
  700. /**
  701. * @covers ::setValidationComplete
  702. *
  703. * @dataProvider providerSingleBooleanArgument
  704. *
  705. * @param bool $complete
  706. */
  707. public function testSetValidationComplete($complete) {
  708. $this->decoratedFormState->setValidationComplete($complete)
  709. ->shouldBeCalled();
  710. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValidationComplete($complete));
  711. }
  712. /**
  713. * @covers ::isValidationComplete
  714. *
  715. * @dataProvider providerSingleBooleanArgument
  716. *
  717. * @param bool $complete
  718. */
  719. public function testIsValidationComplete($complete) {
  720. $this->decoratedFormState->isValidationComplete()
  721. ->willReturn($complete)
  722. ->shouldBeCalled();
  723. $this->assertSame($complete, $this->formStateDecoratorBase->isValidationComplete());
  724. }
  725. /**
  726. * @covers ::loadInclude
  727. *
  728. * @dataProvider providerLoadInclude
  729. *
  730. * @param string|false $expected
  731. * @param string $module
  732. * @param string $type
  733. * @param string|null $name
  734. */
  735. public function testLoadInclude($expected, $module, $type, $name) {
  736. $this->decoratedFormState->loadInclude($module, $type, $name)
  737. ->willReturn($expected)
  738. ->shouldBeCalled();
  739. $this->assertSame($expected, $this->formStateDecoratorBase->loadInclude($module, $type, $name));
  740. }
  741. /**
  742. * Provides data to self::testLoadInclude().
  743. */
  744. public function providerLoadInclude() {
  745. return [
  746. // Existing files.
  747. [__FILE__, 'foo', 'inc', 'foo'],
  748. [__FILE__, 'foo', 'inc', 'foo.admin'],
  749. [__FILE__, 'bar', 'inc', 'bar'],
  750. // Non-existent files.
  751. [FALSE, 'foo', 'php', 'foo'],
  752. [FALSE, 'bar', 'php', 'foo'],
  753. ];
  754. }
  755. /**
  756. * @covers ::getCacheableArray
  757. */
  758. public function testGetCacheableArray() {
  759. $cacheable_array = [
  760. 'foo' => 'bar',
  761. ];
  762. $this->decoratedFormState->getCacheableArray()
  763. ->willReturn($cacheable_array)
  764. ->shouldBeCalled();
  765. $this->assertSame($cacheable_array, $this->formStateDecoratorBase->getCacheableArray());
  766. }
  767. /**
  768. * @covers ::setCompleteForm
  769. */
  770. public function testSetCompleteForm() {
  771. $complete_form = [
  772. 'FOO' => 'BAR',
  773. ];
  774. $this->decoratedFormState->setCompleteForm($complete_form)
  775. ->shouldBeCalled();
  776. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCompleteForm($complete_form));
  777. }
  778. /**
  779. * @covers ::getCompleteForm
  780. */
  781. public function testGetCompleteForm() {
  782. $complete_form = [
  783. 'FOO' => 'BAR',
  784. ];
  785. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  786. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  787. $decorated_form_state = $this->createMock(FormStateInterface::class);
  788. $decorated_form_state->expects($this->once())
  789. ->method('getCompleteForm')
  790. ->willReturn($complete_form);
  791. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  792. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCompleteForm($complete_form));
  793. $this->assertSame($complete_form, $this->formStateDecoratorBase->getCompleteForm());
  794. }
  795. /**
  796. * @covers ::set
  797. *
  798. * @dataProvider providerSet
  799. *
  800. * @param string $key
  801. * @param mixed $value
  802. */
  803. public function testSet($key, $value) {
  804. $this->decoratedFormState->set($key, $value)
  805. ->shouldBeCalled();
  806. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->set($key, $value));
  807. }
  808. /**
  809. * Provides data to self::testSet().
  810. */
  811. public function providerSet() {
  812. return [
  813. ['FOO', 'BAR'],
  814. ['FOO', NULL],
  815. ];
  816. }
  817. /**
  818. * @covers ::get
  819. *
  820. * @dataProvider providerGet
  821. *
  822. * @param string $key
  823. * @param mixed $value
  824. */
  825. public function testGet($key, $value = NULL) {
  826. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  827. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  828. $decorated_form_state = $this->createMock(FormStateInterface::class);
  829. $decorated_form_state->expects($this->once())
  830. ->method('get')
  831. ->with($key)
  832. ->willReturn($value);
  833. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  834. $this->assertSame($value, $this->formStateDecoratorBase->get($key));
  835. }
  836. /**
  837. * Provides data to self::testGet().
  838. */
  839. public function providerGet() {
  840. return [
  841. ['FOO', 'BAR'],
  842. ['FOO', NULL],
  843. ];
  844. }
  845. /**
  846. * @covers ::has
  847. *
  848. * @dataProvider providerHas
  849. *
  850. * @param bool $exists
  851. * @param string $key
  852. */
  853. public function testHas($exists, $key) {
  854. $this->decoratedFormState->has($key)
  855. ->willReturn($exists)
  856. ->shouldBeCalled();
  857. $this->assertSame($exists, $this->formStateDecoratorBase->has($key));
  858. }
  859. /**
  860. * Provides data to self::testHas().
  861. */
  862. public function providerHas() {
  863. return [
  864. [TRUE, 'FOO'],
  865. [FALSE, 'FOO'],
  866. ];
  867. }
  868. /**
  869. * @covers ::setBuildInfo
  870. */
  871. public function testSetBuildInfo() {
  872. $build_info = [
  873. 'FOO' => 'BAR',
  874. ];
  875. $this->decoratedFormState->setBuildInfo($build_info)
  876. ->shouldBeCalled();
  877. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setBuildInfo($build_info));
  878. }
  879. /**
  880. * @covers ::getBuildInfo
  881. */
  882. public function testGetBuildInfo() {
  883. $build_info = [
  884. 'FOO' => 'BAR',
  885. ];
  886. $this->decoratedFormState->getBuildInfo()
  887. ->willReturn($build_info)
  888. ->shouldBeCalled();
  889. $this->assertSame($build_info, $this->formStateDecoratorBase->getBuildInfo());
  890. }
  891. /**
  892. * @covers ::addBuildInfo
  893. */
  894. public function testAddBuildInfo() {
  895. $property = 'FOO';
  896. $value = 'BAR';
  897. $this->decoratedFormState->addBuildInfo($property, $value)
  898. ->shouldBeCalled();
  899. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->addBuildInfo($property, $value));
  900. }
  901. /**
  902. * @covers ::setUserInput
  903. */
  904. public function testSetUserInput() {
  905. $user_input = [
  906. 'FOO' => 'BAR',
  907. ];
  908. $this->decoratedFormState->setUserInput($user_input)
  909. ->shouldBeCalled();
  910. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setUserInput($user_input));
  911. }
  912. /**
  913. * @covers ::getUserInput
  914. */
  915. public function testGetUserInput() {
  916. $user_input = [
  917. 'FOO' => 'BAR',
  918. ];
  919. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  920. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  921. $decorated_form_state = $this->createMock(FormStateInterface::class);
  922. $decorated_form_state->expects($this->once())
  923. ->method('getUserInput')
  924. ->willReturn($user_input);
  925. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  926. $this->assertSame($user_input, $this->formStateDecoratorBase->getUserInput());
  927. }
  928. /**
  929. * @covers ::getValues
  930. */
  931. public function testGetValues() {
  932. $values = [
  933. 'FOO' => 'BAR',
  934. ];
  935. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  936. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  937. $decorated_form_state = $this->createMock(FormStateInterface::class);
  938. $decorated_form_state->expects($this->once())
  939. ->method('getValues')
  940. ->willReturn($values);
  941. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  942. $this->assertSame($values, $this->formStateDecoratorBase->getValues());
  943. }
  944. /**
  945. * @covers ::getValue
  946. */
  947. public function testGetValue() {
  948. $key = 'FOO';
  949. $value = 'BAR';
  950. // Use PHPUnit for mocking, because Prophecy cannot mock methods that return
  951. // by reference. See \Prophecy\Doubler\Generator\Node::getCode().
  952. $decorated_form_state = $this->createMock(FormStateInterface::class);
  953. $decorated_form_state->expects($this->once())
  954. ->method('getValue')
  955. ->with($key, $value)
  956. ->willReturn($value);
  957. $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);
  958. $this->assertSame($value, $this->formStateDecoratorBase->getValue($key, $value));
  959. }
  960. /**
  961. * @covers ::setValues
  962. */
  963. public function testSetValues() {
  964. $values = [
  965. 'foo' => 'Foo',
  966. 'bar' => ['Bar'],
  967. ];
  968. $this->decoratedFormState->setValues($values)
  969. ->shouldBeCalled();
  970. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValues($values));
  971. }
  972. /**
  973. * @covers ::setValue
  974. */
  975. public function testSetValue() {
  976. $key = 'FOO';
  977. $value = 'BAR';
  978. $this->decoratedFormState->setValue($key, $value)
  979. ->shouldBeCalled();
  980. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValue($key, $value));
  981. }
  982. /**
  983. * @covers ::unsetValue
  984. */
  985. public function testUnsetValue() {
  986. $key = 'FOO';
  987. $this->decoratedFormState->unsetValue($key)
  988. ->shouldBeCalled();
  989. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->unsetValue($key));
  990. }
  991. /**
  992. * @covers ::hasValue
  993. */
  994. public function testHasValue() {
  995. $key = ['foo', 'bar'];
  996. $has = TRUE;
  997. $this->decoratedFormState->hasValue($key)
  998. ->willReturn($has)
  999. ->shouldBeCalled();
  1000. $this->assertSame($has, $this->formStateDecoratorBase->hasValue($key));
  1001. }
  1002. /**
  1003. * @covers ::isValueEmpty
  1004. */
  1005. public function testIsValueEmpty() {
  1006. $key = ['foo', 'bar'];
  1007. $is_empty = TRUE;
  1008. $this->decoratedFormState->isValueEmpty($key)
  1009. ->willReturn($is_empty)
  1010. ->shouldBeCalled();
  1011. $this->assertSame($is_empty, $this->formStateDecoratorBase->isValueEmpty($key));
  1012. }
  1013. /**
  1014. * @covers ::setValueForElement
  1015. */
  1016. public function testSetValueForElement() {
  1017. $element = [
  1018. '#type' => 'foo',
  1019. ];
  1020. $value = 'BAR';
  1021. $this->decoratedFormState->setValueForElement($element, $value)
  1022. ->shouldBeCalled();
  1023. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setValueForElement($element, $value));
  1024. }
  1025. /**
  1026. * @covers ::setResponse
  1027. */
  1028. public function testSetResponse() {
  1029. $response = $this->createMock(Response::class);
  1030. $this->decoratedFormState->setResponse($response)
  1031. ->shouldBeCalled();
  1032. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setResponse($response));
  1033. }
  1034. /**
  1035. * @covers ::getResponse
  1036. */
  1037. public function testGetResponse() {
  1038. $response = $this->createMock(Response::class);
  1039. $this->decoratedFormState->getResponse()
  1040. ->willReturn($response)
  1041. ->shouldBeCalled();
  1042. $this->assertSame($response, $this->formStateDecoratorBase->getResponse());
  1043. }
  1044. /**
  1045. * @covers ::setRedirect
  1046. */
  1047. public function testSetRedirect() {
  1048. $route_name = 'foo';
  1049. $route_parameters = [
  1050. 'bar' => 'baz',
  1051. ];
  1052. $options = [
  1053. 'qux' => 'foo',
  1054. ];
  1055. $this->decoratedFormState->setRedirect($route_name, $route_parameters, $options)
  1056. ->shouldBeCalled();
  1057. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRedirect($route_name, $route_parameters, $options));
  1058. }
  1059. /**
  1060. * @covers ::setRedirectUrl
  1061. */
  1062. public function testSetRedirectUrl() {
  1063. $url = new Url('foo');
  1064. $this->decoratedFormState->setRedirectUrl($url)
  1065. ->shouldBeCalled();
  1066. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRedirectUrl($url));
  1067. }
  1068. /**
  1069. * @covers ::getRedirect
  1070. *
  1071. * @dataProvider providerGetRedirect
  1072. *
  1073. * @param bool $expected
  1074. */
  1075. public function testGetRedirect($expected) {
  1076. $this->decoratedFormState->getRedirect()
  1077. ->willReturn($expected)
  1078. ->shouldBeCalled();
  1079. $this->assertSame($expected, $this->formStateDecoratorBase->getRedirect());
  1080. }
  1081. /**
  1082. * Provides data to self::testGetRedirect().
  1083. */
  1084. public function providerGetRedirect() {
  1085. return [
  1086. [NULL],
  1087. [FALSE],
  1088. [new Url('foo')],
  1089. [new RedirectResponse('http://example.com')],
  1090. ];
  1091. }
  1092. /**
  1093. * @covers ::setErrorByName
  1094. */
  1095. public function testSetErrorByName() {
  1096. $name = 'foo';
  1097. $message = 'bar';
  1098. $this->decoratedFormState->setErrorByName($name, $message)
  1099. ->shouldBeCalled();
  1100. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setErrorByName($name, $message));
  1101. }
  1102. /**
  1103. * @covers ::setError
  1104. */
  1105. public function testSetError() {
  1106. $element = [
  1107. '#foo' => 'bar',
  1108. ];
  1109. $message = 'bar';
  1110. $this->decoratedFormState->setError($element, $message)
  1111. ->shouldBeCalled();
  1112. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setError($element, $message));
  1113. }
  1114. /**
  1115. * @covers ::clearErrors
  1116. */
  1117. public function testClearErrors() {
  1118. $this->decoratedFormState->clearErrors()
  1119. ->shouldBeCalled();
  1120. $this->formStateDecoratorBase->clearErrors();
  1121. }
  1122. /**
  1123. * @covers ::getError
  1124. */
  1125. public function testGetError() {
  1126. $element = [
  1127. '#foo' => 'bar',
  1128. ];
  1129. $message = 'bar';
  1130. $this->decoratedFormState->getError($element)
  1131. ->willReturn($message)
  1132. ->shouldBeCalled();
  1133. $this->assertSame($message, $this->formStateDecoratorBase->getError($element));
  1134. }
  1135. /**
  1136. * @covers ::getErrors
  1137. */
  1138. public function testGetErrors() {
  1139. $errors = [
  1140. 'foo' => 'bar',
  1141. ];
  1142. $this->decoratedFormState->getErrors()
  1143. ->willReturn($errors)
  1144. ->shouldBeCalled();
  1145. $this->assertSame($errors, $this->formStateDecoratorBase->getErrors());
  1146. }
  1147. /**
  1148. * @covers ::setRebuild
  1149. *
  1150. * @dataProvider providerSingleBooleanArgument
  1151. *
  1152. * @param bool $rebuild
  1153. */
  1154. public function testSetRebuild($rebuild) {
  1155. $this->decoratedFormState->setRebuild($rebuild)
  1156. ->shouldBeCalled();
  1157. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setRebuild($rebuild));
  1158. }
  1159. /**
  1160. * @covers ::isRebuilding
  1161. *
  1162. * @dataProvider providerSingleBooleanArgument
  1163. *
  1164. * @param bool $rebuild
  1165. */
  1166. public function testIsRebuilding($rebuild) {
  1167. $this->decoratedFormState->isRebuilding()
  1168. ->willReturn($rebuild)
  1169. ->shouldBeCalled();
  1170. $this->assertSame($rebuild, $this->formStateDecoratorBase->isRebuilding());
  1171. }
  1172. /**
  1173. * @covers ::setInvalidToken
  1174. *
  1175. * @dataProvider providerSingleBooleanArgument
  1176. *
  1177. * @param bool $expected
  1178. */
  1179. public function testSetInvalidToken($expected) {
  1180. $this->decoratedFormState->setInvalidToken($expected)
  1181. ->shouldBeCalled();
  1182. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setInvalidToken($expected));
  1183. }
  1184. /**
  1185. * @covers ::hasInvalidToken
  1186. *
  1187. * @dataProvider providerSingleBooleanArgument
  1188. *
  1189. * @param bool $expected
  1190. */
  1191. public function testHasInvalidToken($expected) {
  1192. $this->decoratedFormState->hasInvalidToken()
  1193. ->willReturn($expected)
  1194. ->shouldBeCalled();
  1195. $this->assertSame($expected, $this->formStateDecoratorBase->hasInvalidToken());
  1196. }
  1197. /**
  1198. * @covers ::prepareCallback
  1199. *
  1200. * @dataProvider providerPrepareCallback
  1201. *
  1202. * @param string|callable $unprepared_callback
  1203. * @param callable $prepared_callback
  1204. */
  1205. public function testPrepareCallback($unprepared_callback, callable $prepared_callback) {
  1206. $this->decoratedFormState->prepareCallback(Argument::is($unprepared_callback))
  1207. ->willReturn($prepared_callback)
  1208. ->shouldBeCalled();
  1209. $this->assertSame($prepared_callback, $this->formStateDecoratorBase->prepareCallback($unprepared_callback));
  1210. }
  1211. /**
  1212. * Provides data to self::testPrepareCallback().
  1213. */
  1214. public function providerPrepareCallback() {
  1215. $function = 'sleep';
  1216. $shorthand_form_method = '::submit()';
  1217. $closure = function () {};
  1218. $static_method_string = __METHOD__;
  1219. $static_method_array = [__CLASS__, __FUNCTION__];
  1220. $object_method_array = [$this, __FUNCTION__];
  1221. return [
  1222. // A shorthand form method is generally expanded to become a method on an
  1223. // object.
  1224. [$shorthand_form_method, $object_method_array],
  1225. // Functions, closures, and static method calls generally remain the same.
  1226. [$function, $function],
  1227. [$closure, $closure],
  1228. [$static_method_string, $static_method_string],
  1229. [$static_method_array, $static_method_array],
  1230. ];
  1231. }
  1232. /**
  1233. * @covers ::setFormObject
  1234. */
  1235. public function testSetFormObject() {
  1236. $form = $this->createMock(FormInterface::class);
  1237. $this->decoratedFormState->setFormObject($form)
  1238. ->shouldBeCalled();
  1239. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setFormObject($form));
  1240. }
  1241. /**
  1242. * @covers ::getFormObject
  1243. */
  1244. public function testGetFormObject() {
  1245. $form = $this->createMock(FormInterface::class);
  1246. $this->decoratedFormState->getFormObject()
  1247. ->willReturn($form)
  1248. ->shouldBeCalled();
  1249. $this->assertSame($form, $this->formStateDecoratorBase->getFormObject());
  1250. }
  1251. /**
  1252. * @covers ::setCleanValueKeys
  1253. */
  1254. public function testSetCleanValueKeys() {
  1255. $keys = ['BAR'];
  1256. $this->decoratedFormState->setCleanValueKeys($keys)
  1257. ->shouldBeCalled();
  1258. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->setCleanValueKeys($keys));
  1259. }
  1260. /**
  1261. * @covers ::getCleanValueKeys
  1262. */
  1263. public function testGetCleanValueKeys() {
  1264. $keys = ['BAR'];
  1265. $this->decoratedFormState->getCleanValueKeys()
  1266. ->willReturn($keys)
  1267. ->shouldBeCalled();
  1268. $this->assertSame($keys, $this->formStateDecoratorBase->getCleanValueKeys());
  1269. }
  1270. /**
  1271. * @covers ::addCleanValueKey
  1272. */
  1273. public function testAddCleanValueKey() {
  1274. $key = 'BAR';
  1275. $this->decoratedFormState->addCleanValueKey($key)
  1276. ->shouldBeCalled();
  1277. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->addCleanValueKey($key));
  1278. }
  1279. /**
  1280. * @covers ::cleanValues
  1281. */
  1282. public function testCleanValues() {
  1283. $this->decoratedFormState->cleanValues()
  1284. ->shouldBeCalled();
  1285. $this->assertSame($this->formStateDecoratorBase, $this->formStateDecoratorBase->cleanValues());
  1286. }
  1287. }
  1288. /**
  1289. * Provides a non-abstract version of the class under test.
  1290. */
  1291. class NonAbstractFormStateDecoratorBase extends FormStateDecoratorBase {
  1292. /**
  1293. * Creates a new instance.
  1294. *
  1295. * @param \Drupal\Core\Form\FormStateInterface $decorated_form_state
  1296. * The decorated form state.
  1297. */
  1298. public function __construct(FormStateInterface $decorated_form_state) {
  1299. $this->decoratedFormState = $decorated_form_state;
  1300. }
  1301. }