During the Write of Passage, I stubbornly tried to beat my writer’s block by writing until 3am multiple times. The burnout returned. I dropped everything and went to Greece for a week.
+ + + ++ Have you seen my blog, adamadam.blog? I told a story there of how I got my Bachelor's degree, + check it out: https://adamadam.blog/2021/09/16/how-i-got-bachelors-in-six-months/ +
+ diff --git a/transfer-protocol/married.html b/transfer-protocol/married.html index a6274ea..b4f62f6 100644 --- a/transfer-protocol/married.html +++ b/transfer-protocol/married.html @@ -316,4 +316,4 @@I will make 2022 about doing less. My only map is my intuition. Amor fati, as the Stoics would say. I am open to whatever life will bring. Where is it going to take me? Who knows? We'll see next year!
- \ No newline at end of file + diff --git a/transfer-protocol/phpunit.xml b/transfer-protocol/phpunit.xml index 5349c27..b2ea419 100644 --- a/transfer-protocol/phpunit.xml +++ b/transfer-protocol/phpunit.xml @@ -1,7 +1,11 @@ -I am a new text
', 2, ], + 'Escapes the text in a text node' => [ + 'Hello, there
', + 'TheThe <div> tag is my favorite one
', + 2, + ], ]; } @@ -174,6 +180,16 @@ public function test_set_modifiable_text_can_be_called_twice() { ); } + public function test_next_block_attribute_returns_false_after_the_last_attribute() { + $p = new WP_Block_Markup_Processor( + '' + ); + $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertFalse( $p->next_block_attribute(), 'Returned true even though there was no next attribute' ); + } + public function test_next_block_attribute_finds_the_first_attribute() { $p = new WP_Block_Markup_Processor( '' @@ -204,6 +220,7 @@ public function test_next_block_attribute_finds_nested_attributes() { $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); $this->assertEquals( 'lowres', $p->get_block_attribute_key(), 'Failed to find the block attribute name' ); $this->assertEquals( 'small.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); @@ -214,6 +231,24 @@ public function test_next_block_attribute_finds_nested_attributes() { $this->assertEquals( 'large.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); } + public function test_next_block_attribute_loops_over_lists() { + $p = new WP_Block_Markup_Processor( + '' + ); + $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); + + $this->assertEquals( 0, $p->get_block_attribute_key(), 'Failed to find the block attribute name' ); + $this->assertEquals( 'small.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); + + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + + $this->assertEquals( 1, $p->get_block_attribute_key(), 'Failed to find the block attribute name' ); + $this->assertEquals( 'large.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); + } + public function test_next_block_attribute_finds_top_level_attributes_after_nesting() { $p = new WP_Block_Markup_Processor( '' @@ -221,7 +256,8 @@ public function test_next_block_attribute_finds_top_level_attributes_after_nesti $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); - $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the fourth block attribute' ); $this->assertEquals( 'class', $p->get_block_attribute_key(), 'Failed to find the block attribute name' ); $this->assertEquals( 'wp-bold', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); @@ -235,7 +271,7 @@ public function test_set_block_attribute_value_updates_a_simple_attribute() { $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); $p->set_block_attribute_value( 'wp-italics' ); - $this->assertEquals( '', $p->get_updated_html(), + $this->assertEquals( '', $p->get_updated_html(), 'Failed to update the block attribute value' ); } @@ -257,10 +293,26 @@ public function test_set_block_attribute_value_updates_a_nested_attribute() { $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); + + $p->set_block_attribute_value( 'medium.png' ); + $this->assertEquals( 'medium.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); + $this->assertEquals( '', $p->get_updated_html(), + 'Failed to update the block attribute value' ); + } + + public function test_set_block_attribute_value_updates_a_list_value() { + $p = new WP_Block_Markup_Processor( + '' + ); + $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); $p->set_block_attribute_value( 'medium.png' ); $this->assertEquals( 'medium.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); - $this->assertEquals( '', $p->get_updated_html(), + $this->assertEquals( '', $p->get_updated_html(), 'Failed to update the block attribute value' ); } @@ -271,16 +323,31 @@ public function test_set_block_attribute_can_be_called_multiple_times() { $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); $this->assertTrue( $p->next_block_attribute(), 'Failed to find the second block attribute' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the third block attribute' ); $p->set_block_attribute_value( 'medium.png' ); $p->set_block_attribute_value( 'oh-completely-different-image.png' ); $this->assertEquals( 'oh-completely-different-image.png', $p->get_block_attribute_value(), 'Failed to find the block attribute value' ); $this->assertEquals( - '', + '', $p->get_updated_html(), 'Failed to update the block attribute value' ); } + public function test_set_block_attribute_value_flushes_updates_on_next_token() { + $p = new WP_Block_Markup_Processor( + 'Hello, there' + ); + $this->assertTrue( $p->next_token(), 'Failed to find the block opener' ); + $this->assertTrue( $p->next_block_attribute(), 'Failed to find the first block attribute' ); + $this->assertTrue( $p->set_block_attribute_value( 'wp-italics' ), 'Failed to update the block attribute value' ); + $this->assertTrue( $p->next_token(), 'Failed to find the text node' ); + $this->assertEquals( + 'Hello, there', + $p->get_updated_html(), + 'Failed to update the block attribute value' + ); + } } diff --git a/transfer-protocol/tests/WP_Block_Markup_Url_Processor_Tests.php b/transfer-protocol/tests/WP_Block_Markup_Url_Processor_Tests.php index e57a0f7..012b1fe 100644 --- a/transfer-protocol/tests/WP_Block_Markup_Url_Processor_Tests.php +++ b/transfer-protocol/tests/WP_Block_Markup_Url_Processor_Tests.php @@ -2,51 +2,23 @@ use PHPUnit\Framework\TestCase; -//$block_markup = file_get_contents( __DIR__ . '/../married.html' ); -// -//$p = new URL_Rewriter( $block_markup ); -//$p->next_url(); - -// for ($i = 0; $i < 15; $i++) { -// $p->next_token(); -// if($p->get_token_type() === '#block-comment') { -// $updated_attrs = map_block_attributes($p->get_block_attributes(), function($key, $value) { -// if($key === 'url') { -// return 'https://example.com'; -// } -// return $value; -// }); -// $p->set_block_attributes($updated_attrs); -// echo substr($p->get_updated_html(), 0, 100) . "\n"; -// die(); -// } -// } - -//private function map_block_attributes( array $attributes, $mapper ) { -// $new_attributes = array(); -// foreach ( $attributes as $key => $value ) { -// if ( is_array( $value ) ) { -// $new_attributes[ $key ] = map_block_attributes( $value, $mapper ); -// } else { -// $new_attributes[ $key ] = $mapper( $key, $value ); -// } -// } -// -// return $new_attributes; -//} - - class WP_Block_Markup_Url_Processor_Tests extends TestCase { + public function test_next_url_in_current_token_returns_false_when_no_url_is_found() + { + $p = new WP_Block_Markup_Url_Processor('Text without URLs'); + $this->assertFalse( $p->next_url_in_current_token() ); + } + /** * * @dataProvider provider_test_finds_next_url */ - public function test_next_url_finds_the_url($url, $markup) + public function test_next_url_finds_the_url($url, $markup, $base_url='https://wordpress.org') { - $p = new WP_Block_Markup_Url_Processor($markup); - $this->assertTrue($p->next_url(), 'Failed to find the URL in the markup.'); + $p = new WP_Block_Markup_Url_Processor($markup, $base_url); + $this->assertTrue( $p->next_url(), 'Failed to find the URL in the markup.' ); $this->assertEquals($url, $p->get_url(), 'Found a URL in the markup, but it wasn\'t the expected one.'); } @@ -54,14 +26,14 @@ static public function provider_test_finds_next_url() { return [ 'In the tag' => ['https://wordpress.org', ''], - 'In the first block attribute, when it contains just the URL' => [ - 'https://mysite.com/wp-content/image.png', - '' - ], 'In the second block attribute, when it contains just the URL' => [ 'https://mysite.com/wp-content/image.png', '' ], + 'In the first block attribute, when it contains just the URL' => [ + 'https://mysite.com/wp-content/image.png', + '' + ], 'In a block attribute, in a nested object, when it contains just the URL' => [ 'https://mysite.com/wp-content/image.png', '' @@ -74,6 +46,10 @@ static public function provider_test_finds_next_url() 'https://wordpress.org', 'Have you seen https://wordpress.org? ' ], + 'In a text node after a tag' => [ + 'wordpress.org', + 'Have you seen wordpress.org' + ], 'In a text node, when it contains a protocol-relative absolute URL' => [ '//wordpress.org', 'Have you seen //wordpress.org? ' @@ -86,6 +62,16 @@ static public function provider_test_finds_next_url() 'wordpress.org/plugins', 'Have you seen wordpress.org/plugins? ' ], + 'Matches an empty string in as a valid relative URL when given a base URL' => [ + '', + '', + 'https://wordpress.org' + ], + 'Skips over an empty string in when not given a base URL' => [ + 'https://developer.w.org', + '', + null + ], ]; } @@ -143,7 +129,7 @@ static public function provider_test_set_url_examples() 'In the "src" block attribute' => [ '', 'https://w.org', - '' + '' ], 'In a text node' => [ 'Have you seen https://wordpress.org yet?', @@ -155,7 +141,8 @@ static public function provider_test_set_url_examples() public function test_set_url_complex_test_case() { - $p = new WP_Block_Markup_Url_Processor(<< @@ -170,7 +157,8 @@ public function test_set_url_complex_test_case() check it out: https://adamadam.blog/2021/09/16/how-i-got-bachelors-in-six-months/
-HTML +HTML, + 'https://adamadam.blog' ); // Replace every url with 'https://site-export.internal' @@ -180,7 +168,7 @@ public function test_set_url_complex_test_case() $this->assertEquals( << +