StringBehaviorTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tools\Test\TestCase\Model\Behavior;
  3. use Cake\ORM\TableRegistry;
  4. use Tools\TestSuite\TestCase;
  5. class StringBehaviorTest extends TestCase {
  6. /**
  7. * @var array
  8. */
  9. public $fixtures = [
  10. 'plugin.tools.string_comments'
  11. ];
  12. /**
  13. * @var \Tools\Model\Table\Table
  14. */
  15. public $Comments;
  16. public function setUp() {
  17. parent::setUp();
  18. $this->Comments = TableRegistry::get('StringComments');
  19. $this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'input' => ['ucfirst']]);
  20. }
  21. /**
  22. * StringBehaviorTest::testBasic()
  23. *
  24. * @return void
  25. */
  26. public function testBasic() {
  27. $data = [
  28. 'comment' => 'blabla',
  29. 'url' => 'www.dereuromark.de',
  30. 'title' => 'some Name',
  31. ];
  32. $entity = $this->Comments->newEntity($data);
  33. $res = $this->Comments->save($entity);
  34. $this->assertTrue((bool)$res);
  35. $this->assertSame('Some Name', $res['title']);
  36. }
  37. /**
  38. * StringBehaviorTest::testMultipleFieldsAndMultipleFilters()
  39. *
  40. * @return void
  41. */
  42. public function testMultipleFieldsAndMultipleFilters() {
  43. $this->Comments->behaviors()->String->config(['fields' => ['title', 'comment'], 'input' => ['strtolower', 'ucwords']]);
  44. $data = [
  45. 'comment' => 'blaBla',
  46. 'url' => 'www.dereuromark.de',
  47. 'title' => 'some nAme',
  48. ];
  49. $entity = $this->Comments->newEntity($data);
  50. $res = $this->Comments->save($entity);
  51. $this->assertTrue((bool)$res);
  52. $this->assertSame('Some Name', $res['title']);
  53. $this->assertSame('Blabla', $res['comment']);
  54. }
  55. }