DonationFactory.php
5 years ago
DonationFormFactory.php
5 years ago
DonorFactory.php
5 years ago
PageFactory.php
5 years ago
RevenueFactory.php
5 years ago
DonationFormFactory.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\TestData\Factories; |
| 4 | |
| 5 | use Give\TestData\Framework\Factory; |
| 6 | |
| 7 | /** |
| 8 | * Class DonationFormFactory |
| 9 | * @package Give\TestData\Factories |
| 10 | */ |
| 11 | class DonationFormFactory extends Factory { |
| 12 | |
| 13 | /** |
| 14 | * @var bool |
| 15 | */ |
| 16 | private $donationGoal; |
| 17 | |
| 18 | /** |
| 19 | * @var bool |
| 20 | */ |
| 21 | private $termsAndConditions; |
| 22 | |
| 23 | /** |
| 24 | * @var string |
| 25 | */ |
| 26 | private $template; |
| 27 | |
| 28 | /** |
| 29 | * @var string[] |
| 30 | */ |
| 31 | private $templates = [ 'sequoia', 'legacy' ]; |
| 32 | |
| 33 | /** |
| 34 | * @param string $template |
| 35 | * |
| 36 | * @return bool |
| 37 | */ |
| 38 | public function checkFormTemplate( $template ) { |
| 39 | if ( 'random' === $template ) { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | return in_array( $template, $this->templates ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param string $template |
| 48 | */ |
| 49 | public function setFormTemplate( $template ) { |
| 50 | $this->template = $template; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return string |
| 55 | */ |
| 56 | public function getFormTemplate() { |
| 57 | if ( 'random' === $this->template ) { |
| 58 | return $this->randomDonationTemplate(); |
| 59 | } |
| 60 | |
| 61 | return $this->template; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return string |
| 66 | */ |
| 67 | public function randomDonationTemplate() { |
| 68 | return $this->faker->randomElement( $this->templates ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param bool $generate |
| 73 | */ |
| 74 | public function setDonationFormGoal( $generate ) { |
| 75 | $this->donationGoal = (bool) $generate; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return false|string |
| 80 | */ |
| 81 | public function getDonationGoal() { |
| 82 | if ( is_null( $this->donationGoal ) || ! $this->donationGoal ) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | return $this->randomGoal(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param bool $generate |
| 91 | */ |
| 92 | public function setTermsAndConditions( $generate ) { |
| 93 | $this->termsAndConditions = (bool) $generate; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /** |
| 98 | * @return array |
| 99 | */ |
| 100 | public function getTermsAndConditions() { |
| 101 | if ( is_null( $this->termsAndConditions ) || ! $this->termsAndConditions ) { |
| 102 | return []; |
| 103 | } |
| 104 | |
| 105 | return [ |
| 106 | 'label' => $this->faker->catchPhrase(), |
| 107 | 'text' => $this->faker->text(), |
| 108 | ]; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Donor definition |
| 113 | * |
| 114 | * @return array |
| 115 | * @since 1.0.0 |
| 116 | */ |
| 117 | public function definition() { |
| 118 | $title = $this->faker->catchPhrase(); |
| 119 | |
| 120 | return [ |
| 121 | 'post_title' => $title, |
| 122 | 'post_name' => sanitize_title( $title ), |
| 123 | 'post_author' => $this->randomAuthor(), |
| 124 | 'post_date' => date( 'Y-m-d H:i:s' ), |
| 125 | 'donation_goal' => $this->getDonationGoal(), |
| 126 | 'donation_terms' => $this->getTermsAndConditions(), |
| 127 | 'form_template' => $this->getFormTemplate(), |
| 128 | 'random_amount' => $this->randomAmount(), |
| 129 | ]; |
| 130 | } |
| 131 | |
| 132 | } |
| 133 |