TypographicBehaviorTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. App::import('Behavior', 'Tools.Typographic');
  3. App::uses('App', 'Core');
  4. App::uses('MyCakeTestCase', 'Tools.Lib');
  5. class TypographicBehaviorTest extends MyCakeTestCase {
  6. public function startTest() {
  7. //$this->Comment = ClassRegistry::init('Comment');
  8. $this->Comment = new TestModel();
  9. $this->Comment->Behaviors->attach('Tools.Typographic', array('fields'=>array('body'), 'before'=>'validate'));
  10. }
  11. public function setUp() {
  12. }
  13. public function tearDown() {
  14. }
  15. public function testObject() {
  16. $this->assertTrue(is_a($this->Comment->Behaviors->Typographic, 'TypographicBehavior'));
  17. }
  18. public function testBeforeValidate() {
  19. $this->out($this->_header(__FUNCTION__), false);
  20. // accuracy >= 5
  21. $data = array(
  22. 'name' => 'some Name',
  23. 'body' => 'A title with normal "qotes" - should be left untouched',
  24. );
  25. $this->Comment->set($data);
  26. $res = $this->Comment->validates();
  27. $this->assertTrue($res);
  28. $res = $this->Comment->data;
  29. $this->assertSame($data['body'], $res['TestModel']['body']);
  30. $strings = array(
  31. 'some string with ‹single angle quotes›' => 'some string with "single angle quotes"',
  32. 'other string with „German‟ quotes' => 'other string with "German" quotes',
  33. 'mixed single ‚one‛ and ‘two’.' => 'mixed single "one" and "two".',
  34. 'mixed double “one” and «two».' => 'mixed double "one" and "two".',
  35. );
  36. foreach ($strings as $was => $expected) {
  37. $data = array(
  38. 'body' => $was
  39. );
  40. $this->Comment->set($data);
  41. $res = $this->Comment->validates();
  42. $this->assertTrue($res);
  43. $res = $this->Comment->data;
  44. //debug($expected);
  45. //debug($res['TestModel']['body']);
  46. //die();
  47. $this->assertSame($expected, $res['TestModel']['body']);
  48. }
  49. }
  50. }
  51. /** other files **/
  52. class TestModel extends AppModel {
  53. public $alias = 'TestModel';
  54. public $useTable = false;
  55. public $displayField = 'name';
  56. }