|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests; |
| 4 | + |
| 5 | +use Opensoft\Rollout\Feature; |
| 6 | +use Jaspaul\LaravelRollout\FeaturePresenter; |
| 7 | + |
| 8 | +class FeaturePresenterTest extends TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @test |
| 12 | + */ |
| 13 | + function get_name_returns_the_name_of_the_feature() |
| 14 | + { |
| 15 | + $feature = new Feature('name'); |
| 16 | + $presenter = new FeaturePresenter($feature); |
| 17 | + |
| 18 | + $this->assertEquals('name', $presenter->getName()); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * @test |
| 23 | + */ |
| 24 | + function get_display_status_returns_the_all_message_if_the_feature_is_100_percent_enabled() |
| 25 | + { |
| 26 | + $feature = new Feature('name'); |
| 27 | + $feature->setPercentage(100); |
| 28 | + |
| 29 | + $presenter = new FeaturePresenter($feature); |
| 30 | + |
| 31 | + $this->assertEquals(FeaturePresenter::$statuses['all'], $presenter->getDisplayStatus()); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @test |
| 36 | + */ |
| 37 | + function get_display_status_returns_the_request_parameter_message_if_only_a_request_parameter_is_set() |
| 38 | + { |
| 39 | + $feature = new Feature('name'); |
| 40 | + $feature->setRequestParam('derp'); |
| 41 | + |
| 42 | + $presenter = new FeaturePresenter($feature); |
| 43 | + |
| 44 | + $this->assertEquals(FeaturePresenter::$statuses['request_param'], $presenter->getDisplayStatus()); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @test |
| 49 | + */ |
| 50 | + function get_display_status_returns_the_percentage_message_if_it_is_enabled_for_more_than_0_but_less_than_100_percent_of_users() |
| 51 | + { |
| 52 | + $feature = new Feature('name'); |
| 53 | + $feature->setPercentage(80); |
| 54 | + |
| 55 | + $presenter = new FeaturePresenter($feature); |
| 56 | + |
| 57 | + $this->assertEquals(FeaturePresenter::$statuses['percentage'], $presenter->getDisplayStatus()); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * @test |
| 62 | + */ |
| 63 | + function get_display_status_returns_the_whitelist_message_if_it_is_enabled_for_groups() |
| 64 | + { |
| 65 | + $feature = new Feature('name', '0||d'); |
| 66 | + $presenter = new FeaturePresenter($feature); |
| 67 | + |
| 68 | + $this->assertEquals(FeaturePresenter::$statuses['whitelist'], $presenter->getDisplayStatus()); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @test |
| 73 | + */ |
| 74 | + function get_display_status_returns_the_whitelist_message_if_it_is_enabled_for_users() |
| 75 | + { |
| 76 | + $feature = new Feature('name', '0|a|'); |
| 77 | + $presenter = new FeaturePresenter($feature); |
| 78 | + |
| 79 | + $this->assertEquals(FeaturePresenter::$statuses['whitelist'], $presenter->getDisplayStatus()); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @test |
| 84 | + */ |
| 85 | + function get_display_status_returns_the_whitelist_message_if_it_is_enabled_for_users_and_groups() |
| 86 | + { |
| 87 | + $feature = new Feature('name', '0|a|d'); |
| 88 | + $presenter = new FeaturePresenter($feature); |
| 89 | + |
| 90 | + $this->assertEquals(FeaturePresenter::$statuses['whitelist'], $presenter->getDisplayStatus()); |
| 91 | + } |
| 92 | +} |
0 commit comments