StringBehaviorTest.php 1.5 KB

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