Skip to content

Commit 9708978

Browse files
test: cover deleting the chart's own image and keeping another chart's image
1 parent 1ae1c4c commit 9708978

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎tests/test-chart-image.php‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ public function test_image_save_keeps_an_attachment_of_another_owner() {
4444
$this->assertSame( '', get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true ) );
4545
}
4646

47+
/**
48+
* A new image of a chart replaces the old image of that chart.
49+
*/
50+
public function test_image_save_deletes_the_old_image_of_the_chart() {
51+
$chart_id = $this->create_own_chart();
52+
$module = new Visualizer_Module_Chart( Visualizer_Plugin::instance() );
53+
$old_id = $module->save_chart_image( self::PNG, $chart_id );
54+
update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, $old_id );
55+
56+
$new_id = $module->save_chart_image( self::PNG, $chart_id );
57+
58+
$this->assertNull( get_post( $old_id ) );
59+
$this->assertInstanceOf( 'WP_Post', get_post( $new_id ) );
60+
}
61+
62+
/**
63+
* A chart that points to the image of another chart does not delete that image.
64+
*/
65+
public function test_image_save_keeps_the_image_of_another_chart() {
66+
$module = new Visualizer_Module_Chart( Visualizer_Plugin::instance() );
67+
$source_id = $this->create_own_chart();
68+
$image_id = $module->save_chart_image( self::PNG, $source_id );
69+
$copy_id = $this->create_own_chart();
70+
update_post_meta( $copy_id, Visualizer_Plugin::CF_CHART_IMAGE, $image_id );
71+
72+
$module->save_chart_image( self::PNG, $copy_id );
73+
74+
$this->assertInstanceOf( 'WP_Post', get_post( $image_id ) );
75+
$this->assertFileExists( get_attached_file( $image_id ) );
76+
}
77+
4778
/**
4879
* A request without the editor nonce does not save a chart image.
4980
*/

0 commit comments

Comments
 (0)