TypographicBehaviorTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. App::import('Behavior', 'Tools.Typographic');
  3. App::uses('AppModel', 'Model');
  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 TypographicTestModel();
  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['TypographicTestModel']['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['TypographicTestModel']['body']);
  48. }
  49. }
  50. }
  51. /** other files **/
  52. class TypographicTestModel extends AppModel {
  53. public $useTable = false;
  54. public $displayField = 'name';
  55. }