-
Notifications
You must be signed in to change notification settings - Fork 24
Move WordPress Libraries Methods to Trait #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b47f91
Add `get_body_html` method
n7studios bb95792
Move WordPress Libraries Methods to Trait
n7studios 1e623b9
Add `add_subscriber_to_legacy_form` method
n7studios de20bd8
PHPStan compat.
n7studios 392dac6
Coding Standards on Tests
n7studios 5ef3974
Update code comment on `convert_relative_to_absolute_urls`
n7studios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Dotenv\Dotenv; | ||
| use ConvertKit_API\ConvertKit_API; | ||
|
|
||
| /** | ||
| * Test methods in ConvertKit_API_Traits that don't interact with the API, | ||
| * such as convert_relative_to_absolute_urls(). | ||
| */ | ||
| class ConvertKitMethodsTest extends TestCase | ||
| { | ||
| /** | ||
| * Kit API Class | ||
| * | ||
| * @var object | ||
| */ | ||
| protected $api; | ||
|
|
||
| /** | ||
| * Initialize the API class before each test. | ||
| * | ||
| * @since 2.4.1 | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function setUp(): void | ||
| { | ||
| $this->api = new ConvertKit_API(); | ||
| } | ||
|
|
||
| /** | ||
| * Test the convert_relative_to_absolute_urls() method. | ||
| * | ||
| * @since 2.4.1 | ||
| * | ||
| * @return void | ||
| */ | ||
| public function testConvertRelativeToAbsoluteUrls() | ||
| { | ||
| // Setup HTML in DOMDocument. | ||
| $html = new \DOMDocument(); | ||
| $html->loadHTML('<html> | ||
| <head> | ||
| <script type="text/javascript" src="rocket-loader.min.js"></script> | ||
| <link rel="stylesheet" href="//fonts.googleapis.com"> | ||
| </head> | ||
| <body> | ||
| <a href="/test">Test</a> | ||
| <img src="/test.jpg" /> | ||
| <script type="text/javascript" src="/test.js"></script> | ||
| <form action="/test">Test</form> | ||
| </body> | ||
| </html>'); | ||
|
|
||
| // Define URL to prepend to relative URLs. | ||
| $url_scheme_host_only = 'https://example.com'; | ||
|
|
||
| // Convert relative URLs to absolute URLs for elements we want to test. | ||
| $this->api->convert_relative_to_absolute_urls( | ||
| $html->getElementsByTagName('a'), | ||
| 'href', | ||
| $url_scheme_host_only | ||
| ); | ||
| $this->api->convert_relative_to_absolute_urls( | ||
| $html->getElementsByTagName('link'), | ||
| 'href', | ||
| $url_scheme_host_only | ||
| ); | ||
| $this->api->convert_relative_to_absolute_urls( | ||
| $html->getElementsByTagName('img'), | ||
| 'src', | ||
| $url_scheme_host_only | ||
| ); | ||
| $this->api->convert_relative_to_absolute_urls( | ||
| $html->getElementsByTagName('script'), | ||
| 'src', | ||
| $url_scheme_host_only | ||
| ); | ||
| $this->api->convert_relative_to_absolute_urls( | ||
| $html->getElementsByTagName('form'), | ||
| 'action', | ||
| $url_scheme_host_only | ||
| ); | ||
|
|
||
| // Fetch HTML string. | ||
| $output = $html->saveHTML(); | ||
|
|
||
| // Assert string contains expected HTML elements that should not be modified. | ||
| $this->assertStringContainsString('<link rel="stylesheet" href="//fonts.googleapis.com">', $output); | ||
|
|
||
| // Assert string does not contain HTML elements that should be removed. | ||
| $this->assertStringNotContainsString( | ||
| '<script type="text/javascript" src="rocket-loader.min.js"></script>', | ||
| $output | ||
| ); | ||
|
|
||
| // Assert string contains expected HTML elements that should be modified. | ||
| $this->assertStringContainsString( | ||
| '<a href="' . $url_scheme_host_only . '/test">Test</a>', | ||
| $output | ||
| ); | ||
| $this->assertStringContainsString( | ||
| '<img src="' . $url_scheme_host_only . '/test.jpg">', | ||
| $output | ||
| ); | ||
| $this->assertStringContainsString( | ||
| '<script type="text/javascript" src="' . $url_scheme_host_only . '/test.js"></script>', | ||
| $output | ||
| ); | ||
| $this->assertStringContainsString( | ||
| '<form action="' . $url_scheme_host_only . '/test">Test</form>', | ||
| $output | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that the get_body_html() method returns the expected HTML. | ||
| * | ||
| * @since 2.4.1 | ||
| */ | ||
| public function testGetBodyHtml() | ||
| { | ||
| $content = '<h1>Vantar þinn ungling sjálfstraust í stærðfræði?</h1><p>This is a test</p>'; | ||
| $html = new \DOMDocument(); | ||
| $html->loadHTML(' | ||
| <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> | ||
| <body>' . $content . '</body> | ||
| </html>'); | ||
| $this->assertEquals($content, $this->api->get_body_html($html)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.