| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- App::uses('CommonHelper', 'Tools.View/Helper');
- App::uses('View', 'View');
- App::uses('MyCakeTestCase', 'Tools.TestSuite');
- /**
- * 2012-11-23 ms
- */
- class CommonHelperTest extends MyCakeTestCase {
- public $Common;
- public function setUp() {
- parent::setUp();
- $this->Common = new CommonHelper(new View(null));
- }
- /**
- */
- public function testMetaCanonical() {
- $is = $this->Common->metaCanonical('/some/url/param1');
- $this->out(h($is));
- $this->assertEquals('<link href="'.$this->Common->url('/some/url/param1', true).'" rel="canonical" />', trim($is));
- }
- /**
- */
- public function testMetaAlternate() {
- $is = $this->Common->metaAlternate('/some/url/param1', 'de-de');
- $this->out(h($is));
- $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url/param1').'" rel="alternate" hreflang="de-de" />', trim($is));
- $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), 'de', true);
- $this->out(h($is));
- $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />', trim($is));
- $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de', 'de-ch'), true);
- $this->out(h($is));
- $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de" />'.PHP_EOL.'<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />', trim($is));
- $is = $this->Common->metaAlternate(array('controller'=>'some', 'action'=>'url'), array('de' => array('ch', 'at'), 'en'=>array('gb', 'us')), true);
- $this->out(h($is));
- $this->assertEquals('<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-ch" />'.PHP_EOL.
- '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="de-at" />'.PHP_EOL.
- '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-gb" />'.PHP_EOL.
- '<link href="' . FULL_BASE_URL.$this->Common->url('/some/url').'" rel="alternate" hreflang="en-us" />', trim($is));
- }
- /**
- */
- public function testEsc() {
- $is = $this->Common->esc('Some Cool Text with <b>Html</b>');
- $this->assertEquals($is, 'Some Cool Text with <b>Html</b>');
- $is = $this->Common->esc('Some Cool Text'.PHP_EOL.'with <b>Html</b>');
- $this->assertEquals($is, 'Some Cool Text<br />'.PHP_EOL.'with <b>Html</b>');
- $is = $this->Common->esc('Some Cool'.PHP_EOL.' 2 indends and'.PHP_EOL.' 5 indends'.PHP_EOL.'YEAH');
- $this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.' 2 indends and<br />'.PHP_EOL.' 5 indends<br />'.PHP_EOL.'YEAH');
- $options = array('tabsToSpaces'=>2);
- $is = $this->Common->esc('Some Cool'.PHP_EOL.TB.'1 tab and'.PHP_EOL.TB.TB.'2 tabs'.PHP_EOL.'YEAH', $options);
- $this->assertEquals($is, 'Some Cool<br />'.PHP_EOL.' 1 tab and<br />'.PHP_EOL.' 2 tabs<br />'.PHP_EOL.'YEAH');
- }
- public function testAsp() {
- $res = $this->Common->asp('House', 2, true);
- $expected = __('Houses');
- $this->assertEquals($expected, $res);
- $res = $this->Common->asp('House', 1, true);
- $expected = __('House');
- $this->assertEquals($expected, $res);
- }
- public function testSp() {
- $res = $this->Common->sp('House', 'Houses', 0, true);
- $expected = __('Houses');
- $this->assertEquals($expected, $res);
- $res = $this->Common->sp('House', 'Houses', 2, true);
- $this->assertEquals($expected, $res);
- $res = $this->Common->sp('House', 'Houses', 1, true);
- $expected = __('House');
- $this->assertEquals($expected, $res);
- $res = $this->Common->sp('House', 'Houses', 1);
- $expected = 'House';
- $this->assertEquals($expected, $res);
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Common);
- }
- }
|