| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Tools\Test\TestCase\Model\Behavior;
- use Cake\ORM\TableRegistry;
- use Tools\TestSuite\TestCase;
- class StringBehaviorTest extends TestCase {
- /**
- * @var array
- */
- public $fixtures = [
- 'plugin.Tools.StringComments'
- ];
- /**
- * @var \Tools\Model\Table\Table
- */
- public $Comments;
- /**
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->Comments = TableRegistry::getTableLocator()->get('StringComments');
- $this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'input' => ['ucfirst']]);
- }
- /**
- * @return void
- */
- public function testBasic() {
- $data = [
- 'title' => 'some Name',
- 'comment' => 'blabla',
- 'url' => 'www.dereuromark.de',
- ];
- $entity = $this->Comments->newEntity($data);
- $res = $this->Comments->save($entity);
- $this->assertTrue((bool)$res);
- $this->assertSame('Some Name', $res['title']);
- }
- /**
- * @return void
- */
- public function testMultipleFieldsAndMultipleFilters() {
- $this->Comments->behaviors()->String->setConfig(['fields' => ['title', 'comment'], 'input' => ['strtolower', 'ucwords']]);
- $data = [
- 'title' => 'some nAme',
- 'comment' => 'blaBla',
- 'url' => 'www.dereuromark.de',
- ];
- $entity = $this->Comments->newEntity($data);
- $res = $this->Comments->save($entity);
- $this->assertTrue((bool)$res);
- $this->assertSame('Some Name', $res['title']);
- $this->assertSame('Blabla', $res['comment']);
- }
- /**
- * @return void
- */
- public function testBasicOutput() {
- $this->Comments->removeBehavior('String');
- $data = [
- 'title' => 'some Name',
- 'comment' => 'blabla',
- 'url' => ''
- ];
- $entity = $this->Comments->newEntity($data);
- $res = $this->Comments->save($entity);
- $this->assertTrue((bool)$res);
- $this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'output' => ['ucfirst']]);
- $res = $this->Comments->get($entity->id);
- $this->assertSame('Some Name', $res['title']);
- }
- }
|