| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- App::import('Behavior', 'Tools.Typographic');
- App::uses('App', 'Core');
- App::uses('MyCakeTestCase', 'Tools.Lib');
- class TypographicBehaviorTest extends MyCakeTestCase {
- public function startTest() {
- //$this->Comment = ClassRegistry::init('Comment');
- $this->Comment = new TestModel();
- $this->Comment->Behaviors->attach('Tools.Typographic', array('fields'=>array('body'), 'before'=>'validate'));
- }
- public function setUp() {
- }
- public function tearDown() {
- }
- public function testObject() {
- $this->assertTrue(is_a($this->Comment->Behaviors->Typographic, 'TypographicBehavior'));
- }
- public function testBeforeValidate() {
- $this->out($this->_header(__FUNCTION__), false);
- // accuracy >= 5
- $data = array(
- 'name' => 'some Name',
- 'body' => 'A title with normal "qotes" - should be left untouched',
- );
- $this->Comment->set($data);
- $res = $this->Comment->validates();
- $this->assertTrue($res);
- $res = $this->Comment->data;
- $this->assertSame($data['body'], $res['TestModel']['body']);
- $strings = array(
- 'some string with ‹single angle quotes›' => 'some string with "single angle quotes"',
- 'other string with „German‟ quotes' => 'other string with "German" quotes',
- 'mixed single ‚one‛ and ‘two’.' => 'mixed single "one" and "two".',
- 'mixed double “one” and «two».' => 'mixed double "one" and "two".',
- );
- foreach ($strings as $was => $expected) {
- $data = array(
- 'body' => $was
- );
- $this->Comment->set($data);
- $res = $this->Comment->validates();
- $this->assertTrue($res);
- $res = $this->Comment->data;
- //debug($expected);
- //debug($res['TestModel']['body']);
- //die();
- $this->assertSame($expected, $res['TestModel']['body']);
- }
- }
- }
- /** other files **/
- class TestModel extends AppModel {
- public $alias = 'TestModel';
- public $useTable = false;
- public $displayField = 'name';
- }
|