public function createProduct($name) { $p = new Product(); $ret = $p->create(array('name' => $name)); $this->assertTrue($ret->success); ok($p->id, 'got created id'); return $p; }
public function testCreateSubActionWithRelationshipAndReloadExistingSubRecord() { $tmpfile = tempnam('/tmp', 'test_image_') . '.png'; copy('tests/data/404.png', $tmpfile); $files = ['image' => CreateFileArray('404.png', 'image/png', $tmpfile)]; // new ActionRequest(['title' => 'Test Image'], $files); $createImage = new CreateProductImage(['title' => 'Test Image'], ['files' => $files]); $this->assertActionInvokeSuccess($createImage); $image = $createImage->getRecord(); $this->assertNotNull($image); $this->assertNotNull($image->id); $product = new Product(); $product->create(['name' => 'Test Product']); $updateProduct = new UpdateProduct(['name' => 'Updated Product'], ['record' => $product]); $relation = clone $updateProduct->getRelation('images'); $updateImage = $updateProduct->createSubActionWithRelationship($relation, ['id' => $image->id], $files); $this->assertInstanceOf('ActionKit\\RecordAction\\UpdateRecordAction', $updateImage); $this->assertActionInvokeSuccess($updateImage); $relation = clone $updateProduct->getRelation('images'); $relation['update_action'] = 'ProductBundle\\Action\\UpdateProductImage'; $updateImage = $updateProduct->createSubActionWithRelationship($relation, ['id' => $image->id], $files); $this->assertInstanceOf('ActionKit\\RecordAction\\UpdateRecordAction', $updateImage); $this->assertActionInvokeSuccess($updateImage); }