Skip to content

Commit

Permalink
Merge pull request #34 from nojimage/autolink-set-default-class
Browse files Browse the repository at this point in the history
Add Autolink:: setToAllLinkClasses method
  • Loading branch information
nojimage authored Apr 22, 2020
2 parents 84dc4e8 + 9bc4cf4 commit dc2b568
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Twitter/Text/Autolink.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ public function __construct($tweet = null, $escape = true, $full_encode = false)
$this->extractor = Extractor::create();
}

/**
* Set CSS class to all link types.
*
* @param string $v CSS class for links.
*
* @return Autolink Fluid method chaining.
*/
public function setToAllLinkClasses($v)
{
$this->setURLClass($v);
$this->setUsernameClass($v);
$this->setListClass($v);
$this->setHashtagClass($v);
$this->setCashtagClass($v);

return $this;
}

/**
* CSS class for auto-linked URLs.
*
Expand Down
32 changes: 32 additions & 0 deletions tests/TestCase/AutolinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,36 @@ function (Autolink $linker) {
),
);
}

/**
* setToAllLinkClasses can set class to all link types
*/
public function testSetToAllLinkClasses()
{
$this->assertSame('', $this->linker->getURLClass());
$this->assertSame('tweet-url username', $this->linker->getUsernameClass());
$this->assertSame('tweet-url list-slug', $this->linker->getListClass());
$this->assertSame('tweet-url hashtag', $this->linker->getHashtagClass());
$this->assertSame('tweet-url cashtag', $this->linker->getCashtagClass());

// set default css class
$this->assertSame($this->linker, $this->linker->setToAllLinkClasses('my-custom-class'));
$this->assertSame('my-custom-class', $this->linker->getURLClass(), 'getURLClass will return default class');
$this->assertSame('my-custom-class', $this->linker->getUsernameClass(), 'getUsernameClass will return default class');
$this->assertSame('my-custom-class', $this->linker->getListClass(), 'getListClass will return default class');
$this->assertSame('my-custom-class', $this->linker->getHashtagClass(), 'getHashtagClass will return default class');
$this->assertSame('my-custom-class', $this->linker->getCashtagClass(), 'getCashtagClass will return default class');

// override each classes
$this->linker->setURLClass('my-url-class');
$this->linker->setUsernameClass('my-username-class');
$this->linker->setListClass('my-list-class');
$this->linker->setHashtagClass('my-hashtag-class');
$this->linker->setCashtagClass('my-cashtag-class');
$this->assertSame('my-url-class', $this->linker->getURLClass(), 'getURLClass will return specific class');
$this->assertSame('my-username-class', $this->linker->getUsernameClass(), 'getUsernameClass will return specific class');
$this->assertSame('my-list-class', $this->linker->getListClass(), 'getListClass will return specific class');
$this->assertSame('my-hashtag-class', $this->linker->getHashtagClass(), 'getHashtagClass will return specific class');
$this->assertSame('my-cashtag-class', $this->linker->getCashtagClass(), 'getCashtagClass will return specific class');
}
}

0 comments on commit dc2b568

Please sign in to comment.