1 | <?php |
||
3 | namespace AntonyThorpe\SilverShopProductModel\Tests; |
||
4 | |||
5 | use Exception; |
||
6 | use SilverShop\Page\ProductCategory; |
||
7 | use AntonyThorpe\SilverShopProductModel\ProductModel; |
||
8 | use SilverStripe\Dev\SapphireTest; |
||
9 | |||
10 | class SilvershopProductModelModelTest extends SapphireTest |
||
11 | { |
||
12 | protected static $fixture_file = 'vendor/silvershop/core/tests/php/Fixtures/shop.yml'; |
||
13 | |||
14 | public function testNew() |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | public function testRequiredFields() |
||
46 | { |
||
47 | // create an instance that lacks the required Title field |
||
48 | $product_category = $this->objFromFixture(ProductCategory::class, "electronics"); |
||
49 | $new_product_model = new ProductModel( |
||
50 | array( |
||
51 | //'Title' => 'Freighter', |
||
52 | 'Description' => 'Transportation across the Galaxy', |
||
53 | 'ProductCategoryID' => $product_category->ID |
||
54 | ) |
||
55 | ); |
||
56 | $writeFailed = false; |
||
57 | try { |
||
58 | $new_product_model->write(); |
||
59 | } catch (Exception $ex) { |
||
60 | $writeFailed = true; |
||
61 | } |
||
62 | $this->assertTrue( |
||
63 | $writeFailed, |
||
64 | "ProductModel should not be writable, since it doesn't contain the required Title field" |
||
65 | ); |
||
66 | |||
67 | // create an instance that lacks the required ProductCategoryID field |
||
68 | $product_category = $this->objFromFixture(ProductCategory::class, "electronics"); |
||
|
|||
69 | $new_product_model = new ProductModel( |
||
70 | array( |
||
71 | 'Title' => 'Freighter', |
||
72 | 'Description' => 'Transportation across the Galaxy', |
||
73 | //'ProductCategoryID' => $product_category->ID |
||
74 | ) |
||
75 | ); |
||
76 | $writeFailed = false; |
||
77 | try { |
||
78 | $new_product_model->write(); |
||
79 | } catch (Exception $ex) { |
||
80 | $writeFailed = true; |
||
81 | } |
||
82 | $this->assertTrue( |
||
83 | $writeFailed, |
||
88 |