Skip to content

Commit a963299

Browse files
authored
Merge pull request #20 from nojimage/develop
Fixes #19
2 parents e19d55e + ccab29e commit a963299

File tree

2 files changed

+123
-3
lines changed

2 files changed

+123
-3
lines changed

lib/Twitter/Text/Extractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ public function extract($tweet)
9393
return array(
9494
'hashtags' => $this->extractHashtags($tweet),
9595
'urls' => $this->extractURLs($tweet),
96-
'mentions' => $this->extractMentionedUsernames($tweet),
97-
'replyto' => $this->extractRepliedUsernames($tweet),
96+
'mentions' => $this->extractMentionedScreennames($tweet),
97+
'replyto' => $this->extractReplyScreenname($tweet),
9898
'hashtags_with_indices' => $this->extractHashtagsWithIndices($tweet),
9999
'urls_with_indices' => $this->extractURLsWithIndices($tweet),
100-
'mentions_with_indices' => $this->extractMentionedUsernamesWithIndices($tweet),
100+
'mentions_with_indices' => $this->extractMentionedScreennamesWithIndices($tweet),
101101
);
102102
}
103103

tests/Twitter/Text/ExtractorTest.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function testExtractURLsWithIndicesWithoutProtocol()
7171
$this->assertSame(array(), $extracted, 'Unextract url without protocol');
7272
}
7373

74+
/**
75+
* @group Extractor
76+
*/
7477
public function testUrlWithSpecialCCTLDWithoutProtocol()
7578
{
7679
$text = 'MLB.tv vine.co';
@@ -88,6 +91,9 @@ public function testUrlWithSpecialCCTLDWithoutProtocol()
8891
$this->assertSame(array(), $extracted, 'Unextract url without protocol');
8992
}
9093

94+
/**
95+
* @group Extractor
96+
*/
9197
public function testExtractURLsWithEmoji()
9298
{
9399
$text = "@ummjackson 🤡 https://i.imgur.com/I32CQ81.jpg";
@@ -99,12 +105,18 @@ public function testExtractURLsWithEmoji()
99105
);
100106
}
101107

108+
/**
109+
* @group Extractor
110+
*/
102111
public function testExtractURLsPrecededByEllipsis()
103112
{
104113
$extracted = $this->extractor->extractURLs('text: ...http://www.example.com');
105114
$this->assertSame(array('http://www.example.com'), $extracted, 'Unextract url preceded by ellipsis');
106115
}
107116

117+
/**
118+
* @group Extractor
119+
*/
108120
public function testExtractURLsWith64CharDomainWithoutProtocol()
109121
{
110122
$text = 'randomurlrandomurlrandomurlrandomurlrandomurlrandomurlrandomurls.com';
@@ -113,6 +125,9 @@ public function testExtractURLsWith64CharDomainWithoutProtocol()
113125
$this->assertSame(array(), $extracted, 'Handle a 64 character domain without protocol');
114126
}
115127

128+
/**
129+
* @group Extractor
130+
*/
116131
public function testExtractURLsHandleLongUrlWithInvalidDomainLabelsAndShortUrl()
117132
{
118133
// @codingStandardsIgnoreStart
@@ -127,4 +142,109 @@ public function testExtractURLsHandleLongUrlWithInvalidDomainLabelsAndShortUrl()
127142
),
128143
), $extracted, 'Handle long url with invalid domain labels and short url');
129144
}
145+
146+
/**
147+
* @group Extractor
148+
*/
149+
public function testExtract()
150+
{
151+
// @codingStandardsIgnoreStart
152+
$text = '@someone Hey check out out @otheruser/list_name-01! This is #hashtag1 http://example.com Example cashtags: $TEST $Stock $symbol via @username';
153+
// @codingStandardsIgnoreEnd
154+
155+
$extracted = $this->extractor->extract($text);
156+
$expects = array(
157+
'hashtags' => array(
158+
'hashtag1'
159+
),
160+
'urls' => array(
161+
'http://example.com'
162+
),
163+
'mentions' => array(
164+
'someone',
165+
'otheruser',
166+
'username'
167+
),
168+
'replyto' => 'someone',
169+
'hashtags_with_indices' => array(
170+
array(
171+
'hashtag' => 'hashtag1',
172+
'indices' => array(60, 69)
173+
)
174+
),
175+
'urls_with_indices' => array(
176+
array(
177+
'url' => 'http://example.com',
178+
'indices' => array(70, 88)
179+
)
180+
),
181+
'mentions_with_indices' => array(
182+
array(
183+
'screen_name' => 'someone',
184+
'indices' => array(0, 8)
185+
),
186+
array(
187+
'screen_name' => 'otheruser',
188+
'indices' => array(27, 50)
189+
),
190+
array(
191+
'screen_name' => 'username',
192+
'indices' => array(132, 141)
193+
)
194+
)
195+
);
196+
197+
$this->assertSame($expects, $extracted);
198+
}
199+
200+
/**
201+
* @group Extractor
202+
*/
203+
public function testExtractEntitiesWithIndices()
204+
{
205+
// @codingStandardsIgnoreStart
206+
$text = '@someone Hey check out out @otheruser/list_name-01! This is #hashtag1 http://example.com Example cashtags: $TEST $Stock $symbol via @username';
207+
// @codingStandardsIgnoreEnd
208+
209+
$extracted = $this->extractor->extractEntitiesWithIndices($text);
210+
$expects = array(
211+
array(
212+
'screen_name' => 'someone',
213+
'list_slug' => '',
214+
'indices' => array(0, 8)
215+
),
216+
array(
217+
'screen_name' => 'otheruser',
218+
'list_slug' => '/list_name-01',
219+
'indices' => array(27, 50)
220+
),
221+
array(
222+
'hashtag' => 'hashtag1',
223+
'indices' => array(60, 69)
224+
),
225+
array(
226+
'url' => 'http://example.com',
227+
'indices' => array(70, 88)
228+
),
229+
array(
230+
'cashtag' => 'TEST',
231+
'indices' => array(107, 112)
232+
),
233+
array(
234+
'cashtag' => 'Stock',
235+
'indices' => array(113, 119)
236+
),
237+
array(
238+
'cashtag' => 'symbol',
239+
'indices' => array(120, 127)
240+
),
241+
array(
242+
'screen_name' => 'username',
243+
'list_slug' => '',
244+
'indices' => array(132, 141)
245+
)
246+
);
247+
248+
$this->assertSame($expects, $extracted);
249+
}
130250
}

0 commit comments

Comments
 (0)