SluggedBehaviorTest.php 20 KB

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