SitemapTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. use Webkul\Sitemap\Models\Sitemap;
  3. use function Pest\Laravel\deleteJson;
  4. use function Pest\Laravel\get;
  5. use function Pest\Laravel\postJson;
  6. use function Pest\Laravel\putJson;
  7. it('should show the sitemap index page', function () {
  8. // Act and Assert.
  9. $this->loginAsAdmin();
  10. get(route('admin.marketing.search_seo.sitemaps.index'))
  11. ->assertOk()
  12. ->assertSeeText(trans('admin::app.marketing.search-seo.sitemaps.index.title'))
  13. ->assertSeeText(trans('admin::app.marketing.search-seo.sitemaps.index.create-btn'));
  14. });
  15. it('should fail the validation with errors when certain field not provided when store in the sitemap', function () {
  16. // Act and Assert.
  17. $this->loginAsAdmin();
  18. postJson(route('admin.marketing.search_seo.sitemaps.store'))
  19. ->assertJsonValidationErrorFor('file_name')
  20. ->assertJsonValidationErrorFor('path')
  21. ->assertUnprocessable();
  22. });
  23. it('should store the newly created sitemap', function () {
  24. // Act and Assert.
  25. $this->loginAsAdmin();
  26. postJson(route('admin.marketing.search_seo.sitemaps.store'), [
  27. 'file_name' => $fileName = strtolower(fake()->word()).'.xml',
  28. 'path' => $filePath = '/',
  29. ])
  30. ->assertOk()
  31. ->assertSeeText(trans('admin::app.marketing.search-seo.sitemaps.index.create.success'));
  32. $this->assertModelWise([
  33. Sitemap::class => [
  34. [
  35. 'file_name' => $fileName,
  36. 'path' => $filePath,
  37. ],
  38. ],
  39. ]);
  40. });
  41. it('should fail the validation with errors when certain field not provided when update in the sitemap', function () {
  42. // Arrange.
  43. $sitemap = Sitemap::factory()->create();
  44. // Act and Assert.
  45. $this->loginAsAdmin();
  46. putJson(route('admin.marketing.search_seo.sitemaps.update', $sitemap->id))
  47. ->assertJsonValidationErrorFor('file_name')
  48. ->assertJsonValidationErrorFor('path')
  49. ->assertUnprocessable();
  50. });
  51. it('should update the sitemap', function () {
  52. // Arrange.
  53. $sitemap = Sitemap::factory()->create();
  54. // Act and Assert.
  55. $this->loginAsAdmin();
  56. putJson(route('admin.marketing.search_seo.sitemaps.update'), [
  57. 'id' => $sitemap->id,
  58. 'file_name' => $fileName = strtolower(fake()->word()).'.xml',
  59. 'path' => $sitemap->path,
  60. ])
  61. ->assertOk()
  62. ->assertSeeText(trans('admin::app.marketing.search-seo.sitemaps.index.edit.success'));
  63. $this->assertModelWise([
  64. Sitemap::class => [
  65. [
  66. 'id' => $sitemap->id,
  67. 'file_name' => $fileName,
  68. 'path' => $sitemap->path,
  69. ],
  70. ],
  71. ]);
  72. });
  73. it('should delete the sitemap', function () {
  74. // Arrange.
  75. $sitemap = Sitemap::factory()->create();
  76. // Act and Assert.
  77. $this->loginAsAdmin();
  78. deleteJson(route('admin.marketing.search_seo.sitemaps.delete', $sitemap->id))
  79. ->assertOk()
  80. ->assertSeeText(trans('admin::app.marketing.search-seo.sitemaps.index.edit.delete-success'));
  81. $this->assertDatabaseMissing('sitemaps', [
  82. 'id' => $sitemap->id,
  83. ]);
  84. });