public function setUp()
 {
     parent::setUp();
     //Configure::write('App.namespace', 'TestApp');
     $this->Table = TableRegistry::get('Stories');
     $this->Table->addBehavior('Tools.Neighbor');
 }
 /**
  * @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']);
 }
 /**
  * JsonableBehaviorTest::testDecodeParams()
  *
  * @return void
  */
 public function testDecodeParams()
 {
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['output' => 'array', 'fields' => ['details'], 'decodeParams' => ['assoc' => false]]);
     $data = ['comment' => 'blabla', 'url' => 'www.dereuromark.de', 'title' => 'param', 'details' => ['x' => ['y' => 'z']]];
     $entity = $this->Comments->newEntity($data);
     $this->Comments->save($entity);
     // Test decode with default params
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $obj = new stdClass();
     $obj->x = new stdClass();
     $obj->x->y = 'z';
     $expected = $obj;
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = ['x' => ['y' => 'z']];
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true and depth = 2
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true, 'depth' => 2]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = [];
     $this->assertEquals($expected, $res['details']);
     // Test decode with assoc = true and depth = 3
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['fields' => ['details'], 'decodeParams' => ['assoc' => true, 'depth' => 3]]);
     $res = $this->Comments->find('all', ['conditions' => ['title' => 'param']])->first();
     $expected = ['x' => ['y' => 'z']];
     $this->assertEquals($expected, $res['details']);
 }
 /**
  * Assert that it also works with beforeSave event callback.
  *
  * @return void
  */
 public function testSaveOnBeforeSave()
 {
     $this->Comments->removeBehavior('Bitmasked');
     $this->Comments->addBehavior('Tools.Bitmasked', ['mappedField' => 'statuses', 'on' => 'beforeSave']);
     $data = ['comment' => 'test save', 'statuses' => [BitmaskedComment::STATUS_PUBLISHED, BitmaskedComment::STATUS_APPROVED]];
     $entity = $this->Comments->newEntity($data);
     $this->assertEmpty($entity->errors());
     $res = $this->Comments->save($entity);
     $this->assertTrue((bool) $res);
     $this->assertSame(BitmaskedComment::STATUS_PUBLISHED | BitmaskedComment::STATUS_APPROVED, $res['status']);
 }
 /**
  * ResetBehaviorTest::testResetWithCallbackAndFieldsAutoAdded()
  *
  * @return void
  */
 public function testResetWithCallbackAndFieldsAutoAdded()
 {
     $this->Table->removeBehavior('Reset');
     $this->Table->addBehavior('Tools.Reset', ['fields' => ['id'], 'updateFields' => ['id'], 'callback' => 'TestApp\\Model\\Table\\ResetCommentsTable::fieldsCallbackAuto']);
     $x = $this->Table->find('first', ['conditions' => ['id' => 6]]);
     $this->assertEquals('Second Comment for Second Article', $x['comment']);
     $result = $this->Table->resetRecords();
     $this->assertTrue((bool) $result);
     $x = $this->Table->find('first', ['conditions' => ['id' => 6]]);
     $expected = 'bar';
     $this->assertEquals($expected, $x['comment']);
 }
 /**
  * @return void
  */
 public function testEncodeWithNoParamsComplexContent()
 {
     $this->Comments->removeBehavior('Jsonable');
     $this->Comments->addBehavior('Tools.Jsonable', ['output' => 'array', 'fields' => ['details'], 'encodeParams' => ['options' => 0]]);
     $data = ['comment' => 'blabla', 'url' => 'www.dereuromark.de', 'title' => 'param', 'details' => ['foo' => 'bar', 'nan' => NAN, 'inf' => INF]];
     $entity = $this->Comments->newEntity($data);
     $result = $this->Comments->save($entity);
     $this->assertTrue((bool) $result);
     $res = $this->Comments->get($entity->id);
     $expected = [];
     $this->assertSame($expected, $res->details);
 }
 public function setUp()
 {
     parent::setUp();
     $this->Comments = TableRegistry::get('StringComments');
     $this->Comments->addBehavior('Tools.String', ['fields' => ['title'], 'input' => ['ucfirst']]);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->Table = TableRegistry::get('Stories');
     $this->Table->addBehavior('Tools.Neighbor');
 }