Example #1
0
 public function testShortcodeAliasDeregister()
 {
     $manager = new ShortcodeManager();
     $test = new Library\SimpleShortcode('test', null, function () {
         return 'test';
     });
     $manager->register($test)->alias('test', 't');
     $manager->deregister('test', false);
     $this->assertTrue(isset($manager['t']));
     $this->assertFalse(isset($manager['test']));
     $this->assertEquals($manager->doShortcode('[t]'), 'test');
     $this->assertEquals($manager->doShortcode('[test]'), '[test]');
 }
/*
 * Nested shortcode can be processed by the Manager
 * You can also decide which tags are available for rendering
 * */
echo $manager->register(new SimpleShortcode('nest', null, function ($content) {
    return $this->manager->doShortcode($content, 'mail');
}))->doShortcode('[nest]My email is [mail address=test@test.com], but "[date]" doesn\'t work[/nest]') . '<br><br>';
/*
 * You may also tell the original calling manager to override permissions
 * A third parameter of 'true' will attempt to use the calling manager's tag declarations
 * */
echo $manager->doShortcode('[nest]My email is [mail address=test@test.com], and the date is [d/][/mail][/nest]', 'nest|d', true) . '<br><br>';
/*
 * Let's get rid of 'm' and use it for something else
 * */
echo $manager->deregister('m')->register(new SimpleShortcode('m', null, function () {
    return 'M is pretty fantastic';
}))->doShortcode('My opinion on the letter "M": [m]') . '<br><br>';
/*
 * Let's go even further
 * Let's deregister the original [date] shortcode, but keep its alias
 * The second parameter allows us to prevent deregistration of a given shortcode's aliases
 * */
echo $manager->deregister('date', false)->doShortcode('Today is [d], not "[date]"') . '<br><br>';
/*
 * There are also a few shorthand methods!
 * Registration and Deregistration may be performed using the manager's ArrayAccess Implementation
 * There is also a doShortcode method for Shortcode Classes that will allow you to run the manager against only that particular shortcode and its aliases
 * Aliasing is also availble to SimpleShortcode, and Shortcodes that implement AliasInterface
 * */
$bold = new SimpleShortcode('bold', null, function ($content) {
 /**
  * @expectedException \Maiorano\Shortcodes\Exceptions\DeregisterException
  * @expectedExceptionMessage The shortcode 'test' does not exist in the current library
  */
 public function testDeregisterError()
 {
     $manager = new ShortcodeManager();
     $manager->deregister('test');
 }