|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once dirname(__FILE__) . '/../TinyTestCase.php'; |
| 4 | +require_once dirname(__FILE__) . '/../../../src/compatibility/as3cf/class-tiny-as3cf.php'; |
| 5 | + |
| 6 | +class Tiny_AC3SF_Test extends Tiny_TestCase |
| 7 | +{ |
| 8 | + public function set_up() |
| 9 | + { |
| 10 | + parent::set_up(); |
| 11 | + } |
| 12 | + |
| 13 | + /** |
| 14 | + * Stub is_plugin_active to return true for the pro plugin |
| 15 | + * is_plugin_active will only work in admin area (after admin_init); |
| 16 | + */ |
| 17 | + public function test_is_active_when_pro_is_enabled() |
| 18 | + { |
| 19 | + $this->wp->stub( |
| 20 | + 'is_plugin_active', |
| 21 | + function ($plugin_name) { |
| 22 | + return $plugin_name === 'amazon-s3-and-cloudfront-pro/amazon-s3-and-cloudfront-pro.php'; |
| 23 | + } |
| 24 | + ); |
| 25 | + |
| 26 | + $tiny_settings = new Tiny_Settings(); |
| 27 | + $tiny_ac3sf = new Tiny_AS3CF($tiny_settings); |
| 28 | + |
| 29 | + $this->assertTrue(Tiny_AS3CF::is_active()); |
| 30 | + } |
| 31 | + |
| 32 | + public function test_is_active_when_lite_is_enabled() |
| 33 | + { |
| 34 | + $this->wp->stub( |
| 35 | + 'is_plugin_active', |
| 36 | + function ($plugin_name) { |
| 37 | + return $plugin_name === 'amazon-s3-and-cloudfront/wordpress-s3.php'; |
| 38 | + } |
| 39 | + ); |
| 40 | + |
| 41 | + |
| 42 | + $this->assertTrue(Tiny_AS3CF::is_active()); |
| 43 | + } |
| 44 | + |
| 45 | + public function test_is_not_active() |
| 46 | + { |
| 47 | + $this->wp->stub( |
| 48 | + 'is_plugin_active', |
| 49 | + function ($plugin_name) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + ); |
| 53 | + |
| 54 | + |
| 55 | + $this->assertFalse(Tiny_AS3CF::is_active()); |
| 56 | + } |
| 57 | + |
| 58 | + public function test_remove_local_enabled_is_false_when_plugin_inactive() |
| 59 | + { |
| 60 | + $this->wp->stub( |
| 61 | + 'is_plugin_active', |
| 62 | + function ($plugin_name) { |
| 63 | + return false; |
| 64 | + } |
| 65 | + ); |
| 66 | + |
| 67 | + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); |
| 68 | + } |
| 69 | + |
| 70 | + public function test_remove_local_false_when_option_not_exists() |
| 71 | + { |
| 72 | + $this->wp->stub( |
| 73 | + 'is_plugin_active', |
| 74 | + function ($plugin_name) { |
| 75 | + return true; |
| 76 | + } |
| 77 | + ); |
| 78 | + |
| 79 | + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); |
| 80 | + } |
| 81 | + |
| 82 | + public function test_remove_local_false_when_option_is_false() |
| 83 | + { |
| 84 | + $this->wp->stub( |
| 85 | + 'is_plugin_active', |
| 86 | + function ($plugin_name) { |
| 87 | + return true; |
| 88 | + } |
| 89 | + ); |
| 90 | + |
| 91 | + $this->wp->addOption('tantan_wordpress_s3', array( |
| 92 | + 'remove-local-file' => false, |
| 93 | + )); |
| 94 | + |
| 95 | + $this->assertFalse(Tiny_AS3CF::remove_local_files_setting_enabled()); |
| 96 | + } |
| 97 | + |
| 98 | + public function test_remove_local_true_when_option_is_true() |
| 99 | + { |
| 100 | + $this->wp->stub( |
| 101 | + 'is_plugin_active', |
| 102 | + function ($plugin_name) { |
| 103 | + return true; |
| 104 | + } |
| 105 | + ); |
| 106 | + |
| 107 | + $this->wp->addOption('tantan_wordpress_s3', array( |
| 108 | + 'remove-local-file' => true, |
| 109 | + )); |
| 110 | + |
| 111 | + $this->assertTrue(Tiny_AS3CF::remove_local_files_setting_enabled()); |
| 112 | + } |
| 113 | +} |
0 commit comments