excerpt() public method

See also: Bolt\Twig\Handler\RecordHandler::excerpt()
public excerpt ( $content, $length = 200, $focus = null )
示例#1
0
 public function testExcerpt()
 {
     $app = $this->getApp();
     $handlers = $this->getTwigHandlers($app);
     $handlers['record'] = $this->getMockHandler('RecordHandler', 'excerpt');
     $twig = new TwigExtension($app, $handlers, true);
     $twig->excerpt(null, null);
 }
示例#2
0
 public function testExcerpt()
 {
     $app = $this->getApp();
     $handlers = $this->getTwigHandlers($app);
     $twig = new TwigExtension($app, $handlers, false);
     $storage = new Storage($app);
     $content = $storage->getEmptyContent('showcases');
     $content->setValue('body', $this->getDummyText());
     $content->setValue('title', 'A Test Title');
     // First check on the raw string excerpt length 200 and ellipsis added
     $excerpt1 = $twig->excerpt($this->getDummyText());
     $this->assertEquals(200, mb_strlen($excerpt1, "UTF-8"));
     $this->assertEquals('…', mb_substr($excerpt1, -1, 1, 'UTF-8'));
     // If passed an object excerpt will try to call an excerpt() method on it
     $mock = $this->getMock('Bolt\\Legacy\\Content', ['excerpt'], [$app]);
     $mock->expects($this->any())->method('excerpt')->will($this->returnValue('called'));
     $excerpt2 = $twig->excerpt($mock);
     $this->assertEquals('called', $excerpt2);
     // If the object doesn't implement method, it should return false
     // Note: Current behaviour is that an ArrayObject will be treated as an array:
     // values are 'glued' together, and excerpt is created from that. If we change
     // that behaviour, the test below should be uncommented again.
     //         $obj = new \ArrayObject(['info' => 'A test title', 'body' => $this->getDummyText()]);
     //         $this->assertFalse($twig->excerpt($obj));
     // Check that array works.
     $sample = ['info' => 'A test title', 'body' => $this->getDummyText()];
     $excerpt4 = $twig->excerpt($sample);
     $this->assertRegExp('/' . $sample['info'] . '/', $excerpt4);
     // Check that non text returns empty
     $excerpt5 = $twig->excerpt(1);
     $this->assertEmpty($excerpt5);
 }