11<?php
22
33use The3LabsTeam \Readability \Facades \Readability ;
4+ use The3LabsTeam \Readability \Readability as ReadabilityClass ;
45
56it ('cannot parse a non html ' , function () {
67 $ html = 'This is a test ' ;
910 })->toThrow (Exception::class);
1011});
1112
13+ it ('cannot parse a non html from ReadabilityClass ' , function () {
14+ $ html = 'This is a test ' ;
15+ expect (function () use ($ html ) {
16+ $ readability = new ReadabilityClass ($ html );
17+ $ readability ->parse ();
18+ })->toThrow (Exception::class);
19+ });
20+
1221it ('can parse and get the title ' , function () {
1322 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
1423 $ parsed = Readability::parse ($ html );
1524 $ title = $ parsed ->getTitle ();
1625 expect ($ title )->toBe ('Bitcoin: A Peer-to-Peer Electronic Cash System ' );
1726});
1827
28+ it ('can parse and get the title from ReadabilityClass ' , function () {
29+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
30+ $ parsed = (new ReadabilityClass ($ html ))->parse ();
31+ $ title = $ parsed ->getTitle ();
32+ expect ($ title )->toBe ('Bitcoin: A Peer-to-Peer Electronic Cash System ' );
33+ });
34+
35+
1936it ('can parse and get excerpt ' , function () {
2037 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
2138 $ excerpt = Readability::parse ($ html )->getExcerpt ();
2239 expect ($ excerpt )->toBe ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
2340});
2441
42+ it ('can parse and get excerpt from ReadabilityClass ' , function () {
43+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
44+ $ excerpt = (new ReadabilityClass ($ html ))->parse ()->getExcerpt ();
45+ expect ($ excerpt )->toBe ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
46+ });
47+
2548it ('can parse and get the author ' , function () {
2649 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
2750 $ author = Readability::parse ($ html )->getAuthor ();
2851 expect ($ author )->toBe ('Satoshi Nakamoto ' );
2952});
3053
54+ it ('can parse and get the author from ReadabilityClass ' , function () {
55+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
56+ $ author = (new ReadabilityClass ($ html ))->parse ()->getAuthor ();
57+ expect ($ author )->toBe ('Satoshi Nakamoto ' );
58+ });
59+
3160it ('can parse and get the image ' , function () {
3261 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
3362 $ image = Readability::parse ($ html )->getImage ();
3463 expect ($ image )->toBe ('https://www.bitcoin.com/wp-content/uploads/2020/10/bitcoin-whitepaper-featured-image.jpg ' );
3564});
3665
66+ it ('can parse and get the image from ReadabilityClass ' , function () {
67+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
68+ $ image = (new ReadabilityClass ($ html ))->parse ()->getImage ();
69+ expect ($ image )->toBe ('https://www.bitcoin.com/wp-content/uploads/2020/10/bitcoin-whitepaper-featured-image.jpg ' );
70+ });
71+
3772it ('can parse and get images ' , function () {
3873 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
3974 $ images = Readability::parse ($ html )->getImages ();
4883 ->and ($ images )->toContain ('/static/img/bitcoin/privacy.svg ' );
4984});
5085
86+ it ('can parse and get images from ReadabilityClass ' , function () {
87+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
88+ $ images = (new ReadabilityClass ($ html ))->parse ()->getImages ();
89+ expect ($ images )->toBeArray ()->toHaveCount (8 )
90+ ->and ($ images )->toContain ('https://www.bitcoin.com/wp-content/uploads/2020/10/bitcoin-whitepaper-featured-image.jpg ' )
91+ ->and ($ images )->toContain ('/static/img/bitcoin/transactions.svg ' )
92+ ->and ($ images )->toContain ('/static/img/bitcoin/timestamp-server.svg ' )
93+ ->and ($ images )->toContain ('/static/img/bitcoin/proof-of-work.svg ' )
94+ ->and ($ images )->toContain ('/static/img/bitcoin/reclaiming-disk-space.svg ' )
95+ ->and ($ images )->toContain ('/static/img/bitcoin/simplified-payment-verification.svg ' )
96+ ->and ($ images )->toContain ('/static/img/bitcoin/combining-splitting-value.svg ' )
97+ ->and ($ images )->toContain ('/static/img/bitcoin/privacy.svg ' );
98+ });
99+
51100it ('can parse and get the direction ' , function () {
52101 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
53102 $ direction = Readability::parse ($ html )->getDirection ();
54103 expect ($ direction )->toBe ('ltr ' );
55104});
56105
106+ it ('can parse and get the direction from ReadabilityClass ' , function () {
107+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
108+ $ direction = (new ReadabilityClass ($ html ))->parse ()->getDirection ();
109+ expect ($ direction )->toBe ('ltr ' );
110+ });
111+
57112it ('can parse and get the content ' , function () {
58113 $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
59114 $ readability = Readability::parse ($ html );
60115 $ readability ->getContent ();
61116 expect ($ readability )->not ->toBeNull ();
62117});
118+
119+ it ('can parse and get the content from ReadabilityClass ' , function () {
120+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
121+ $ readability = (new ReadabilityClass ($ html ))->parse ();
122+ $ content = $ readability ->getContent ();
123+ expect ($ content )->not ->toBeNull ();
124+ expect ($ content )->toContain ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
125+ });
126+
127+ it ('can parse and get the content with source list ' , function () {
128+ $ html = file_get_contents (__DIR__ .'/fixtures/demo-with-iframe.html ' );
129+ $ content = (new ReadabilityClass ($ html ))->addSourceList (['facebook.com ' ])->parse ()->getContent ();
130+ expect ($ content )->not ->toBeNull ();
131+ expect ($ content )->toContain ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
132+ expect ($ content )->toContain ('https://www.facebook.com/v3.2/plugins/post ' );
133+ });
134+
135+ it ('can parse and get the content with source list with specific URL ' , function () {
136+ $ html = file_get_contents (__DIR__ .'/fixtures/demo-with-iframe.html ' );
137+ $ content = (new ReadabilityClass ($ html ))->addSourceList (['facebook.com/v3.2/plugins ' ])->parse ()->getContent ();
138+ expect ($ content )->not ->toBeNull ();
139+ expect ($ content )->toContain ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
140+ expect ($ content )->toContain ('https://www.facebook.com/v3.2/plugins/post ' );
141+ expect ($ content )->not ->toContain ('https://www.facebook.com/posts/ ' );
142+ });
143+
144+
145+ it ('can parse and get the content without source list ' , function () {
146+ $ html = file_get_contents (__DIR__ .'/fixtures/demo.html ' );
147+ $ content = (new ReadabilityClass ($ html ))->addSourceList (['facebook.com ' ])->parse ()->getContent ();
148+ expect ($ content )->not ->toBeNull ();
149+ expect ($ content )->toContain ('A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. ' );
150+ expect ($ content )->not ->toContain ('https://www.facebook.com/v3.2/plugins/post ' );
151+ });
152+
153+ it ('can parse and get the content with all source list ' , function () {
154+ $ html = file_get_contents (__DIR__ .'/fixtures/demo-with-iframe.html ' );
155+ $ content = (new ReadabilityClass ($ html ))->addSourceList ()->parse ()->getContent ();
156+ expect ($ content )->not ->toBeNull ();
157+ expect ($ content )->toContain ('https://satoshi.nakamotoinstitute.org ' );
158+ expect ($ content )->toContain ('https://www.facebook.com/v3.2/plugins/post ' );
159+ expect ($ content )->toContain ('https://www.bitcoin.com/wp-content/uploads/2020/10/bitcoin-whitepaper-featured-image.jpg ' );
160+ });
0 commit comments