|
@@ -7,38 +7,34 @@ App::uses('MyCakeTestCase', 'Tools.Lib');
|
|
|
|
|
|
|
|
class TypographicBehaviorTest extends MyCakeTestCase {
|
|
class TypographicBehaviorTest extends MyCakeTestCase {
|
|
|
|
|
|
|
|
- public function startTest() {
|
|
|
|
|
- //$this->Comment = ClassRegistry::init('Comment');
|
|
|
|
|
- $this->Comment = new TypographicTestModel();
|
|
|
|
|
- $this->Comment->Behaviors->attach('Tools.Typographic', array('fields'=>array('body'), 'before'=>'validate'));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public function setUp() {
|
|
|
|
|
|
|
+ public $Model;
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public $fixtures = array('core.article');
|
|
|
|
|
|
|
|
- public function tearDown() {
|
|
|
|
|
|
|
+ public function setUp() {
|
|
|
|
|
+ parent::setUp();
|
|
|
|
|
|
|
|
|
|
+ $this->Model = ClassRegistry::init('Article');
|
|
|
|
|
+ $this->Model->Behaviors->attach('Tools.Typographic', array('fields'=>array('body'), 'before'=>'validate'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testObject() {
|
|
public function testObject() {
|
|
|
- $this->assertTrue(is_a($this->Comment->Behaviors->Typographic, 'TypographicBehavior'));
|
|
|
|
|
|
|
+ $this->assertTrue(is_a($this->Model->Behaviors->Typographic, 'TypographicBehavior'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testBeforeValidate() {
|
|
public function testBeforeValidate() {
|
|
|
$this->out($this->_header(__FUNCTION__), false);
|
|
$this->out($this->_header(__FUNCTION__), false);
|
|
|
- // accuracy >= 5
|
|
|
|
|
$data = array(
|
|
$data = array(
|
|
|
- 'name' => 'some Name',
|
|
|
|
|
|
|
+ 'title' => 'some «cool» title',
|
|
|
'body' => 'A title with normal "qotes" - should be left untouched',
|
|
'body' => 'A title with normal "qotes" - should be left untouched',
|
|
|
);
|
|
);
|
|
|
- $this->Comment->set($data);
|
|
|
|
|
- $res = $this->Comment->validates();
|
|
|
|
|
|
|
+ $this->Model->set($data);
|
|
|
|
|
+ $res = $this->Model->validates();
|
|
|
$this->assertTrue($res);
|
|
$this->assertTrue($res);
|
|
|
|
|
|
|
|
- $res = $this->Comment->data;
|
|
|
|
|
- $this->assertSame($data['body'], $res['TypographicTestModel']['body']);
|
|
|
|
|
|
|
+ $res = $this->Model->data;
|
|
|
|
|
+ $this->assertSame($data, $res['Article']);
|
|
|
|
|
|
|
|
$strings = array(
|
|
$strings = array(
|
|
|
'some string with ‹single angle quotes›' => 'some string with "single angle quotes"',
|
|
'some string with ‹single angle quotes›' => 'some string with "single angle quotes"',
|
|
@@ -48,30 +44,44 @@ class TypographicBehaviorTest extends MyCakeTestCase {
|
|
|
);
|
|
);
|
|
|
foreach ($strings as $was => $expected) {
|
|
foreach ($strings as $was => $expected) {
|
|
|
$data = array(
|
|
$data = array(
|
|
|
|
|
+ 'title' => 'some «cool» title',
|
|
|
'body' => $was
|
|
'body' => $was
|
|
|
);
|
|
);
|
|
|
- $this->Comment->set($data);
|
|
|
|
|
- $res = $this->Comment->validates();
|
|
|
|
|
|
|
+ $this->Model->set($data);
|
|
|
|
|
+ $res = $this->Model->validates();
|
|
|
$this->assertTrue($res);
|
|
$this->assertTrue($res);
|
|
|
|
|
|
|
|
- $res = $this->Comment->data;
|
|
|
|
|
- //debug($expected);
|
|
|
|
|
- //debug($res['TestModel']['body']);
|
|
|
|
|
- //die();
|
|
|
|
|
- $this->assertSame($expected, $res['TypographicTestModel']['body']);
|
|
|
|
|
|
|
+ $res = $this->Model->data;
|
|
|
|
|
+ $this->assertSame($data['title'], $res['Article']['title']);
|
|
|
|
|
+ $this->assertSame($expected, $res['Article']['body']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * test that not defining fields results in all textarea and text fields being processed
|
|
|
|
|
+ * 2012-08-07 ms
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testAutoFields() {
|
|
|
|
|
+ $this->Model->Behaviors->detach('Typographic');
|
|
|
|
|
+ $this->Model->Behaviors->attach('Tools.Typographic');
|
|
|
|
|
+ $data = array(
|
|
|
|
|
+ 'title' => '„German‟ quotes',
|
|
|
|
|
+ 'body' => 'mixed double “one” and «two»',
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/** other files **/
|
|
|
|
|
|
|
+ $this->Model->set($data);
|
|
|
|
|
+ $res = $this->Model->save();
|
|
|
|
|
+ $this->assertTrue((bool)$res);
|
|
|
|
|
|
|
|
-class TypographicTestModel extends AppModel {
|
|
|
|
|
|
|
+ $expected = array(
|
|
|
|
|
+ 'title' => '"German" quotes',
|
|
|
|
|
+ 'body' => 'mixed double "one" and "two"',
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- public $useTable = false;
|
|
|
|
|
- public $displayField = 'name';
|
|
|
|
|
|
|
+ $this->assertSame($expected['title'], $res['Article']['title']);
|
|
|
|
|
+ $this->assertSame($expected['body'], $res['Article']['body']);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|