SluggedBehaviorTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <?php
  2. namespace Tools\Test\TestCase\Model\Behavior;
  3. use Cake\Core\Configure;
  4. use Cake\ORM\Entity;
  5. use Cake\ORM\TableRegistry;
  6. use Tools\TestSuite\TestCase;
  7. /**
  8. * SluggedBehaviorTest
  9. */
  10. class SluggedBehaviorTest extends TestCase {
  11. /**
  12. * Fixture
  13. *
  14. * @var array
  15. */
  16. public $fixtures = [
  17. 'plugin.tools.slugged_articles'
  18. ];
  19. /**
  20. * setup
  21. *
  22. * @return void
  23. */
  24. public function setUp() {
  25. parent::setUp();
  26. //$this->connection = ConnectionManager::get('test');
  27. $options = ['alias' => 'Articles'];
  28. $this->articles = TableRegistry::get('SluggedArticles', $options);
  29. Configure::delete('Slugged');
  30. $this->articles->addBehavior('Tools.Slugged');
  31. }
  32. /**
  33. * teardown
  34. *
  35. * @return void
  36. */
  37. public function tearDown() {
  38. unset($this->articles);
  39. TableRegistry::clear();
  40. parent::tearDown();
  41. }
  42. /**
  43. * Testing simple slugging when adding a record
  44. *
  45. * @return void
  46. */
  47. public function testAdd() {
  48. $entity = $this->_getEntity();
  49. $result = $this->articles->save($entity);
  50. $this->assertEquals('test-123', $result->get('slug'));
  51. }
  52. /**
  53. * Testing simple slugging when adding a record
  54. *
  55. * @return void
  56. */
  57. public function testAddUnique() {
  58. $this->articles->behaviors()->Slugged->config(['unique' => true]);
  59. $entity = $this->_getEntity();
  60. $result = $this->articles->save($entity);
  61. $this->assertEquals('test-123', $result->get('slug'));
  62. //$entity = $this->_getEntity();
  63. //$result = $this->articles->save($entity);
  64. //$this->assertEquals('test-123', $result->get('slug'));
  65. //debug($result);
  66. }
  67. /**
  68. * @return void
  69. */
  70. public function testAddUniqueMultipleLabels() {
  71. //$this->articles->behaviors()->Slugged->config('label', ''); // Hack necessary right now to avoid title showing up twice
  72. $this->articles->behaviors()->Slugged->configShallow(['mode' => 'ascii', 'unique' => true, 'label' => ['title', 'long_title']]);
  73. $entity = $this->_getEntity(null, null, ['long_title' => 'blae']);
  74. $result = $this->articles->save($entity);
  75. $this->assertEquals('test-123-blae', $result->get('slug'));
  76. $entity = $this->_getEntity(null, null, ['long_title' => 'blä']);
  77. $result = $this->articles->save($entity);
  78. $this->assertEquals('test-123-blae-1', $result->get('slug'));
  79. }
  80. /**
  81. * SluggedBehaviorTest::testCustomFinder()
  82. *
  83. * @return void
  84. */
  85. public function testCustomFinder() {
  86. $article = $this->articles->find()->find('slugged', ['slug' => 'foo'])->first();
  87. $this->assertEquals('Foo', $article->get('title'));
  88. }
  89. /**
  90. * Tests that manual slugging works.
  91. *
  92. * @return void
  93. */
  94. public function testSlugManualSave() {
  95. $article = $this->articles->newEntity(['title' => 'Some Cool String']);
  96. $result = $this->articles->save($article);
  97. $this->assertEquals('Some-Cool-String', $result['slug']);
  98. $article = $this->articles->newEntity(['title' => 'Some Other String']);
  99. $result = $this->articles->save($article);
  100. $this->assertEquals('Some-Other-String', $result['slug']);
  101. $this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar']);
  102. $result = $this->articles->save($article);
  103. $this->assertEquals('foo-bar', $result['slug']);
  104. $this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar-bat']);
  105. $result = $this->articles->save($article);
  106. $this->assertEquals('foo-bar-bat', $result['slug']);
  107. $this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => '']);
  108. $result = $this->articles->save($article);
  109. $this->assertEquals('Some-Cool-Other-String', $result['slug']);
  110. }
  111. /**
  112. * Length based on manual config.
  113. *
  114. * @return void
  115. */
  116. public function testLengthRestrictionManual() {
  117. $this->articles->behaviors()->Slugged->config(['length' => 155]);
  118. $entity = $this->_getEntity(str_repeat('foo bar ', 31));
  119. $result = $this->articles->save($entity);
  120. $this->assertEquals(155, strlen($result->get('slug')));
  121. $this->articles->behaviors()->Slugged->config(['length' => 10, 'mode' => 'ascii']);
  122. $entity = $this->_getEntity('ä ö ü ä ö ü');
  123. $result = $this->articles->save($entity);
  124. $this->assertEquals('ae-oe-ue-a', $result->get('slug'));
  125. }
  126. /**
  127. * Test that fieldList doesnt mess with slug storing.
  128. *
  129. * @return void
  130. */
  131. public function testFieldList() {
  132. // field list is only relevant for newEntity(), not for what the behavior does
  133. $entity = $this->articles->newEntity(['title' => 'Some title'], ['fieldList' => ['title']]);
  134. $result = $this->articles->save($entity);
  135. $this->assertEquals('Some-title', $result->get('slug'));
  136. }
  137. /**
  138. * Tests needSlugUpdate()
  139. *
  140. * @return void
  141. */
  142. public function testNeedsSlugUpdate() {
  143. // No title change
  144. $entity = $this->articles->newEntity(['title' => 'Some title'], ['fieldList' => []]);
  145. $result = $this->articles->needsSlugUpdate($entity);
  146. $this->assertFalse($result);
  147. // Title change
  148. $entity = $this->articles->newEntity(['title' => 'Some title']);
  149. $result = $this->articles->needsSlugUpdate($entity);
  150. $this->assertTrue($result);
  151. $result = $this->articles->save($entity);
  152. $this->assertEquals('Some-title', $result->get('slug'));
  153. // No title change
  154. $entity = $this->articles->patchEntity($entity, ['description' => 'Foo bar']);
  155. $result = $this->articles->needsSlugUpdate($entity);
  156. $this->assertFalse($result);
  157. // Needs an update, but overwrite is still false: will not modify the slug
  158. $entity = $this->articles->patchEntity($entity, ['title' => 'Some other title']);
  159. $result = $this->articles->needsSlugUpdate($entity);
  160. $this->assertTrue($result);
  161. $result = $this->articles->save($entity);
  162. $this->assertEquals('Some-title', $result->get('slug'));
  163. $this->articles->behaviors()->Slugged->config(['overwrite' => true]);
  164. // Now it can modify the slug
  165. $entity = $this->articles->patchEntity($entity, ['title' => 'Some really other title']);
  166. $result = $this->articles->needsSlugUpdate($entity);
  167. $this->assertTrue($result);
  168. $result = $this->articles->save($entity);
  169. $this->assertEquals('Some-really-other-title', $result->get('slug'));
  170. }
  171. /**
  172. * Tests needSlugUpdate() with deep
  173. *
  174. * @return void
  175. */
  176. public function testNeedsSlugUpdateDeep() {
  177. // No title change
  178. $entity = $this->articles->newEntity(['title' => 'Some title']);
  179. $result = $this->articles->needsSlugUpdate($entity);
  180. $this->assertTrue($result);
  181. $result = $this->articles->needsSlugUpdate($entity, true);
  182. $this->assertTrue($result);
  183. $result = $this->articles->save($entity);
  184. $this->assertEquals('Some-title', $result->get('slug'));
  185. // Needs an update, but overwrite is still false: will not modify the slug
  186. $entity = $this->articles->patchEntity($entity, ['title' => 'Some other title']);
  187. $result = $this->articles->needsSlugUpdate($entity);
  188. $this->assertTrue($result);
  189. $result = $this->articles->needsSlugUpdate($entity, true);
  190. $this->assertTrue($result);
  191. $result = $this->articles->save($entity);
  192. $this->assertEquals('Some-title', $result->get('slug'));
  193. // Here deep would tell the truth
  194. $entity = $this->articles->patchEntity($entity, ['title' => 'Some other title']);
  195. $result = $this->articles->needsSlugUpdate($entity);
  196. $this->assertFalse($result);
  197. $result = $this->articles->needsSlugUpdate($entity, true);
  198. $this->assertTrue($result);
  199. }
  200. /**
  201. * Length based on auto-detect of schema.
  202. *
  203. * @return void
  204. */
  205. public function testLengthRestrictionAutoDetect() {
  206. $entity = $this->_getEntity(str_repeat('foo bar ', 31));
  207. $result = $this->articles->save($entity);
  208. $this->assertEquals(245, strlen($result->get('slug')));
  209. }
  210. /**
  211. * Ensure that you can overwrite length.
  212. *
  213. * @return void
  214. */
  215. public function testLengthRestrictionNoLimit() {
  216. $this->articles->behaviors()->Slugged->config(['length' => 0, 'label' => 'long_title', 'field' => 'long_slug']);
  217. $entity = $this->_getEntity(str_repeat('foo bar ', 100), 'long_title');
  218. $result = $this->articles->save($entity);
  219. $this->assertEquals(799, strlen($result->get('long_slug')));
  220. }
  221. /**
  222. * SluggedBehaviorTest::testResetSlugs()
  223. *
  224. * @return void
  225. */
  226. public function testResetSlugs() {
  227. $this->articles->removeBehavior('Slugged');
  228. $article = $this->articles->newEntity(['title' => 'Andy Dawson', 'slug' => 'foo']);
  229. $this->articles->save($article);
  230. $article = $this->articles->newEntity(['title' => 'Andy Dawsom', 'slug' => 'bar']);
  231. $this->articles->save($article);
  232. $result = $this->articles->find('all', [
  233. 'conditions' => ['title LIKE' => 'Andy Daw%'],
  234. 'fields' => ['title', 'slug'],
  235. 'order' => 'title'
  236. ])->combine('title', 'slug')->toArray();
  237. $expected = [
  238. 'Andy Dawsom' => 'bar',
  239. 'Andy Dawson' => 'foo'
  240. ];
  241. $this->assertEquals($expected, $result);
  242. $this->articles->addBehavior('Tools.Slugged');
  243. $result = $this->articles->resetSlugs(['limit' => 1]);
  244. $this->assertTrue($result);
  245. $result = $this->articles->find('all', [
  246. 'conditions' => ['title LIKE' => 'Andy Daw%'],
  247. 'fields' => ['title', 'slug'],
  248. 'order' => 'title'
  249. ])->combine('title', 'slug')->toArray();
  250. $expected = [
  251. 'Andy Dawsom' => 'Andy-Dawsom',
  252. 'Andy Dawson' => 'Andy-Dawson'
  253. ];
  254. $this->assertEquals($expected, $result);
  255. }
  256. /**
  257. * TestDuplicateWithLengthRestriction method
  258. *
  259. * If there's a length restriction - ensure it's respected by the unique slug routine
  260. *
  261. * @return void
  262. */
  263. public function testDuplicateWithLengthRestriction() {
  264. $this->skipIf(true);
  265. $this->articles->behaviors()->Slugged->config(['length' => 10, 'unique' => true]);
  266. $article = $this->articles->newEntity(['title' => 'Andy Dawson']);
  267. $this->articles->save($article);
  268. $article = $this->articles->newEntity(['title' => 'Andy Dawsom']);
  269. $this->articles->save($article);
  270. $article = $this->articles->newEntity(['title' => 'Andy Dawsoo']);
  271. $this->articles->save($article);
  272. $article = $this->articles->newEntity(['title' => 'Andy Dawso3']);
  273. $this->articles->save($article);
  274. $article = $this->articles->newEntity(['title' => 'Andy Dawso4']);
  275. $this->articles->save($article);
  276. $article = $this->articles->newEntity(['title' => 'Andy Dawso5']);
  277. $this->articles->save($article);
  278. $article = $this->articles->newEntity(['title' => 'Andy Dawso6']);
  279. $this->articles->save($article);
  280. $article = $this->articles->newEntity(['title' => 'Andy Dawso7']);
  281. $this->articles->save($article);
  282. $article = $this->articles->newEntity(['title' => 'Andy Dawso8']);
  283. $this->articles->save($article);
  284. $article = $this->articles->newEntity(['title' => 'Andy Dawso9']);
  285. $this->articles->save($article);
  286. $article = $this->articles->newEntity(['title' => 'Andy Dawso0']);
  287. $this->articles->save($article);
  288. $result = $this->articles->find('all', [
  289. 'conditions' => ['title LIKE' => 'Andy Daw%'],
  290. 'fields' => ['title', 'slug'],
  291. 'order' => 'title'
  292. ])->combine('title', 'slug')->toArray();
  293. $expected = [
  294. 'Andy Dawson' => 'Andy-Dawso',
  295. 'Andy Dawsom' => 'Andy-Daw-1',
  296. 'Andy Dawsoo' => 'Andy-Daw-2',
  297. 'Andy Dawso3' => 'Andy-Daw-3',
  298. 'Andy Dawso4' => 'Andy-Daw-4',
  299. 'Andy Dawso5' => 'Andy-Daw-5',
  300. 'Andy Dawso6' => 'Andy-Daw-6',
  301. 'Andy Dawso7' => 'Andy-Daw-7',
  302. 'Andy Dawso8' => 'Andy-Daw-8',
  303. 'Andy Dawso9' => 'Andy-Daw-9',
  304. 'Andy Dawso0' => 'Andy-Da-10'
  305. ];
  306. $this->assertEquals($expected, $result);
  307. }
  308. /**
  309. * TestTruncateMultibyte method
  310. *
  311. * @return void
  312. */
  313. /**
  314. * TestTruncateMultibyte method
  315. *
  316. * Ensure that the first test doesn't cut a multibyte character The test string is:
  317. * 17 chars
  318. * 51 bytes UTF-8 encoded
  319. *
  320. * @return void
  321. */
  322. public function testTruncateMultibyte() {
  323. $this->articles->behaviors()->Slugged->config(['length' => 16]);
  324. $result = $this->articles->generateSlug('モデルのデータベースとデータソース');
  325. $expected = 'モデルのデータベースとデータソー';
  326. $this->assertEquals($expected, $result);
  327. }
  328. /**
  329. * Test Url method
  330. *
  331. * @return void
  332. */
  333. public function testUrlMode() {
  334. $this->articles->behaviors()->Slugged->config(['mode' => 'url', 'replace' => false]);
  335. $string = 'standard string';
  336. $expected = 'standard-string';
  337. $result = $this->articles->generateSlug($string);
  338. $this->assertEquals($expected, $result);
  339. $string = 'something with a \' in it';
  340. $expected = 'something-with-a-in-it';
  341. $result = $this->articles->generateSlug($string);
  342. $this->assertEquals($expected, $result);
  343. $string = 'something with a " in it';
  344. $expected = 'something-with-a-in-it';
  345. $result = $this->articles->generateSlug($string);
  346. $this->assertEquals($expected, $result);
  347. $string = 'something with a / in it';
  348. $expected = 'something-with-a-in-it';
  349. $result = $this->articles->generateSlug($string);
  350. $this->assertEquals($expected, $result);
  351. $string = 'something with a ? in it';
  352. $expected = 'something-with-a-in-it';
  353. $result = $this->articles->generateSlug($string);
  354. $this->assertEquals($expected, $result);
  355. $string = 'something with a < in it';
  356. $expected = 'something-with-a-in-it';
  357. $result = $this->articles->generateSlug($string);
  358. $this->assertEquals($expected, $result);
  359. $string = 'something with a > in it';
  360. $expected = 'something-with-a-in-it';
  361. $result = $this->articles->generateSlug($string);
  362. $this->assertEquals($expected, $result);
  363. $string = 'something with a . in it';
  364. $expected = 'something-with-a-in-it';
  365. $result = $this->articles->generateSlug($string);
  366. $this->assertEquals($expected, $result);
  367. $string = 'something with a $ in it';
  368. $expected = 'something-with-a-in-it';
  369. $result = $this->articles->generateSlug($string);
  370. $this->assertEquals($expected, $result);
  371. $string = 'something with a / in it';
  372. $expected = 'something-with-a-in-it';
  373. $result = $this->articles->generateSlug($string);
  374. $this->assertEquals($expected, $result);
  375. $string = 'something with a : in it';
  376. $expected = 'something-with-a-in-it';
  377. $result = $this->articles->generateSlug($string);
  378. $this->assertEquals($expected, $result);
  379. $string = 'something with a ; in it';
  380. $expected = 'something-with-a-in-it';
  381. $result = $this->articles->generateSlug($string);
  382. $this->assertEquals($expected, $result);
  383. $string = 'something with a ? in it';
  384. $expected = 'something-with-a-in-it';
  385. $result = $this->articles->generateSlug($string);
  386. $this->assertEquals($expected, $result);
  387. $string = 'something with a @ in it';
  388. $expected = 'something-with-a-in-it';
  389. $result = $this->articles->generateSlug($string);
  390. $this->assertEquals($expected, $result);
  391. $string = 'something with a = in it';
  392. $expected = 'something-with-a-in-it';
  393. $result = $this->articles->generateSlug($string);
  394. $this->assertEquals($expected, $result);
  395. $string = 'something with a + in it';
  396. $expected = 'something-with-a-in-it';
  397. $result = $this->articles->generateSlug($string);
  398. $this->assertEquals($expected, $result);
  399. $string = 'something with a & in it';
  400. $expected = 'something-with-a-in-it';
  401. $result = $this->articles->generateSlug($string);
  402. $this->assertEquals($expected, $result);
  403. $string = 'something with a % in it';
  404. $expected = 'something-with-a-in-it';
  405. $result = $this->articles->generateSlug($string);
  406. $this->assertEquals($expected, $result);
  407. $string = 'something with a \ in it';
  408. $expected = 'something-with-a-in-it';
  409. $result = $this->articles->generateSlug($string);
  410. $this->assertEquals($expected, $result);
  411. $string = 'something with a # in it';
  412. $expected = 'something-with-a-in-it';
  413. $result = $this->articles->generateSlug($string);
  414. $this->assertEquals($expected, $result);
  415. }
  416. /**
  417. * Test slug with ascii
  418. *
  419. * @return void
  420. */
  421. public function testSlugGenerationModeAscii() {
  422. $this->articles->removeBehavior('Slugged');
  423. $this->articles->addBehavior('Tools.Slugged', [
  424. 'mode' => 'ascii']);
  425. $article = $this->articles->newEntity(['title' => 'Some Article 25271']);
  426. $result = $this->articles->save($article);
  427. $this->assertTrue((bool)$result);
  428. $this->assertEquals('Some-Article-25271', $result['slug']);
  429. }
  430. /**
  431. * Test slug generation/update on beforeSave
  432. *
  433. * @return void
  434. */
  435. public function testSlugGenerationBeforeSave() {
  436. $this->articles->removeBehavior('Slugged');
  437. $this->articles->addBehavior('Tools.Slugged', [
  438. 'on' => 'beforeSave', 'overwrite' => true]);
  439. $article = $this->articles->newEntity(['title' => 'Some Article 25271']);
  440. $result = $this->articles->save($article);
  441. //$result['id'] = $result['id'];
  442. $this->assertEquals('Some-Article-25271', $result['slug']);
  443. }
  444. /**
  445. * Test slug generation with i18n replacement pieces
  446. *
  447. * @return void
  448. */
  449. public function testSlugGenerationI18nReplacementPieces() {
  450. $this->articles->removeBehavior('Slugged');
  451. $this->articles->addBehavior('Tools.Slugged', [
  452. 'overwrite' => true]);
  453. $article = $this->articles->newEntity(['title' => 'Some & More']);
  454. $result = $this->articles->save($article);
  455. $this->assertEquals('Some-' . __d('tools', 'and') . '-More', $result['slug']);
  456. }
  457. /**
  458. * Test dynamic slug overwrite
  459. *
  460. * @return void
  461. */
  462. public function testSlugDynamicOverwrite() {
  463. $this->articles->removeBehavior('Slugged');
  464. $this->articles->addBehavior('Tools.Slugged', [
  465. 'overwrite' => false, 'overwriteField' => 'overwrite_my_slug']);
  466. $article = $this->articles->newEntity(['title' => 'Some Cool String', 'overwrite_my_slug' => false]);
  467. $result = $this->articles->save($article);
  468. $this->assertEquals('Some-Cool-String', $result['slug']);
  469. $this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'overwrite_my_slug' => false]);
  470. $result = $this->articles->save($article);
  471. $this->assertEquals('Some-Cool-String', $result['slug']);
  472. $this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'overwrite_my_slug' => true]);
  473. $result = $this->articles->save($article);
  474. $this->assertEquals('Some-Cool-Other-String', $result['slug']);
  475. }
  476. /**
  477. * Test slug generation/update based on scope
  478. *
  479. * @return void
  480. */
  481. public function testSlugGenerationWithScope() {
  482. $this->articles->removeBehavior('Slugged');
  483. $this->articles->addBehavior('Tools.Slugged', ['unique' => true]);
  484. $data = ['title' => 'Some Article 12345', 'section' => 0];
  485. $article = $this->articles->newEntity($data);
  486. $result = $this->articles->save($article);
  487. $this->assertTrue((bool)$result);
  488. $this->assertEquals('Some-Article-12345', $result['slug']);
  489. $article = $this->articles->newEntity($data);
  490. $result = $this->articles->save($article);
  491. $this->assertTrue((bool)$result);
  492. $this->assertEquals('Some-Article-12345-1', $result['slug']);
  493. $this->articles->removeBehavior('Slugged');
  494. $this->articles->addBehavior('Tools.Slugged', ['unique' => true, 'scope' => ['section' => 1]]);
  495. $data = ['title' => 'Some Article 12345', 'section' => 1];
  496. $article = $this->articles->newEntity($data);
  497. $result = $this->articles->save($article);
  498. $this->assertTrue((bool)$result);
  499. $this->assertEquals('Some-Article-12345', $result['slug']);
  500. }
  501. /**
  502. * Test slug generation works with virtual fields.
  503. *
  504. * @return void
  505. */
  506. public function testSlugGenerationWithVirualField() {
  507. $this->articles->removeBehavior('Slugged');
  508. $this->articles->entityClass('\TestApp\Model\Entity\SluggedArticle');
  509. $this->articles->addBehavior('Tools.Slugged', [
  510. 'label' => [
  511. 'title',
  512. 'special'
  513. ],
  514. ]);
  515. $data = ['title' => 'Some Article 12345', 'section' => 0];
  516. $article = $this->articles->newEntity($data);
  517. $result = $this->articles->save($article);
  518. $this->assertTrue((bool)$result);
  519. $this->assertEquals('Some-Article-12345-dereuromark', $result['slug']);
  520. }
  521. /**
  522. * Get a new Entity
  523. *
  524. * @param string|null $title
  525. * @param string|null $field
  526. * @param array $data
  527. * @param array $options
  528. * @return \Cake\ORM\Entity
  529. */
  530. protected function _getEntity($title = null, $field = null, array $data = [], array $options = []) {
  531. $options += ['validate' => false];
  532. if ($title === null) {
  533. $title = 'test 123';
  534. }
  535. if ($field === null) {
  536. $field = 'title';
  537. }
  538. $data = [
  539. $field => $title
  540. ] + $data;
  541. return new Entity($data, $options);
  542. }
  543. }